https://github.com/hashrocket/slack-command-api
A Sinatra API for processing custom Slack commands
https://github.com/hashrocket/slack-command-api
Last synced: about 1 year ago
JSON representation
A Sinatra API for processing custom Slack commands
- Host: GitHub
- URL: https://github.com/hashrocket/slack-command-api
- Owner: hashrocket
- Created: 2015-04-20T14:26:52.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2017-01-24T18:51:01.000Z (over 9 years ago)
- Last Synced: 2025-03-27T14:21:17.385Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 43 KB
- Stars: 12
- Watchers: 10
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Slack Command API [](https://heroku.com/deploy?template=https://github.com/hashrocket/slack-command-api)
This Sinatra API converts custom Slack commands into Bot messages.
The API will post to your current channel by default, but you can specify a channel: `/late 10AM #another_channel`
Example:
A `/late 10AM` command converts to a text response **Hey team, I'm gonna be in around 10AM.**
## Dependencies
* RVM
* Sinatra
* Testing: RSpec
## Getting Started
1. `git clone` the app
2. `cd` into the folder.
3. Bundle the gems. `bundle install`
4. Set your Slack webhook environment variable. Create a `.env` file. Populate it with a `SLACK_URL` variable for your app's incoming webhook.
4. Run the app with `bundle exec passenger start`
## Adding a New Command in 2 steps
Create a message object that constructs a message, gives the bot a name, and gives it an emoji.
```
class YourCommandMessage
def construct_message(text, user_name)
"This text will show up in Slack and can show the #{user_name} of who issued the command, along the #{text} of the command"
end
# Your bot will be named 'Your-Command-Bot'
def bot_name
'Your-Command-Bot'
end
# This will show a whale icon for your chat bot
def icon_emoji
':whale:'
end
end
```
Add a post url to `app.rb`
```
# ...
require_relative 'your_command_message'
# ...
post '/your_command_url' do
response = Response.new(params, YourCommandMessage.new)
Slack.new(response).post
end
# ...
```
Done.
## Testing
1. Head to the spec folder. `cd spec`
2. Run the tests with `rspec --color --format documentation`
## Credits
Maintainer: [Joshua Plicque](https://twitter.com/GoHard_EveryDay)
If you have any questions, send me a tweet.