A Slack bot that adds two numbers. Built with Ruby.
Explore the docs »
Video Demo
·
Report Bug
·
Request Feature
A simple slack chat bot that adds two numbers. Eg: when the user types to the bot 234 + 123
, it responds back with 357
.
- slack-ruby-bot-server
- slack-ruby-bot-server-events
- mongodb
- mongoid
IMPORTANT! Checkout this video first - https://www.loom.com/share/07050cd0480c4109b01ad411b9e92189
Deployed to Heroku - https://enigmatic-thicket-31440.herokuapp.com/
To get a local copy up and running follow these simple steps.
- MongoDB
- Ruby
- Admin access to a Slack Workspace.
-
Create a new Slack app from here
-
Scroll down and you will find the App Credentials section. Take note of these four fields:
- Client ID
- Client Secret
- Signing Secret
- Verification Token
You will need these later.
-
Go to OAuth & Permissions. You will find this option in the side bar.
-
Scroll down to Scopes and add these 👇 scopes one-by-one to Bot Token Scopes:
users:read
channels:read
groups:read
chat:write
commands
im:history
incoming-webhook
-
Go to Event Subscriptions. You will find this option in the side bar. Then enable events.
-
Click on Subscribe to bot events. Then click on the Add Bot User Event button. Then add
message.im
event.Everytime you send a direct message to the bot, the
message.im
event will be fired. -
Now you have to install this app to your workspace. Go to Basic Information. You will find this option in the side bar. Then click the Install to Workspace button.
-
In the next page, you will be asked to Allow the bot permissions. In the last permission (Where should Example Bot post?), select any channel.
-
Clone this repository.
git clone https://github.com/tirthajyoti-ghosh/slack-adder-bot.git
-
Create an
.env
file in the root directory. Then fill these 👇 with their respective values (client id, client secret, etc. from slack app). The values must be put after the=
sign.SLACK_CLIENT_ID= SLACK_CLIENT_SECRET= SLACK_SIGNING_SECRET= SLACK_VERIFICATION_TOKEN=
-
Run
bundle install
andforeman start
to boot the app.$ foreman start 07:44:47 web.1 | started with pid 59258 07:44:50 web.1 | * Listening on tcp://0.0.0.0:5000
-
Since Slack won't send a POST request to
localhost
, we need to expose our local server through a public tunneling service. You can use ngrok.$ ngrok http 5000 Forwarding https://ddfd97f80615.ngrok.io -> http://localhost:5000
-
Go to Event Subscriptions in your Slack apps dashboard. You will find this option in the side bar. Then paste this URL in the Request URL field:
<your ngrok URL>/api/slack/event Eg., https://ddfd97f80615.ngrok.io/api/slack/event
-
Click on Save Changes if necessary.
Start a direct chat with the bot. The input must be in this format => 6+3
. If the input does not have two numbers and an addition symbol in between, respond back with a error message - "Sorry, I didn't understand that. I only add numbers in this format. eg: 5+6 or 6+3".
- Add tests.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
👤 Tirthajyoti Ghosh
- Website: ghosh.tech
- GitHub - @tirthajyoti-ghosh
- Twitter - @terrific_ghosh
- LinkedIn - @tirthajyoti-ghosh
Project Link: https://github.com/tirthajyoti-ghosh/slack-adder-bot
- slack-ruby-bot-server
- slack-ruby-bot-server-events
- slack-ruby-bot-server-events-sample
- README icon from Icons8