How to create a Twitter bot

By Steve Poland   •   April 10, 2007

  1. Determine what your bot will do. Capabilities include the ability to push information publicly to everyone (i.e. a sports team bot might push the current score of a game after each new point scored; or a world news bot might push headlines with a link to world news items). Another ability is for a user to direct message your bot — essentially sending it a command (i.e. a user could send their zipcode to a weather bot and the bot could send a private direct message back to only that user with the weather for that zipcode; or a stock quote bot could receive a stock symbol from a user and send them back a direct message with the price of that specific stock).
  2. Register a Twitter username.
  3. Create the functionality for your bot on a web server. Push (public broadcast of info to anyone that is your bot’s friend) and/or Pull (user provides command, you send them a result) functionality.
  4. Use Twitter’s API to understand: retrieving direct messages and sending messages.
  5. Users can only send your bot a direct message if your bot adds that user as a friend. Thus, your bot needs to call the ‘befriend_all’ link, which will befriend anyone that has added your bot as their friend. Hit this link every 30(?) seconds: http://twitter.com/followers/befriend_all.
    • An alternative option is to go into the settings of your Twitter username, choose to be alerted by email when someone adds you as a friend, and then monitor those incoming emails and add each user individually that way (automated).
    • Adding a username as your bot’s friend is easy, simply use the update function of the Status Methods.
  6. For push bots (broadcasting a single message to all users that are your friend or following you or viewing your webpage publicly), simply use the update function of the Status Methods.
  7. For pull bots (a user is your friend, you are their friend, they send you a direct message with some sort of command in it, you process that command on your server, you send them a direct message back with a result/answer to their query), use the direct_messages function of the Direct Message Methods to get the direct messages (”commands”) that users have sent to your bot. Then use the new function of the Direct Message Methods to send that user a direct message (”result/answer”) back to their query (note: direct messages are private, so only that user will see this result).
  8. Let others know about your bot! Post it at http://www.twitterbots.com




Related posts:

  1. “Pull” Twitter Apps Not Practical Until… “Pull” Twitter apps aren’t very practical until a setting is added to each user account. Right now, if someone adds me as a friend — I still can’t receive any direct messages they send me,...
  2. Twitter - What Will Dominate: Content Push or Content Pull? I don’t know what will blow up and be used more on Twitter — content push plays, or pull plays. Push would be having ‘NFL’ as a friend and getting all the latest NFL news...
  3. I’m the first Twitter spammer, ugh There’s a lot of things I am, but this wasn’t one of them that I expected to become — particularly given my love for the Twitter service. But things are fine with the Twitter team...
  4. First Twitter Bots Launched: Sports Teams, Weather, Stock Quotes These might be the first push/pull Twitter applications. For weather forecasts, add Forecast as a Twitter friend. Simply send it a direct message with your zip code, or city name, or city / state —...
  5. Twitter Syntax for Twitter Bots Fred Wilson just featured a twitter bot for stock quotes. I was also just chatting with Andrew Parker (Fred’s associate) at USV about Twitter syntax. I think we came up with a pretty good idea...

Related posts brought to you by Yet Another Related Posts Plugin.

Comments

12 Responses to “How to create a Twitter bot”

  1. MyAvatars 0.2 Grant Bowskill on April 10th, 2007 7:59 pm (perm link)

    For automatically adding people as friends, the bot I’ve made checks the friends requests page (http://twitter.com/friend_requests/) and extracts all user ids and then visits the accept url (http://twitter.com/friend_requests/accept/USER_ID/). I couldn’t get the befriend all page to work.

    If anybody wants to try it out, add findprice as a friend on twitter, then from your cell phone text: “d findprice playstation 3″ and you will get back the price of a playstation 3 on Amazon UK. It can take up too 2 minutes to get this reply.

  2. MyAvatars 0.2 Wambui on July 24th, 2008 2:26 am (perm link)

    Did anyone create an actual working Twitter bot for sending out follow requests? If so, email me. I’m interested

  3. MyAvatars 0.2 Den on December 2nd, 2008 5:24 pm (perm link)

    Twitter 411 - your own information system on the top of Twitter. Yes, it is a bot (with user defined responses). See http://t411.linkstore.ru

  4. MyAvatars 0.2 SEO Marketing on December 4th, 2008 7:03 am (perm link)

    still confusing, I just modifying some feed from mybloglog, and make new twitter account that acts like a bot. it automatically twits my recent update….

    btw what is the benefit for this messanging bot?

  5. MyAvatars 0.2 Den on December 12th, 2008 6:13 pm (perm link)

    >btw what is the benefit for this messanging bot?
    twitting updates is like broadcasting. And message bots works by requests

  6. MyAvatars 0.2 Is This The World’s First Useful Twitterbot? on January 19th, 2009 11:49 am (perm link)

    [...] more over at the all-new Who Is Hosting This blog, or more on how to create your own over at Steve Poland’s blog. Bookmark [...]

  7. MyAvatars 0.2 Larry M on January 20th, 2009 10:42 am (perm link)

    Here is a a new bot.

    http://twitter.com/myflightinfo

    I find it useful.

  8. MyAvatars 0.2 Linky Pimp Friday 13/02/09 on February 13th, 2009 5:53 am (perm link)

    [...] An oldie but a goodie on creating a Twitter bot. [...]

  9. MyAvatars 0.2 Mobile Messaging 2.0 » Tweetfoxxy: ‘Hooking up’ using Twitter: a hosted discussion on mobile messaging, devices, and user practices and trends on February 25th, 2009 11:37 pm (perm link)

    [...] closed out the evening with the BBC’s Ian Forrester pitching Tweetfoxxy, a playful ‘Twitter-bot‘ that helps match people for dates and, um, sexual liasons…almost a ‘booty [...]

  10. MyAvatars 0.2 Nuno Rodrigues on March 4th, 2009 7:58 am (perm link)

    If you want to check a bot which provides the results of the main football (Soccer) competitions just check http://www.twitter.com/twitscores

  11. MyAvatars 0.2 Jonas Lejon on March 30th, 2009 10:00 am (perm link)

    Thanks! I’ve just made a Twitter bot. More info http://download11.com/twitter

  12. MyAvatars 0.2 Twitter Bot on June 7th, 2009 9:32 pm (perm link)

    Excellent, I’m loving the Twitter bots for pushing sports scores. Thanks!

Got something to say?





*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word