Babur is ml-based real-time Slack Bot. It categorizes the messages sent to the channels you specify in Slack and returns the answers you specify.
- create environment:
conda env create -f=environment.yaml
conda activate babur
- Firstly you should have labeled data to train a model.
If you don't have data
You can listen your slack channels and write them to the google sheets or excel.- We have
slack_message_helper
class. - In this class we get trained model, listen message and analyse, return answer, write to google sheet all of data. Now you dont have trained model yet. So you should use just listen messages and write to google sheet. After you can label messages and train a model with them.
- In model.py we get our messages from Google Bigquery.(We connect google sheet to google bigquery.) If your data on local csv file or others, you can use load_data_from_csv_file or you can write your own.
- You should explain your google application credential to use google bigquery.
export GOOGLE_APPLICATION_CREDENTIALS=path-to-your-key-json-file.json
- In the rest, we create the best model by trying many algorithms.
First you need to fill there according yourself.
- LISTENING_CHANNELS: We just listen, not answer yet. (So if you collect data first, you can get the IDs of channels you will listen to here.)
- TARGET_CHANNELS: We listen and answer to this channels.
We have slack_message_helper class.
Function | Description |
---|---|
get_response | Get the message, analyse them via analyze_message function, return response which you determine. |
analyze_message | Get the message, applies to preprocess steps, return models prediction. |
get_sheet_cover | Write message metada which you specify to google sheet. |
- You need to have app in slack. Check here.
- If you have, open your slack app page
- Open Event Subscription page and give your domain with "/slack/events" endpoint.(If you run on local, you can use ngrok.)
- Make sure that you have the necessary permissions.
-
We're on bot.py
-
You should give your slack_api_token and signing secret.
-
We have a function app.event("message") here. This listens every message from channels which bot added in.
-
In the rest of function we return answers with using slack_message_helper class. We dont return answers to our team members so we add them to no_reply_team_members.
-
Our web application will be run on the 5000 port. Remember, we gave our endpoint to slack. Slacks send each message payload to us via a POST request.
-
We use gunicorn to serve our application. We can use a shell script to run the app. Create a file called run.sh with the following content.
sh run.sh
-
We build an Nginx server to manage our application requests. Start with creating a folder named nginx that contains two files nginx.conf and project.conf.
-
Under nginx folder we got Dockerfile . This file will create an image with our Nginx configurations.
-
Create docker image for bot here
-
To stand up our container create docker-compose.yml
-
We create train.sh to schedule training model with cron job.
-
Finally build our images and start!
docker-compose build --no-cache
docker-compose up -d
- Messages come from slack to our app.
- If we listen this message channel:
- Get the message
- Analyse message with the best model
- Predict message content and return answer according to content.
- We also save the incoming message to excel. We can label the messages in excel and use them to train our model.
Distributed under the MIT License. See LICENSE for more information.
Please give your feedback ❤️ Happy coding!