The bots are coming! Twitter bots!

When I accepted a spot in the Flatiron School Ruby005 class, I knew my social life and, uh, casual internet-browsing life (?) would be cut dramatically down while I would be focusing all of my efforts on learning Ruby. I didn’t want my friends to miss me too much (which is hard, since I also had to move from South Carolina to New York), so I decided to build a twitter bot that could tweet and talk to my friends.

Fortunately, there’s already a Ruby gem that does all of the work for me. So I didn’t really have to build a bot, I could just launch one! I used the gem found here and pulled in the example bot’s code. When I got stuck, I referenced this bot tutorial. Setting up the bot and modifying the code was easy, but I hit a few snags trying to cooperate with the Twitter app API and OAuth.

Here’s how the twitter_ebooks gem works.

  1. The gem pulls in your twitter history in json format.
  2. Then, it parses through the json data and identifies words and phrases according to grammatical structure.
  3. It randomly generates sentences based on a user’s tweet history. A cron job is set up to tweet randomly once a day, but I bumped that up to once an hour.
  4. It knows how to respond to other users when they tweet at the bot.
  5. It has a keyword list and will favorite or retweet tweets in its timeline that use those keywords.

Here are a few examples of what my bot has to say:

But the best part of having a Twitter bot is that it can interact with other users! Classmate Randall asked her for some advice:

That’s my bot! Have your bot add my bot at @ablwr_ebooks. Stay tuned for some more technical blog posts about working through the Twitter authentication steps, understanding CRON, modifying a bot, deploying to heroku, and ~mad science experiments~.