Class: Agents::SlackbotAgent

Inherits:
Agent
  • Object
show all
Defined in:
lib/huginn_slackbot_agent/slackbot_agent.rb

Instance Method Summary collapse

Instance Method Details

#default_optionsObject



19
20
21
22
23
24
25
26
# File 'lib/huginn_slackbot_agent/slackbot_agent.rb', line 19

def default_options
  {
    'channel' => '#general',
    'text' => 'It works',
    'as_user' => true,
    'attachments' => []
  }
end

#receive(incoming_events) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/huginn_slackbot_agent/slackbot_agent.rb', line 37

def receive(incoming_events)
  incoming_events.each do |event|
    interpolate_with(event) do
      options = {
        channel: interpolated['channel'],
        as_user: interpolated['as_user']
      }

      options[:text] = interpolated['text'] if interpolated['text'].present?
      options[:attachments] = interpolated['attachments'] if interpolated['attachments'].present? && interpolated['attachments'].any?

      client.chat_postMessage(options)
    end
  end
end

#validate_optionsObject



28
29
30
31
# File 'lib/huginn_slackbot_agent/slackbot_agent.rb', line 28

def validate_options
  errors.add(:base, 'you need to specify the channel or user name') unless options['channel'].present?
  errors.add(:base, 'you need to specify the text or attachments list') unless options['text'].present? || options['attachments'].any?
end

#working?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/huginn_slackbot_agent/slackbot_agent.rb', line 33

def working?
  received_event_without_error?
end