UPDATE: Please note that the functionality described in this blog post relises on Twitter API version 1.0 which has now been deprecated by Twitter. This means that the functionality described may no longer work for you.
If you are building a business and are perhaps too busy to be manning TweetDeck 24×7, then augmenting your real social media activities with the help of a bot may be just what you need. Or perhaps you want to build a new twitter account that curates and auto-tweets specialist content. Either way, here’s how you can build your very own Twitter-bot.
I have tried a number of systems and techniques, but have found the following approach to be the most effective. On the surface, it appears to be overly complex – mainly because it uses three different sites to achieve its aim. But its not as complicated as it may appear.
Here’s the sites we use and why:
Feedburner - http://feedburner.google.com. If we use Yahoo Pipes directly with a Twitter search, it will access the Twitter servers too frequently which will result in errors and timeouts. Feedburner only updates a feed either every 30 minutes or when notified with a ping. This means that we can be kinder to Twitter’s servers and will have more consistent data.
Yahoo Pipes - http://pipes.yahoo.com. We use Yahoo Pipes to clean up the results we get back from Twitter. We eliminate spammy tweets, remove replies and retweets, and reformat the results so that we can retweet more easily.
Twitterfeed - http://twitterfeed.com. We use Twitterfeed to actually post/tweet the “cleansed” Yahoo Pipes feed. You will note that you can tweet results directly from Feedburner but I don’t like this as a solution for two reasons. First because we can’t clean up the feed like we can in Pipes and second because you have to link a Twitter account to your Google account, which we may not want to do.
1. Finding the Source.
For the purpose of this example, let’s say that we wanted auto retweet any tweet that mentions the London Zoo. So, we are going to search Twitter using their search.twitter.com interface with the following query:
“london zoo” OR #londonzoo -source:twitterfeed -filter:retweets lang:en
This query is saying – give me the most recent tweets that mention “london zoo” or the hashtag “#londonzoo” but ignore any tweets published using twitterfeed (remove the other bots like we are creating) and ignore any retweets (we only want the original tweets) and only give me those in english.
At the top right of the twitter search site, there is a link that says “Feed for this query” – if you click on that, you will get the following link which is your search results as an RSS feed.
2. Creating the Twitter Account.
If you already have a Twitter account, then skip ahead – otherwise you will need to create a dedicated Twitter account for your new bot. For this post, I created a new account called LondonZoobot (@LondonZoobot).
3. Setting up Feedburner.
Setting up the Feedburner feed is very simple.
1. Go to http://feedburner.google.com and create an account / login.
2. Copy and paste the URL for the Twitter search from the step earlier into the box where it says “Burn a feed right this instant” and press “Next”
3. Change the Feed Title to something more friendly – we’ll name ours “London Zoo Tweets” and press “Next” the press Skip for the next steps. Your feed should have a url something like http://feeds.feedburner.com/LondonZoobot
That’s it for Feedburner..
4. Setting up Yahoo! Pipes.
Yahoo! Pipes does the bulk of our work and so this is the most complicated part. We’re going to basically run our new Feedburner feed through a series of filters to re-shape it. We’re going to eliminate potential spam tweets, remove any replies, and then add “RT @”+username to the front of the tweet so that we can easily retweet the information in the next step. It looks scary, but as with all things – its easy when you know how.
1. Create a new pipe by clicking on “Create a pipe” on the menu.
2. Drag the “Fetch Feed” box from the left side panel onto the Pipes grid and enter the URL for your new Feedburner feed (e.g. http://feeds.feedburner.com/LondonZoobot). This box is going to load your source RSS feed so that we can “clean” it.
3. Expand the Operators menu on the left and drag the “Filter” box to the Pipes grid. This box is going allow us to remove any tweets that we wouldn’t want to retweet – for example – anyone mentioning a RT (should be eliminated in our Twitter search – but just in case) and any other words such as bad language or spam signals. Add a few lines in the filter box, so that it looks like this (be sure to select items that match “Any” instead of “All”):
You can add more of these as time goes by to make sure that you are retweeting better quality tweets by filtering out the garbage.
4. Drag another “Filter” box from the left hand side to the Pipes grid. We are going to add another filter that blocks any replies so that we are only ever retweeting original messages (this is “belts and braces” really). It should look like this (note the “Matches regex” operator):
5. Now we’re going to tell Pipes to loop through each item in the RSS feed and add the Twitter account (Author) to the front of each tweet. This is so that we can mention them in the RT a bit later. So – drag a “Loop” operator from the left hand side to the Pipes Grid. Then expand the “Strings” section from the left menu and drag a “String Builder” object to the center of the “Loop” box. We want three lines – so press the “+” icon a couple of times – then.. select “item.author.uri” in the first line, then a space (” “) in the second line, then “item.title” in the third line. We are replacing the title field in the RSS feed with Author URI + ” ” + item.title. It should look like this:
6. Almost there – this last step is simply going to add the “RT @” to all of the newly created titles. The actual “item.author.uri” is a url – something like “http://twitter.com/authorname and so we are going to replace all “http://twitter.com/” we find with “RT @”. To this, expand operators on the left side and drag a “RegEx” box to the Pipes grid. Set it to look like this:
7. Now join up all the pipes by dragging from the circle at the bottom of the first box to the circle at the top of the next box and so on. It should now look like this:
8. Save your Pipe (press Save at the top) – and name it something useful – “LondonZoobot”
9. Final step – run the pipe (select “Run Pipe”) and then get the link for the RSS feed for this process by selecting “Get as RSS”. Should be something like - http://pipes.yahoo.com/pipes/pipe.run?_id=6139c8dd57b3d08c1b6d9d0ad2375b69&_render=rss
5. Setting up Twitterfeed.
We use Twitterfeed to get the set of “clean” tweets from Yahoo! Pipes and then post 1-5 of them, every 30 minutes automatically.
If you don’t have a Twitterfeed account, create one.. they’re free, then login.
1. Select “Create New Feed”
2. Give your feed a name.. “LondonZoobot” and then copy and paste the RSS url from Yahoo! Pipes (e.g. http://pipes.yahoo.com/pipes/pipe.run?_id=6139c8dd57b3d08c1b6d9d0ad2375b69&_render=rss)
3. Select “Advanced Settings” so that we can tweak the feed just a bit more
4. Change the update frequency and number of tweets – I would suggest you leave the defaults as 30 minutes and 1 tweet at a time (otherwise it becomes too spammy).
5. Change PostContent to “Title only”
6. Click on “Continue to Step 2″
7. Now we are going to tell Twitterfeed which Twitter account you want to tweet to. So – before you go any further, make sure that you are logged into the Twitter account that you want to use (on another browser tab)
8. Select Twitter.
9. Select “Authenticate Twitter” – and then “Authorize App” when you go to the Twitter site.
10. Click on “Create Service”
11. Click on “All Done”
That’s it! Check out the auto tweets we just created here: http://twitter.com/#!/LondonZoobot
You now know how to auto tweet by creating your very own twitter bot. There’s a lot of steps in this I realize, but give it a shot – its not that difficult when you get stuck in.