The slack-api
provides a Ruby wrapper around the slack bot API. It can be installed with gem install slack-api
. It is then included in Ruby applications as simply require "slack"
.
In order to access a slack team, you must first create a bot for your team through the Slack web app, and obtain a unique token associated with the team.
Here is sample code for a basic bot that logs each message that it receives to the terminal:
require "slack"
client = Slack::Client.new token: "YOUR_UNIQUE_SLACK_TOKEN"
rtm = client.realtime
rtm.on :message do |m|
p "User #{m.user} said #{m.text}"
end
rtm.start