class Sinatra::Slack::Helpers::SlackResponse

Represents a message sent to the Slack Channel.

Attributes

delete_original[RW]
mrkdwn[RW]
replace_original[RW]
response_type[RW]
text[RW]

Public Class Methods

new(callback_id) click to toggle source
# File lib/sinatra/slack/helpers/slack_response.rb, line 12
def initialize(callback_id)
  @callback_id = callback_id
  @text = nil
  @attachments = []
  @replace_original = true
  @response_type = 'ephemeral'
  @delete_original = false
  @mrkdwn = false
end

Public Instance Methods

attachment() { |attachment| ... } click to toggle source
# File lib/sinatra/slack/helpers/slack_response.rb, line 22
def attachment
  return unless block_given?

  attachment = Helpers::Attachment.new(@callback_id)
  yield attachment
  @attachments << attachment
end
to_json() click to toggle source
# File lib/sinatra/slack/helpers/slack_response.rb, line 30
def to_json
  response = {}

  response[:text] = @text if @text
  response[:mrkdwn] = @mrkdwn
  response[:replace_original] = @replace_original
  response[:response_type] = @response_type
  response[:delete_original] = @delete_original

  response[:attachments] = @attachments.map(&:to_json) unless @attachments.empty?

  response.to_json
end