forked from slack-ruby/slack-ruby-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hi.rb
28 lines (23 loc) · 716 Bytes
/
hi.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true
require 'slack-ruby-client'
Slack.configure do |config|
config.token = ENV['SLACK_API_TOKEN']
raise 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
end
client = Slack::RealTime::Client.new
client.on :hello do
puts(
"Successfully connected, welcome '#{client.self.name}' " \
"to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
)
end
client.on :message do |data|
puts data
case data.text
when 'bot hi'
client.web_client.chat_postMessage channel: data.channel, text: "Hi <@#{data.user}>!"
when /^bot/
client.web_client.chat_postMessage channel: data.channel, text: "Sorry <@#{data.user}>, what?"
end
end
client.start!