If you know me, you know I love a good pub quiz. Most of the time I play them on my own just for fun, but there is one weekly quiz in which I have a table at every week and potentially more players on the team than the maximum allowed. It’s rarely a problem because every week there’s normally somebody who can’t make it, but from time to time I get more requests to join than I have seats, so I turned to one of my other passions – coding – to solve the problem.
The goal was to create a ChatBot that sits on WhatsApp which can gather together all the info about who’s coming or not and be able to confirm a seat based on a specific set of rules.
The first rule is if you were on a winning team the week before, you have priority at the next quiz because it’s only fair you should have a crack at your share of the bar tab. The second rule is that team regulars get priority over guest players unless rule one applies. The third rule is all bets are off by 2pm on the day of the quiz, and then it’s just first-come, first-served until the table is full.
So I set about writing this all in code so that I could throw a player name at it and it would respond whether there was a seat for them; whether they would have to wait until after 2pm on the day of the quiz, or whether the table was already full. So far, so good.
I then wrote a little interpreting engine which would take free text input and look for keywords and phrases so team players could interact with the bot via WhatsApp. These were things like ‘I’m quizzing’, ‘Who’s playing’ and ‘I’m not quizzing for the next 2 weeks’. I also built in some admin commands so I could manage the team via the same ChatBot without having to do it directly in the database.
The frustration of interacting with WhatsApp’s API aside (it’s a nightmare), I managed to pull this all together pretty quickly and had something working in little under a week. I dubbed the bot ‘Gloria’ and launched it to test with the team – and I should have known, because the first thing they were doing was swearing at it. Minds in the gutter, but I shouldn’t have been surprised.
Rather than responding with a stock ‘sorry, I don’t understand’ message, I figured Gloria needed to clap back. So now about half the code is dedicated to dealing with when one of my lovely team members tries to insult Gloria. Some of the choice responses to insulting the bot include “I have neither the time nor the crayons to explain this to you.”; “You’re as useless as Anne Frank’s drum kit.” and “I’ve met some pricks in my time, but you’re a fucking cactus.”
Then I decided to go a little further. If you enter a message Gloria can’t pick any keywords from, you still get “sorry, I don’t understand”. Very boring. So I hooked up that final step to OpenAI and threw the message at them. So if you were to say “What’s the capital of Belgium?” you’d actually get the answer – but rather than the dull tones of an AI robot replying, “The capital of Belgium is Brussels.”, I built a list of styles of responses one of which gets tagged onto the message sent to OpenAI, so you might get the sarcastic reply “Oh, you know, just a little place called Brussels. It’s not like it’s the headquarters of the European Union or anything—totally off the radar!”, or the answer as a limerick.
Come for Gloria at your peril.
Add comment
You must be logged in to post a comment.