Class: Nuntius::SlackSlackProvider

Inherits:
BaseProvider show all
Defined in:
app/providers/nuntius/slack_slack_provider.rb

Instance Attribute Summary

Attributes inherited from BaseProvider

#message

Instance Method Summary collapse

Methods inherited from BaseProvider

all_settings, #callback, class_from_name, #initialize, #name, #refresh, setting_reader, states, transport

Constructor Details

This class inherits a constructor from Nuntius::BaseProvider

Instance Method Details

#deliverObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/providers/nuntius/slack_slack_provider.rb', line 11

def deliver
  client = Slack::Web::Client.new(token: api_key)

  message.attachments.each do |attachment|
    client.files_upload(
      channels: message[:to],
      as_user: true,
      username: message[:from],
      file: Faraday::UploadIO.new(StringIO.new(attachment.download), attachment.content_type),
      filename: attachment.filename.to_s
    )
  end

  args = (message.payload || {}).merge(channel: message[:to], text: message.text, as_user: true, username: message[:from])
  response = client.chat_postMessage(args.deep_symbolize_keys)

  message.status = if response["ok"]
    "sent"
  else
    "undelivered"
  end

  message
end