Class: Pepito::Adapters::Slack

Inherits:
Adapter
  • Object
show all
Defined in:
lib/pepito/adapters/slack.rb

Overview

Adapter for slack

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(robot, config) ⇒ Slack

Returns a new instance of Slack.



30
31
32
33
34
35
36
37
38
39
# File 'lib/pepito/adapters/slack.rb', line 30

def initialize(robot, config)
  super(robot, config)

  configure_slack_api

  @client = ::Slack::RealTime::Client.new
  @client.web_client.auth_test

  slack_on_message
end

Instance Attribute Details

#clientSlack::RealTime::Client (readonly)

Slack RealTime client

Returns:

  • (Slack::RealTime::Client)


28
29
30
# File 'lib/pepito/adapters/slack.rb', line 28

def client
  @client
end

Class Method Details

.configsArray<Hash>

Configs needed for Slack

Returns:

  • (Array<Hash>)


16
17
18
19
20
21
22
23
# File 'lib/pepito/adapters/slack.rb', line 16

def configs
  [
    {
      name: 'SLACK_API_TOKEN',
      required: true
    }
  ]
end

Instance Method Details

#runvoid

This method returns an undefined value.

Runs the slack client



43
44
45
# File 'lib/pepito/adapters/slack.rb', line 43

def run
  @client.start!
end

#send_messages(target, strings) ⇒ void

This method returns an undefined value.

Send messages to slack.

Parameters:

  • target (Pepito::Source)

    Where to send the message to.

  • strings (Array<String>)

    Strings to output.



51
52
53
54
55
56
57
# File 'lib/pepito/adapters/slack.rb', line 51

def send_messages(target, strings)
  message = ''
  strings.each do |s|
    message = message + s + "\n"
  end
  @client.message(channel: target.room, text: message)
end

#stopvoid

This method returns an undefined value.

Stops the client



68
69
70
# File 'lib/pepito/adapters/slack.rb', line 68

def stop
  @client.stop!
end

#topic(target, topic) ⇒ void

This method returns an undefined value.

Set topic

Parameters:

  • topic (String)

    new topic string



62
63
64
# File 'lib/pepito/adapters/slack.rb', line 62

def topic(target, topic)
  @client.web_client.channels_setTopic(channel: target.room, topic: topic)
end