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