Create Slackbot in Ruby

 

I. Requirements

screen-shot-2017-02-23-at-09-53-03

II. Create ruby scripts


Slack.configure do |config|
 config.token = "xoxb-xxx-xxx-xxxx" #SLACK_API_TOKEN
 fail 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
 config.logger = Logger.new(STDOUT)
 config.logger.level = Logger::INFO
 # config.include DBConnection
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|
 client.typing channel: data.channel
 if data.text.include?('bot hi')
 msg ="Hey <@#{data.user}>"
 client.message channel: data.channel, text:(msg)
 end
end
client.on :close do |_data|
 puts 'Connection closing, exiting.'
end

In Slack setting page:  Browse Apps > Custom Integrations  >Bots –> create new bot integration

slackbot

Use SLACK_API_TOKEN in your ruby script:

screen-shot-2017-02-23-at-10-05-17

–> Start ruby script and go to slack app to see:

botai

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.