Friendbot is a Markov-chain based chatbot which uses Slack messages as its corpus. It reads in messages from a Slack data export, generates a corpus from them, and feeds this to a markov chain generator to naively simulate a conversation. It is built with Flask, served by Gunicorn, cached by Redis, and run in Docker. The sentences which it generates can be accessed via an API which is designed to connect to the existing Slack API.
Download the docker-compose.yaml
file (or clone this repo), and start by letting Friendbot know the location of your Slack export zip file by running
FB_EXPORT=<path to your Slack export> docker-compose up -d
All config is done via environment variables, listed below:
Parameter | Description | Default |
---|---|---|
FRIENDBOT_LOG_LEVEL |
Friendbot's log level | info |
FRIENDBOT_EXPORT_ZIP |
Path (inside Friendbot) to zip file containing the Slack Export | /home/friendbot/export.zip |
FRIENDBOT_REDIS_HOST |
Hostname of Redis instance used for cache | redis |
FRIENDBOT_REDIS_PORT |
Port number of Redis instance used for cache | 6379 |
FRIENDBOT_SECRET_FILE |
File containing a Signing Secret recieved from Slack, used to verify requests | nil |
This endpoint accepts HTTP POST
requests sentence generated using the export data. It reads the text
key of the POST
ed form and splits the value into arguments in the form of Slack channels <#CHANNEL>
or users <@USER>
. These are used to narrow the selection of messages Friendbot will read to generate its corpus. These arguments can be in any order and can also be left blank to include all channels/users. In most cases, responses from this endpoint will return a 200 status code, regardless of whether an error has occurred. This is because Slack does not follow the HTTP spec and uses 200 to indicate that a request has been received even if an error occurs.
This endpoint accepts HTTP POST
requests in the form of application/x-www-form-urlencoded
, extracts a JSON payload, sends a POST
request to the Slack API based on the interaction that initiated the request, and returns a 200 status code. This provides the interactive component of Friendbot messages. These interactions consist of sending a generated sentence to the channel, shuffling to generate a new sentence, and cancelling sentence generation.
This endpoint accepts HTTP GET
requests and returns metrics about Friendbot in a format that can be consumed by Prometheus.
This endpoint accepts HTTP GET
requests and returns 200 as long as the application is healthy. Used for Docker healthchecking.
- Docker
- Docker Compose