module MessageSlack
Module for message interactions on Slack
Public Instance Methods
add_reaction(icon, channel, thread)
click to toggle source
# File lib/modules/message_slack.rb, line 74 def add_reaction(icon, channel, thread) @web_client.reactions_add channel: channel, name: icon, timestamp: thread, icon_url: @bot_icon, username: @bot_name rescue Slack::Web::Api::Errors::SlackError => e print e.message false end
attach_format(data, title, color = '
click to toggle source
# File lib/modules/message_slack.rb, line 20 def attach_format(data, title, color = '#e93d94') text = '' data.each { |v| text << "#{v}\n" } [{ "pretext": title, "color": color, "text": text }] end
discern_end(data, ts = nil)
click to toggle source
# File lib/modules/message_slack.rb, line 7 def discern_end(data, ts = nil) @thread = if data.respond_to? :thread_ts data.ts else ts unless ts.nil? end @channel = if data.respond_to? :channel data.channel else data end end
send_attachment(attachment, data, ts = nil)
click to toggle source
# File lib/modules/message_slack.rb, line 48 def send_attachment(attachment, data, ts = nil) discern_end(data, ts) @web_client.chat_postMessage channel: @channel, attachments: attachment, icon_url: @bot_icon, username: @bot_name, thread_ts: @thread, as_user: @bot_user end
send_direct_message(text, channel)
click to toggle source
# File lib/modules/message_slack.rb, line 43 def send_direct_message(text, channel) dm = get_user_id(channel) dm == false ? false : send_message(text, dm) end
send_file(path, data, ts = nil)
click to toggle source
# File lib/modules/message_slack.rb, line 58 def send_file(path, data, ts = nil) file = path discern_end(data, ts) @web_client.files_upload channels: @channel, icon_url: @bot_icon, username: @bot_name, thread_ts: @thread, as_user: @bot_user, file: Faraday::UploadIO.new(file, 'text'), title: File.basename(file), filename: File.basename(file) rescue Slack::Web::Api::Errors::SlackError => e print e.message false end
send_message(text, data, ts = nil)
click to toggle source
# File lib/modules/message_slack.rb, line 30 def send_message(text, data, ts = nil) discern_end(data, ts) @web_client.chat_postMessage channel: @channel, text: text, icon_url: @bot_icon, username: @bot_name, thread_ts: @thread, as_user: @bot_user rescue Slack::Web::Api::Errors::SlackError => e print e.message false end