Train a Markov model to generate poetry a la Robert Burns, pipe it via a Slackbot
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
corpus
.gitignore
.htaccess
Procfile
README.md
burnsbot.py
check_model.py
getenvs.py
markov_model.json
newrelic.ini
print_bot_id.py
requirements.txt
runtime.txt
train_markovmodel.py

README.md

Burns Bot

This project creates a Slackbot which produces poetry in the style of Robert Burns, generated by a Markov chain model. Code is included to train the Markov model and run the bot. I also wrote a blog post detailing the theory behind Markov chains and their implementation here.

Getting started

To install the bot on your slack team of choice, you will need admin access. Go to https://api.slack.com/bot-users and follow the instructions there to setup a bot user. Slack provides two pieces of information which much be saved as environmental variables. To do this, use the commands:

export SLACK_BOT_TOKEN=your_sb_token
export BOT_ID=your_bot_id

These two pieces of information confirm that your bot has the ability to read and write to your Slack channel. Be sure not to disclose them.

Installation

To install the dependencies required to run this package, simply run

pip install -r requirements.txt

Running your bot

In order for your bot to respond to a Slack message, it must be permanently running on a server. You can use Heroku - the project includes a Profile suitable for use on a Heroku instance - but you will need to find a way of keeping the instance awake, as merely messaging the bot will not suffice. I used a ping service provided by the add-on New Relic.

Alternatively, if you already have a Python equipped server you can host your bot there. Our Burns bot is hosted on the ASI data science platform, Sherlock ML.

Bot behaviour

Currently, the bot is limited to responding to messages in which it is tagged (@burnsbot), including the command 'write' and a number. It will respond with the specified number of lines of Burns-esque poetry.

More sophisticated behaviours might include writing acrostics to trace out specific words (by specifying the first letter of each line), 'poems of the day' produced on a schedule, or semi-relevant injection of Burnsesque poetry into ongoing conversations between other Slack users.

Other ideas

A similar framework could be used to provide a bot modelled on your favourite author; snippets from your favourite coding language; song lyrics; even song notes (if you could find a way of playing them in Slack). Fork away and go nuts.

Acknowledgements

Much of the Slackbot code comes from this blogpost and the associated github repo.

I am indebted to Alberto Favaro for the idea and for providing a Burns corpus in JSON form. Thanks to ASI Data Science for hosting the Burns night event.