A Noncoder’s Attempt to Make the Twitterbot of His Dreams

image

On Twitter, bots are hot. Marketers, artists, news organizations, and general-purpose wiseacres have found all kinds of uses for Twitter accounts that pump out or react to tweets under the guidance of pure code, rather than a carbon-based life form.

For example: @QuakesToday auto-tweets based on real-time machine reading of earthquake data. @congressedits is a bot that shares Wikipedia edits made from IP addresses associated with congressional offices as they happen. @big_ben_clock alerts followers to the new hour, in the form of tweeted “bongs.”

Other Twitterbots are not so much useful as purely amusing or entertaining — see, for instance, this list of silly but lovable Twitterbots.

Much like the guy who is certain he can create a hit song — if only he could read music and play an instrument — I like to believe that my ideas for silly Twitterbots are as good as anybody’s. If only I had the slightest understanding of code!

Then again, about 35 years ago I wrote a BASIC program that caused a ball-like digital object to bounce across the screen of my Commodore 64. Surely I could figure out how to make a Twitterbot, right?

That was my cocky starting point for what turned out to be a humbling journey. Yes, I did create a bot — two, in fact. And chances are that you can, too — although unless you really want to buckle down and learn JavaScript, it may not be quite the bot of your imagination.

Here’s what I learned by attempting to participate in the hotness of bots.

Up and running in five minutes (or, uh, not)
My (possibly stupid!) idea: a bot that would identify top Twitter trends and, several times a day, tweet references to them, appending useless observations such as “Speechless!” or “Don’t know what to say!”

This idea sprang from my experience of dabbling in the culture of live-tweeting around TV broadcasts of watercooler-worthy shows like Breaking Bad — I was amused to learn that people felt compelled to express the fact that they had no insight about the event. So why not extend that sentiment to whatever is trending?

To concoct samples from what’s trending as I write this: “ ’Nuff said! #1DAnnouncement,” or “Nothing to add #ESPINOSADAY.”

I would call my bot “Trending Raconteur.”

Yes, that is partly a smart-ass comment on the frequent banality of Twitter — but it’s arguably also useful, to the extent that it prods followers to take regular note of what’s hot on the social network.

Anyway, I started by reaching out to a few web-creativity wizards for whom whipping up a Twitterbot is about as challenging as preparing a PB&J. Writer and developer Mike Lacher — known for online projects like The World’s Most Exclusive Website, The Geocitiesizer, and other brilliantly absurd exploits documented at MikeLacher.com — generously responded with a quick overview of how I would need to proceed.

And he sent a link to a tutorial that promised: “Writing a Twitter bot is easy and you can get one up and running in 5 minutes.”

Sounds good!

But of course it turned out to be more complicated. In fact it took me many (cough) days, during which I read or watched a blizzard of tutorials — and did an even-more-than-normal amount of cursing at my computer, out loud.

To leap ahead a bit, here’s the essence of what I eventually figured out.

Good news: Tutorials like the one I’ve linked to above (and those below) are useful to total noncoders like me — if we want to build a bot that is highly similar to the tutorial example.

The tutorial above is actually based on the Dear Assistant question-answering bot — which is awesome but has nothing to do with my own goals. Thus the bad news: If you want to do something different, you’ll have to develop some understanding of code. And that takes a lot more than five minutes.

Time to reboot
Picking up the pieces of my shattered insta-bot dream, I did three things.

First: I started an online tutorial on JavaScript, offered for free by Codecademy. This soon helped me grasp at least some of the basics about what all those {’s and ;’s meant in the example code I’d seen.

But since my editor was already losing patience with this venture, I didn’t really have time to master this language. So, second, I went hunting for a tutorial involving a bot that was closer to what I had in mind. This one, created by Zach Whalen, associate professor of new media at the University of Mary Washington, fit the bill: It’s very simple and is basically designed to combine words and phrases in randomized patterns, tweeted at regular intervals.

It took more than five minutes, but I used his template to create a version of Trending Raconteur that worked — almost.

Twitter profile with tweet reading 'Don't know what to say'
Twitter profile with tweet reading 'Don't know what to say'

My bot was soon tweeting banalities, just as I’d envisioned. But I couldn’t figure out how to include the reference to a top trend.

That brings me to my third step: cheating. Basically, I cajoled Lacher into helping me. Luckily for me, my request was so easy for someone with chops to answer, it probably really did take just five minutes for him to get me off his back. And voilà! I had a working bot!

Trending Raconteur Twitter profile
Trending Raconteur Twitter profile

Obviously this process had not turned me into a world-class hacker — but it did demystify the way bots (and other applications and extensions and whatnot) are built. Lacher solved my problem by pointing out how to get top-trend information from Twitter’s API, in essence obtaining and plugging in a bit of prefab code.

Another useful source I encountered, a more advanced but lucid tutorial on Tiny Subversions, demonstrated how this logic extends to combining tools from Twitter’s API with those available from third parties. (For those interested in delving deeper, ReadWrite has a great overview of APIs.)

Rise of the bots
A Quartz article from earlier this year wondered, “How many of Twitter’s active users are actually human?” The story notes the soaring growth in Twitter accounts that tap into the service’s API. That doesn’t mean they’re all bots, but it suggests that as coding systems become more accessible, more people really are using them to make, or enhance, a dizzying variety of applications and bots.

Line graph showing increase in API use
Line graph showing increase in API use

(Quartz)

Epilogue
As I wrapped up this project and got back to my JavaScript lessons, a friend pointed out to me that my Trending Raconteur might run crosswise of Twitter’s developer terms of service — automated tweets that include popular hashtags arguably undermine the hashtags’ value.

But by now I wasn’t panicked by such a fate. I decided that, as a fallback, I’d make another bot: A parody of my own silly invention, called Fake Trend Raconteur, which would merely advise followers to look at the top trends or hashtags, and add a useless comment — “Nothing to add,” for instance.

Fake Trend Raconteur Twitter profile
Fake Trend Raconteur Twitter profile

This obviously is even more absurd than Trending Raconteur itself. But it’s not hurting anybody, it makes me laugh, and it works.

And it took me only seven minutes to build.

Tweets reading 'Wow top trends right now ... speechless' and 'That top trend ... nothing to add'
Tweets reading 'Wow top trends right now ... speechless' and 'That top trend ... nothing to add'

Write to me at rwalkeryn@yahoo.com or find me on Twitter, @notrobwalker. RSS lover? Paste this URL into your reader of choice: https://www.yahoo.com/tech/author/rob-walker/rss.