Skip to content

Instantly share code, notes, and snippets.

@christopherfujino
Last active August 30, 2017 18:17
Show Gist options
  • Save christopherfujino/83dac561bf26223d584333b2b219b0f9 to your computer and use it in GitHub Desktop.
Save christopherfujino/83dac561bf26223d584333b2b219b0f9 to your computer and use it in GitHub Desktop.
Slack-api Gem

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment