Class: Ruboty::Adapters::SlackRTM

Inherits:
Base
  • Object
show all
Defined in:
lib/ruboty/adapters/slack_rtm.rb

Instance Method Summary collapse

Instance Method Details

#add_reaction(reaction, channel_id, timestamp) ⇒ Object



68
69
70
# File 'lib/ruboty/adapters/slack_rtm.rb', line 68

def add_reaction(reaction, channel_id, timestamp)
  client.reactions_add(name: reaction, channel: channel_id, timestamp: timestamp)
end

#runObject



18
19
20
21
22
# File 'lib/ruboty/adapters/slack_rtm.rb', line 18

def run
  init
  bind
  connect
end

#say(message) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruboty/adapters/slack_rtm.rb', line 24

def say(message)
  channel = message[:to]
  if channel[0] == '#'
    channel = resolve_channel_id(channel[1..-1])
  end

  return unless channel

  args = {
    as_user: true
  }
  if message[:thread_ts] || (message[:original] && message[:original][:thread_ts])
    args.merge!(thread_ts: message[:thread_ts] || message[:original][:thread_ts])
  end

  if message[:attachments] && !message[:attachments].empty?
    args.merge!(
      channel: channel,
      text: message[:code] ? "```\n#{message[:body]}\n```" : message[:body],
      parse: message[:parse] || 'full',
      unfurl_links: true,
      attachments: message[:attachments].to_json
    )
    client.chat_postMessage(args)
  elsif message[:file]
    path = message[:file][:path]
    args.merge!(
      channels: channel,
      file: Faraday::UploadIO.new(path, message[:file][:content_type]),
      title: message[:file][:title] || path,
      filename: File.basename(path),
      initial_comment: message[:body] || ''
    )
    client.files_upload(args)
  else
    args.merge!(
      channel: channel,
      text: message[:code] ? "```\n#{message[:body]}\n```" : resolve_send_mention(message[:body]),
      mrkdwn: true
    )
    client.chat_postMessage(args)
  end
end