Class: Xify::Output::RocketChat

Inherits:
Base::RocketChat show all
Defined in:
lib/xify/output/rocket_chat.rb

Instance Method Summary collapse

Methods inherited from Base::RocketChat

#initialize, #request

Constructor Details

This class inherits a constructor from Xify::Base::RocketChat

Instance Method Details

#process(event) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/xify/output/rocket_chat.rb', line 10

def process(event)
  request :post, '/api/v1/chat.postMessage' do |req|
    req['Content-Type'] = 'application/json'
    if @config['alias']
      author = event.author
      title = event.args[:parent]
    else
      author = nil
      title = "#{event.args[:parent]} by #{event.author}"
    end

      req.body = {
        channel: @config['channel'],
        alias: author,
        attachments: [
          {
            title: title,
            title_link: event.args[:parent_link],
            text: event.args[:link] ? "#{event.message.chomp}\n\n([link to source](#{event.args[:link]}))" : event.message.chomp
          }
        ]
      }.to_json
  end
end