class Sinatra::Slack::Helpers::Attachment

Represents a message attachment sent to the Slack Channel.

Attributes

attachment_type[RW]
color[RW]
fallback[RW]
image_url[RW]
text[RW]
title[RW]

Public Class Methods

new(callback_id) click to toggle source
# File lib/sinatra/slack/helpers/slack_attachment.rb, line 11
def initialize(callback_id)
  @callback_id = callback_id
  @attachment_type = 'default'
  @color = '#3AA3E3'
  @actions = []
end

Public Instance Methods

action_button(name, text, value) click to toggle source
# File lib/sinatra/slack/helpers/slack_attachment.rb, line 18
def action_button(name, text, value)
  @actions << {
    name: name,
    text: text,
    type: 'button',
    value: value
  }
end
action_menu(name, text, options) click to toggle source
# File lib/sinatra/slack/helpers/slack_attachment.rb, line 27
def action_menu(name, text, options)
  @actions << {
    name: name,
    text: text,
    type: 'select',
    options: options
  }
end
to_json() click to toggle source
# File lib/sinatra/slack/helpers/slack_attachment.rb, line 36
def to_json
  att_obj = {}
  att_obj[:callback_id] = @callback_id
  att_obj[:actions] = @actions unless @actions.empty?

  attrs = %i[title color attachment_type text fallback image_url]

  attrs.each do |a|
    a_value = send(a)
    next if !a_value || a_value.empty?

    att_obj[a] = a_value
  end

  att_obj
end