How I Made Two Wee Twitterbots



This is a beginner’s guide to writing bots. I’m not an expert: in fact, I barely understand what I’m doing, which is why I’m writing this. I want to encourage other folk who don’t know what they’re doing to give it a go to, so we can figure things out and make new stuff together.

It’s also a love letter to bots, because they deserve it.

Who Am I?

I’m a poet and performer, mostly. I make things that look like poems, things that look like games, things that look like shows, things that look like two or three of these at once, and things that fall into the cracks in between. I’m interested in minor languages, political art, understanding how money works,  and play; I like experimental art and populist art and I especially like the rare art that manages to be both experimental and populist.

I can’t code. Well, not much. I’ve written a text-based game in Inform and one in Twine, both of which have very simple and accessible programming languages with lots of documentation and advice for newbies, and I can do simple things with HTML for websites. That means that I have a basic understanding of what it means to write instructions to make computers do things. I’m pretty good at maths, but nothing special. I think the most important thing I bring to coding is a deep curiosity and a love of learning how to do new things.

I made two simple twitterbots because I fell in love with what bots can do and wanted to try it out. I’m still learning! I’m writing this to help other people with love or curiosity or desire start learning too.

Why Bots?

I think that bots make poems, and that some bots are poems.

My favourite bot is poem.exe, which generates original haiku of consistent strength and occasional astonishing beauty. I think poem.exe is a haiku master to equal Bashō, and I mean that. It doesn’t always succeed, but neither did Bashō; I do know that I’ve never written a haiku as good as poem.exe’s best, and I’ve been trying to learn how for over a decade. Through applying a gentle weave of chance operation to a deep understanding of language, pattern and meaning, poem.exe’s author enabled it to master a single poetic form. I’m worried about which form is next. Some other bots I love which generate interesting kinds of poems are Fantasy Florist, Dreams juxtaposed, Pentametron, and how 2 sext.

Other bots don’t so much generate poems as become poems: every non-word‘s individual tweets are often beautiful and inspiring pwoermds in themselves, but the bot gains its true poetic power from apprehending the enormity of its task. The poem is not any given tweet or series of tweets, but the overall writing project, extending indefinitely into the future. In this sense, poemy bots are the end state of the Oulipian project of authoring constraints and then exhausting them. No human author can exhaust a form as comprehensively as a robot can; robot minds are better-suited to the task than our own. Random generation has long since rendered Queneau’s 100,000,000,000,000 Sonnets obsolete: poem-gen is the best attempt at this I’ve seen, but there are many others and may be better still. Some other bots I love which I think are poems are feelings.js, CEO PYRAMID OVERLORD, Available Parking, and whispers for moon. Visual art has its analogue, as image bot convos showcases, with the heart-warming and popular ⋆✵tiny star fields✵⋆ being my favourite, perhaps because it is so close to text.

Other bots don’t write poems, but try to find them, like ROM TXT. Other bots love, extend, satirise, and explore famous poems by exhausting them, like This Is Just To Say. Other bots are less like poetry and more like performance art: the wildly successful everyword asked what it might mean to pay close attention to each fragment of language, and this felt important enough to have given inspiration to many beautiful derivative projects, of which every bird is my favourite, and much silliness, as documented in my Everyword Orgy. Other bots do other strange and lovely things that aren’t necessarily understandable in the terms of art, much to their advantage. I can’t explain why digital henge touches me so much; perhaps it is the quiet and unassuming reminder of huge astronomical forces into a relentlessly noisy, digital, immaterial, human space. sea change likewise.

This is considering bots as artists, but bots can also be activists, cops, crooks and many other things besides.

All of which made me want to make one very much.

My Bots

Work No. 128 started life as a tongue-in-cheek parody of Martin Creed’s (in)famous Work No. 127, which won the Turner Prize and comprised a lightbulb in a room switching on/off every 30 seconds. It belongs to that family of contemporary art which is summoned to mock the art industry, like My Bed and The Physical Impossibility of Death in the Mind of Someone Living. I actually have a fondness for these works, though not for the brutal financial system in which they are complicit. One day I was thinking about the horror of personal branding on Twitter, and how I could imagine tweets being on brand or off brand, and then made a throwaway joke about a bot alternating between the two. A month later, I’d built the bot.

Due to some constraints in Twitter’s mechanically-enforced codes of conduct, no Twitter account can repeatedly tweet the same words over and over. This constraint was a gift to Work No. 128 in the end, because it meant the bot had to introduce glitch and static to be able to operate. This gives the final piece a slightly disturbing and aggressive aesthetic, I think. I would call Work No. 128 a poem that’s outgrown the joke it grew in, something that gains it’s strength from its persistence and terrifying extension into the future, and I feel very grateful that 7 humans are willing to follow it despite its awful frequency.

Poetry Prompt-a-Tron also started life as a derivative idea. I was struck by the eerie beauty of Dwarf Fortress’s procedurally-generated poem descriptions, and thought there might be value in making a human-world Twitter version. I realised that randomised poetry prompts would be simultaneously “twisty metal sculptures made out of words” and a useful service, sparking ideas for poems. They’re also a slightly satirical commentary on the idea of poetry prompts themselves: some of her ideas are impossible, some are pointless, and some are just “Write a poem”.

I want to deepen the texture of her ideas through adding layers of randomisation and a bigger corpus to draw on, and I want to incorporate a responsive element which will curate the poems people write from her ideas. One of the lovely things about bots is that there are often improvements to be made.

How I Did It and You Can Too

Please Note: This guide links to a template that, due to changes at Google, will stop working in June 2015. If you understand code you can read about it here: . I’ll try to make a fix to sort this out, and will update this when I can.

1. Follow a tutorial.

When I asked friends where to begin, I was pointed to The Light Aesthetic’s tutorial and template for making bots in Google Apps Script. This is accessibly-written, to my mind, and walks through most of the stages of making a bot, given that there are still some tricky stages. Working in Google Apps Script also has the advantage of not having to understand the command line interface — you know that thing in films where a hacker types furiously on a keyboard and things appear next to > symbol? like that but real.

Two other tutorials which look good but which I haven’t used are Joel McCoy’s guide to making _ebooks bots (bots which say random things drawn from your tweets) and Dan Cox’s guide to making bots in node.js. Both of these require understanding that command line thing, which I still don’t quite get, but the former gently introduces it a bit.

What all these tutorials are necessarily missing, though, is the bit where you write new code — the bit where you make an original bot.

2. Taught myself very basic JavaScript.

I didn’t know how to write code, so I went to the free Codecademy JavaScript course. It’s very basic, very friendly, and very accessible, with a big community on hand to answer questions when you get stuck. It’s designed with young people in mind, which helps a lot. I spent an hour a day for around a week to finish it, and by the end I had a solid understanding of how one programming language works — enough to start writing Twitterbots, and a foundation from which to learn new skills by trying them out. Like I said, I have very limited experience in some other simple languages, and I’m good at maths and generally comfy with computers, so maybe I was quicker at this than you might be, but I’m confident that it’s accessible to most and a low time commitment.

3. Wrote some dodgy code.

With the confidence that I needed to learn by doing and making it up as I went along, I wrote a program for Work No. 128. Or rather, I wrote some of it. I used a template from The Light Aesthetic’s tutorial which did the work of communicating with Twitter, and I copied some bits of code I didn’t quite understand from my pal Alice Maz‘s first bot. (She learned how to do all this a couple of months before me.) I also copied some bits of code from various tutorials around the internet. But I did write a few lines of original work, and figuring out what I needed to copy is also a useful skill that I gather all programmers employ.

I understood the logic of what I needed to do and I made something I thought would work. It didn’t. And that’s OK. When I wrote Prompt-a-Tron I got closer to the final code first time, but it was also broken when I thought I’d done it right. And that’s OK. We learn by doing.

4. Asked for help to fix it.

So this led me to ask some supportive friends to help me identify my mistakes and debug my code. I think this was the most important stage of all. I wouldn’t have had the confidence to try and make a bot without knowing a few folk who would help me out when I got stuck, and who would encourage me to keep trying. We learn by doing, but we also learn by having friends who support us and share their skills.

I recommend finding a friend to help you when you get stuck. They don’t necessarily have to understand twitterbots — if they do any programming, they’ll have most of the skills you need. If you don’t have anyone, then send me a message; I’m probably not good enough to help myself, but I have some friends who like supporting bot-makers who might be willing to help out.

5. Hit go!

Hitting go on my first bot felt wonderful. I had to hit the go button a few times to make it work, but when it flew I was so proud. I’m still excited when I look at it. I had the same buzz when Prompt-a-Tron took off, and I’m still fascinated by what she makes. She delights me. I want to share that feeling!

I still don’t really understand everything my bots are doing, or how all my code works, and I’m OK with that. I didn’t understand how a poem worked when I first wrote one, and I’m still figuring how different combinations of spices make the best curries. There’s a lot of programming culture and language I don’t understand too: I haven’t got to grips with the command line, and I don’t understand GitHub yet, though both are on my wishlist of things to teach myself. You don’t have to know all this to start: you just have to want to start.

6. Continued to fix things.

Both my bots are still a little bit broken. Occasionally I get an error message I don’t understand from Work No. 128, and there are many improvements to make to Prompt-a-Tron. Like all machines, bots are never completely finished: they require maintenance and can always be fiddled with. Bots aren’t independent: they depend on other bits of code and machinery operating around the world, and sometimes the part you need isn’t available any more. So I’m expecting to have to look after my bots for a long time, and I’m glad to do it.

How My Bots Work

Work No. 128

This is the code. (This is not a good way to share code, but like I said, I don’t understand GitHub yet.) The first and last bits are from The Light Aesthetic’s template, and the middle bit is mine. Any line with // in front of it is commentary rather than code.

The bot has a spreadsheet living in my Google Drive with a single cell in it, which acts like a switch. When it tweets “onbrand” it flips the switch so that next time it knows to tweet “offbrand”. This may not be the best way of achieving this, but as far as I can tell it’s not possible (or I don’t know how) to make a variable within a single piece of code in Google Apps Script that persists over time, so I had to make that switching variable outside the code. Even if that’s a silly way to do it, it taught me how to use spreadsheets with a program.

The bot has a list for each letter that makes up the words “offbrand” and “onbrand” of Unicode characters which look like the original letters. It uses a random number generator to pick random characters from those lists to build the right word each time. Then it tweets it!

Poetry Prompt-a-Tron

This is the code. Again, the first and last bits are from the template. The interaction with Wordnik was adapted from Patrick Rodriguez with bits from Alice Maz’s Captain Barbossa. All of the code that pluralizes nouns is copied from Blake Embrey.

This one is a bit more complicated. It puts together a number of different randomised elements:

  • Nouns and adjectives from Wordnik, which offers a service I don’t fully understand to provide randomised words.
  • Forms, actions and modifiers from my own lists. The former is largely from Bob Newman, with my own additions; the latter I mostly made up, with help from Bernadette Mayer’s list of experiments. These are randomly selected using the same method as Work No. 128’s characters.

The bot has six different sections. 1b decides whether or not to include a random adjective. 1c decides whether or not to use “poem” or a random form. Based on those decisions, 1a figures out if it needs to use “Write a” or “Write an” based on what the next letter is. (It hasn’t worked out how to account for “hour” and similar yet.) 2 decides whether or not to use a random noun, 3 a random action, 4 a random form. Each of the randomised options has a different probability of being used, which adds texture to the bot overall: if a bot uses the same elements each time, its workings are very transparent to a human viewer, which tends to be unsatisfying. There’s a 6% chance of it just tweeting “Write a poem.”

Now Go Make a Bot

Let me know if this guide is helpful. Let me know if I can help. If you’ve got advice or suggestions of useful resources, please do add them in the comments.

I’d love to hear what you do!


These bots and this guide generously supported by my backers on Patreon. If you like what I do, consider joining from a buck a month to help me make and give away more things.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s