Class: SlackBot::Client
- Inherits:
-
Object
- Object
- SlackBot::Client
- Defined in:
- lib/simple_slack_bot/client.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#slack_realtime_client ⇒ Object
Returns the value of attribute slack_realtime_client.
-
#slack_web_client ⇒ Object
Returns the value of attribute slack_web_client.
Instance Method Summary collapse
- #add_command(regex) ⇒ Object
- #config ⇒ Object
- #configure ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #message(channel, text) ⇒ Object
- #start! ⇒ Object
- #web_message(channel, text) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/simple_slack_bot/client.rb', line 9 def initialize @commands = [] end |
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
6 7 8 |
# File 'lib/simple_slack_bot/client.rb', line 6 def commands @commands end |
#slack_realtime_client ⇒ Object
Returns the value of attribute slack_realtime_client.
5 6 7 |
# File 'lib/simple_slack_bot/client.rb', line 5 def slack_realtime_client @slack_realtime_client end |
#slack_web_client ⇒ Object
Returns the value of attribute slack_web_client.
5 6 7 |
# File 'lib/simple_slack_bot/client.rb', line 5 def slack_web_client @slack_web_client end |
Instance Method Details
#add_command(regex) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/simple_slack_bot/client.rb', line 13 def add_command(regex) command = Command.new(self) command.regex = regex command.action = -> (data) { yield(data) } @commands << command end |
#config ⇒ Object
34 35 36 |
# File 'lib/simple_slack_bot/client.rb', line 34 def config Config end |
#configure ⇒ Object
38 39 40 |
# File 'lib/simple_slack_bot/client.rb', line 38 def configure block_given? ? yield(Config) : Config end |
#message(channel, text) ⇒ Object
46 47 48 |
# File 'lib/simple_slack_bot/client.rb', line 46 def (channel, text) @slack_realtime_client. channel: channel, text: text end |
#start! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/simple_slack_bot/client.rb', line 20 def start! if config.token.nil? puts 'You must setting a token.' return end slack_init EM.run do @slack_realtime_client.start! end end |
#web_message(channel, text) ⇒ Object
42 43 44 |
# File 'lib/simple_slack_bot/client.rb', line 42 def (channel, text) @slack_web_client.chat_postMessage(channel: channel, text: text, as_user: true) end |