https://github.com/tirthajyoti-ghosh/slack-adder-bot
A simple slack chatbot that adds two numbers. Eg: when the user types to the bot `234 + 123`, it responds back with `357`. Built with Ruby.
https://github.com/tirthajyoti-ghosh/slack-adder-bot
mongodb mongoid ruby slack-bot slack-ruby-bot-server
Last synced: 2 months ago
JSON representation
A simple slack chatbot that adds two numbers. Eg: when the user types to the bot `234 + 123`, it responds back with `357`. Built with Ruby.
- Host: GitHub
- URL: https://github.com/tirthajyoti-ghosh/slack-adder-bot
- Owner: tirthajyoti-ghosh
- License: mit
- Created: 2020-12-21T21:00:55.000Z (over 5 years ago)
- Default Branch: development
- Last Pushed: 2020-12-24T16:51:41.000Z (over 5 years ago)
- Last Synced: 2025-03-16T05:42:47.144Z (over 1 year ago)
- Topics: mongodb, mongoid, ruby, slack-bot, slack-ruby-bot-server
- Language: Ruby
- Homepage: https://enigmatic-thicket-31440.herokuapp.com/
- Size: 83 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![License: MIT][license-shield]][license-url]
[![LinkedIn][linkedin-shield]][linkedin-url]
Slack Adder Bot
A Slack bot that adds two numbers. Built with Ruby.
Explore the docs ยป
Video Demo
ยท
Report Bug
ยท
Request Feature
## Table of Contents
* [About the Project](#about-the-project)
* [Built With](#built-with)
* [Getting Started](#getting-started)
* [Prerequisites](#prerequisites)
* [Installation](#installation)
* [Setting Up Slack](#setting-up-slack)
* [Setting Up Web Hook](#setting-up-web-hook)
* [Usage](#usage)
* [Roadmap](#roadmap)
* [Contributing](#contributing)
* [License](#license)
* [Contact](#contact)
* [Acknowledgements](#acknowledgements)
## About The Project
A simple slack chat bot that adds two numbers. Eg: when the user types to the bot `234 + 123`, it responds back with `357`.

### Built With
* slack-ruby-bot-server
* slack-ruby-bot-server-events
* mongodb
* mongoid
## Live demo
**IMPORTANT!** Checkout this video first -
Deployed to Heroku -
## Getting Started
To get a local copy up and running follow these simple steps.
### Prerequisites
* MongoDB
* Ruby
* Admin access to a Slack Workspace.
### Setting Up Slack
1. Create a new Slack app from [here](https://api.slack.com/apps?new_app=1)
2. 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.
3. Go to **OAuth & Permissions**. You will find this option in the side bar.

4. 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`

5. Go to **Event Subscriptions**. You will find this option in the side bar. Then enable events.

6. 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.
7. 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.

8. 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.

### Installation
1. Clone this repository.
```bash
git clone https://github.com/tirthajyoti-ghosh/slack-adder-bot.git
```
2. 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.
```text
SLACK_CLIENT_ID=
SLACK_CLIENT_SECRET=
SLACK_SIGNING_SECRET=
SLACK_VERIFICATION_TOKEN=
```
3. Run `bundle install` and `foreman start` to boot the app.
```bash
$ foreman start
07:44:47 web.1 | started with pid 59258
07:44:50 web.1 | * Listening on tcp://0.0.0.0:5000
```
### Setting Up Web Hook
1. 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](https://ngrok.com/).
```bash
$ ngrok http 5000
Forwarding https://ddfd97f80615.ngrok.io -> http://localhost:5000
```
2. 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:
```text
/api/slack/event
Eg.,
https://ddfd97f80615.ngrok.io/api/slack/event
```

3. Click on **Save Changes** if necessary.
## Usage
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".

## Roadmap
* Add tests.
## Contributing
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**.
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## License
Distributed under the MIT License. See `LICENSE` for more information.
## Contact
๐ค **Tirthajyoti Ghosh**
* Website: [ghosh.tech](https://ghosh.tech/)
* GitHub - [@tirthajyoti-ghosh](https://github.com/tirthajyoti-ghosh)
* Twitter - [@terrific_ghosh](https://twitter.com/terrific_ghosh)
* LinkedIn - [@tirthajyoti-ghosh](https://www.linkedin.com/in/tirthajyoti-ghosh/)
Project Link: [https://github.com/tirthajyoti-ghosh/slack-adder-bot](https://github.com/tirthajyoti-ghosh/slack-adder-bot)
## Acknowledgements
* [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server)
* [slack-ruby-bot-server-events](https://github.com/slack-ruby/slack-ruby-bot-server-events)
* [slack-ruby-bot-server-events-sample](https://github.com/slack-ruby/slack-ruby-bot-server-events-sample)
* README icon from Icons8
[contributors-shield]: https://img.shields.io/github/contributors/tirthajyoti-ghosh/slack-adder-bot.svg?style=flat-square
[contributors-url]: https://github.com/tirthajyoti-ghosh/slack-adder-bot/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/tirthajyoti-ghosh/slack-adder-bot.svg?style=flat-square
[forks-url]: https://github.com/tirthajyoti-ghosh/slack-adder-bot/network/members
[stars-shield]: https://img.shields.io/github/stars/tirthajyoti-ghosh/slack-adder-bot.svg?style=flat-square
[stars-url]: https://github.com/tirthajyoti-ghosh/slack-adder-bot/stargazers
[issues-shield]: https://img.shields.io/github/issues/tirthajyoti-ghosh/slack-adder-bot.svg?style=flat-square
[issues-url]: https://github.com/tirthajyoti-ghosh/slack-adder-bot/issues
[license-shield]: https://img.shields.io/badge/License-MIT-yellow.svg
[license-url]: https://github.com/tirthajyoti-ghosh/slack-adder-bot/blob/development/LICENSE
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555
[linkedin-url]: https://www.linkedin.com/in/tirthajyoti-ghosh/