Skip to content

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.

License

Notifications You must be signed in to change notification settings

tirthajyoti-ghosh/slack-adder-bot

Repository files navigation

Contributors Forks Stargazers Issues License: MIT LinkedIn


Logo

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

A simple slack chat bot that adds two numbers. Eg: when the user types to the bot 234 + 123, it responds back with 357.

Screenshot

Built With

  • slack-ruby-bot-server
  • slack-ruby-bot-server-events
  • mongodb
  • mongoid

Live demo

IMPORTANT! Checkout this video first - https://www.loom.com/share/07050cd0480c4109b01ad411b9e92189

Deployed to Heroku - https://enigmatic-thicket-31440.herokuapp.com/

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

  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

    image

    You will need these later.

  3. Go to OAuth & Permissions. You will find this option in the side bar.

    image

  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

    image)

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

    image

  6. Click on Subscribe to bot events. Then click on the Add Bot User Event button. Then add message.im event.

    image

    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.

    image

  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.

    image

Installation

  1. Clone this repository.

    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.

    SLACK_CLIENT_ID=
    SLACK_CLIENT_SECRET=
    SLACK_SIGNING_SECRET=
    SLACK_VERIFICATION_TOKEN=
    
  3. Run bundle install and foreman 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

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.

    $ 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:

    <your ngrok URL>/api/slack/event
    
    Eg.,
    
    https://ddfd97f80615.ngrok.io/api/slack/event
    

    image

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

usage

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

Project Link: https://github.com/tirthajyoti-ghosh/slack-adder-bot

Acknowledgements

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published