For our upcoming series of workshops, The Three Pillars of the Digital, we needed a quick introduction to writing Twitter bots. The result was Markov Duck, a sort of parody of Twitter bots that nevertheless embodies some useful tricks and techniques.

Markov Duck combines three simple Twitter bot themes in a completely arbitrary way:

  • Text generation using Markov chains
  • Word replacement
  • Algorithmic image generation

The first is done using a Markov chain built from Hermann Melville’s epic Moby Dick, Robert Barnwell Roosevelt’s The Game-Birds of the Coasts and Lakes of the Northern States of America and Thornton W. Burgess’s The Adventures of Poor Mrs Quack. The first of these is much longer and so dominates, but occasionally a random quail or Mrs Quack makes a welcome appearance.

This kind of text generation (though not necessarily this exact technique) is used by bots such as @lowanimalspirit, @MythologyBot, @str_voyage, @oliviataters, @thinkpiecebot and Allison Parrish’s The Ephemerides, about which she observes:

both space probes and generative poetry programs venture into realms inhospitable to human survival and send back telemetry telling us what is found there. For space probes, that realm is outer space. For generative poetry programs, that realm is nonsense.

The second theme is very simple: it replaces whales with ducks. This is a simple matter of string manipulation that can easily be done in almost any language. Many simple Twitter bots do this and it’s a good thing to try as a first project.

The third is realised by some messy code with a lot of random parameters; it still isn’t very good. It proves a point about how to go about the mechanical task of generating an image procedurally and getting it onto Twitter, though, which is the key technique used by such popular bots as @mothgenerator (algorithmic botany), @pixelsorter (glitch), @veilbymist (abstraction) and @tiny_star_field (a sort of minimalism).

Twitter bots using these techniques have become more or less clich├ęd; we suspect they offer far more possibilities than have been explored so far.

Our “Write a Twitter Bot” workshop runs on 17 November and will cover the basic code and libraries needed to do what Markov Bot does, aside from the image generation (which graduates of our Processing course already know how to do).