friendbot

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.

Installation

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

Configuration

All config is done via environment variables, listed below:

ParameterDescriptionDefault
FRIENDBOT_LOG_LEVELFriendbot's log levelinfo
FRIENDBOT_EXPORT_ZIPPath (inside Friendbot) to zip file containing the Slack Export/export.zip
FRIENDBOT_REDIS_HOSTHostname of Redis instance used for cacheredis
FRIENDBOT_REDIS_PORTPort number of Redis instance used for cache6379
FRIENDBOT_SECRET_FILEFile containing a Signing Secret recieved from Slack, used to verify requestsnil

API

/sentence

This endpoint accepts HTTP POST requests sentence generated using the export data. It reads the text key of the POSTed 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.

/action

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.

/metrics

This endpoint accepts HTTP GET requests and returns metrics about Friendbot in a format that can be consumed by Prometheus.

/health

This endpoint accepts HTTP GET requests and returns 200 as long as the application is healthy. Used for Docker healthchecking.

Requirements

  • Docker
  • Docker Compose
GitHub - barrelmaker97/friendbot: Markov-chain based chatbot which uses Slack messages as its corpus
Markov-chain based chatbot which uses Slack messages as its corpus - GitHub - barrelmaker97/friendbot: Markov-chain based chatbot which uses Slack messages as its corpus