How to auto tweet and create your own Twitter bot

How to auto tweet and create your own Twitter bot

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.

Overview.

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.

http://search.twitter.com/search.atom?q=+%22london+zoo%22+OR+%23londonzoo+-source%3Atwitterfeed+-filter%3Aretweets

 

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.

  • http://twitter.com/marnelle Marnelle Apat

    Hey Matt,

    thanks for sharing this brilliant idea. I just wanna ask for some clarifications. This means that by doing the auto-tweet, i need two twitter accounts? Am i right? One for the bots and one is your main twitter account.

    Thanks,
    Marnel

  • Anonymous

    Not necessarily.  You can use this autotweet approach in your main account – to keep a consistent level of activity and then augment this with real user engagement (highly recommended)

  • Pingback: How to Generate a Twitter Bot

  • Diego

    Hello Matt,

    i wish to develop an AIML chatterbot as dialogue system to be embedded on twitter for my final year project for college. The user enquires on fligts and hotel rates by means of dialogue and the system should return with that information gathered from the internet by means of dialogue, tweets and messages suing the twitter account system. I definitely need to create a twitterbot, right?

  • Anonymous

    Not sure if a twitterbot is what you would need.  Seems like this would require a program that monitors a twitter account and responds to requests.  It then searches other sites/APIs (flights, hotels) and responds.  You just need to have your software access Twitter via their API.  Good luck – sounds like a cool project.

  • http://shareitto.com Shailesh Tripathi

    Your article on Twitter  yahoo pipe is very interesting and appealing to readers. Thanks and wish to post you more article about it.

  • http://www.hondonvillas.net Hondon Villa Rentals

    WOW! – I never knew about Yahoo Pipes ! – What an awesome tool – up there with the best of them. I can think of so many uses for this already.

  • http://twitter.com/TheZombieBot Zombie

    Thank you for a great article, i want to add a constraint “stop @myusername” and the pipe never tweets that user again, is that possible? is it also possible to set it to never tweet any user twice?

    Second question, what if i don’t want it to RT the user but tweet the user a specific message e.g. @username predefined message – what pipe do i use for this?

  • http://twitter.com/Dick_Foster Dick Foster

    I can’t find the “Feed for this Query” link on Twitter query page. Has it been removed or just moved to a new location.

    Great information. Thanks!

  • Anonymous

    Interesting. They may have.  Here’s how you can still get it though.

    1. Look at the URL for the Twitter search.  
    2. Copy everything *after* the /search/ part of the URL – this is your actual search query.
    3. Append what you have copied to the following URL:

    http://search.twitter.com/search.atom?q=

    4. Save the newly formed / combined URL as your search.  Should look something like:
    http://search.twitter.com/search.atom?q=+%22london+zoo%22

    Hope this helps – and thanks for pointing this out for me.

  • WTreF

    This is great Matt!

    I have a question.  What if I want to add my own hash to each of these retweets before I RT it?

    For example – I own @WTreF and I repost folks who complain about refs.  So when I RT I would like to introduce my #WTreF to get folks familiar with it@WTre:disqus 

    If I RT someone saying WTF Refs or something similiar, I want to end it with #WTreF 

  • WTreF

    I figured out how to do this.  On Twitter feed their is an option to add a “Post” at the end of the tweet.  I put in #WTreF and it works great.  Now I have another issue.

    My tweets have the persons names and are TOO lengthy and cutting on the content.  For example here is a post it just retweeted on my @WTreF account @ 9:41am this morning (central time)
    @890a2dbb7e81fc0730fbafa328d13ad0:disqus 
    ArronMacDonal (Arron MacDonald)RT @ArronMacDonaldIs still seething over last night’s game. Point wrongfully kicked out in 2Q,… #WTreF

    I would like it to look like this:

    RT @ArronMacDonaldIs still seething over last night’s game. Point wrongfully kicked out in 2Q,… #WTreF

    But where the “…” is finish up as much as possible, or if it’s too long, not even repost those…is that an option?  basically, removing the full name twice and blocking posts that can’t be repost without losing the message.

  • WTreF

    I would like to add a space in between the name and the first word as well.  The example above shows
    @ArronMacDonaldIs and it should be “@ArronMacDonald Is” – there is a space but my retweets are not posting them.

  • Anonymous

    Hi WTreF – sorry for the reply in responding.. been a busy period at work recently.  I am glad you have found how to add the hash tags in TwitterFeed.  

    To do the trimming that you would like to – I would recommend that you do this in Yahoo Pipes.  There is an option under “String” called Sub String, and you can select from a starting point.. up to a maximum number of characters.

    If you want to make sure that you always have enough room for #WTreF (6 chars) then you should set this as starting from 0 and up to 133 chars.

    Hope this helps
    Matt

  • WTreF

    Matt,

    I got all you suggested to work.  I have one more idea I am not sure if it is possible.

    I want to be able to Retweet anyone that uses my name with a Hashtag.  (i.e. #WTreF)  The key is, I don’t want it to RT as myself, and include there name and put it as a RT in front of it (like you disucssed in the instructions).

    I want it to RT as I would if I were using my iphone app and hit “Retweet”.  NOT “Quote Tweet”.  It would appear in my feed as the original user posted it on my feed; however at the bottom it says “by WTreF”.

    Is this possible and how do you suggest it?  TIA

  • Anonymous

    I’m not sure how to post these as “new” retweet formats.  Sorry.  

    If I find out, I’ll let you know.

  • Dennis

    I’ve got an error when running the pipe, is that a problem or not?
    No pipe results for AndaikanBot.
    This Pipe ran successfully but encountered some problems:warning Error fetching site feed from http://feeds.feedburner.com/andaikan-sourcetwitterfeed-filterretweets-backalley-backalleyrock-TwitterSearch: Invalid XML document: org.xml.sax.SAXParseException: The entity name must immediately follow the ‘&’ in the entity reference.

  • Dennis

    And when i continue set-up the twitterfeed, it is appears like this :

    1 error prohibited this feed from being savedThere were problems with the following fields:Feedurl A feed needs to contain publish dates or GUIDs in order to work with twitterfeed, see http://twitterfeed.com/help#faq3_13

  • http://twitter.com/nazihtw Globe_city Citizen

    On twitter research I can’t find how to export a search to rss feed

  • http://twitter.com/RobGordonBot Rob Gordon

    Hi Matt, thanks for this great tutorial.
    I was trying to create something a bit different: a twitter account that replies with a random tweet (from a list of N pre-written tweets) to anyone who mentions a specific word or hashtag. As the Zoolander bot.

    Dou you know a way to achieve this? Is there any tool or tutorial you could recommend?

    Thanks in advance!

  • Kevin Blaak

    Is there any way to set it up like this, but for the bot the send an automatic reply to people mentioning the searched words ?
    So the bot would reply to people mentioning #LondonZoo in your case

  • 1MattHopkins

    Of course – just remove the RT in step 6.. just add the “@”

  • http://twitter.com/themoceanvibe liquidmocean

    Hey Matt,
    Great info BUT I got all the way to Twitterfeed and it came up with an error stating:

    “Feedurl A feed needs to contain publish dates or GUIDs in order to work
    with twitterfeed, see http://twitterfeed.com/help#faq3_13

    All steps were carried out to the T following your outline, I got the RSS URL but Twitterfeed won’t accept it?

    Any ideas?
    Cheers,
    mark.

  • http://twitter.com/themoceanvibe liquidmocean

    “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”

    I’ve been staring at the screen for an hour or so and nowhere can I see a “Feed for this Query” link! Can you upload a screen grab?

  • 1MattHopkins

    Are you hooking up the Yahoo Pipe to Twitterfeed?  I think I used to get that message if I connected the twitter search or feedburner (one of the two)

  • 1MattHopkins

    Looks like they changed the ui.  You can still get this by changing the URL.  The standard url you are probably seeing is like:

    https://twitter.com/search/mysearch

    If you change the url to be like this:

    https://search.twitter.com/search.atom?q=mysearch 

    So 
    1. Add search.  in front of twitter.com
    2. replace “/search/” with “/search.atom?q=”

    Hope that helps

  • Chernenko Margera

    it works but i got some problem, the bots responding

    Tuhan Memberkati RT @fragmangelTuhan fragma mohon jagai mama dan bapa hingga tiba di surabaya,amien http://bit.ly/PJ8YiX

    we can see that @fragmangelTuhan actually, its @fragmangel account said  Tuhan fragma mohon jagai mama dan bapa hingga tiba di surabaya,amien http://bit.ly/PJ8YiX

    how do i resolve this ?

  • 1MattHopkins

    You need to add a blank line with a ” ” (space) in it – like in step 5 above.

  • coolppl

    Thanks so much for the time you took to make this awesome tutorial! Worked for me!

    I’m so excited and now I have a further question that maybe you can help with. In yahoo pipes (or somewhere) I want to be able to filter out any phrase that separates my “london zoo” twitter search query with periods or other punctuation. 

    In other words, remove tweets that say I “I love london! Zoo is the name of the coolest club there”

    Any ideas?

  • 1MattHopkins

    Absolutely – you just need to use a RegEx pipe.. and then use a regular express to either ignore punctuation – or in your example above, take the search string exactly as is -> here’s a reference: 
    http://www.grymoire.com/Unix/Regular.html  

  • Ganna Boiko

    Hi Matt, 
    It seems you spent a lot of time to write this post))) Great job! 
    If you are still interested in automatic retweeting – I’d like to tell you about up-to-date free service I use – RoundTeam. It retweets everything with defined #hashtags, @mentions or just key words. You can also choose from whom to retweet – from followers, form whom you are following or from all twitter.
    It took me about 2 mins to set up retweet parameters. 
    Hope it will work for you.

    Ganna

  • Tim

    Matt,

    Here is an example of a tweet that was auto retweeted thanks to your methods.

    DatingSitesRevU (Dating Pro..)RT @DatingSitesRevU The Right Way To Learn Game Podcast Review http://t.co/6rJbNgj…bit.ly/P1NpmZ However, I would like to omit the name at the beginning “DatingSitesRevU (Dating Pro..) and just start with “RT @DatingSitesRevU:disqus Someone posted a similar question, but I am having difficulties figuring this out. How can I fix this?

  • Dools

    I know this was made a long time ago, but how would i make it so, the bot does not retweet but simply replies to a word in a search query? Like the infamous Stealth Mountain. It would be insane if you answerd this :)

  • 1MattHopkins

    Sure it works fine even today – take a look at @LondonZooBot on Twitter – it was set up using these instructions exactly. Make sure you follow step 5 (adding the space especially) and step 6 (adding the RT) above.

  • http://twitter.com/UCit_Promo UCit Promo

    had a question regarding auto tweets Im a club promoter in Atlanta and I want to send my event info to anyone tweeting the words “Atlanta tonight”

  • http://twitter.com/SEM_Experts_DMP Jeffrey Arnold

    Matt:

    Great post. I am working with a similar setup on my own, but even though I have “RT” at the beginning, the messages only show up as ‘mentions’ when I look at them in Hootsuite. Does this method actually get recognized in Hootsuite (and more importantly, Klout), as a RT, or is it just a ‘mention’ with RT at the beginning?

  • 1MattHopkins

    They are just mentions – the same using a “via” or preceding the tweet with any character (“.” works too). The benefit really over true RT’s is that mentions go to all your followers..

    Thanks for reading and commenting.

  • http://twitter.com/jetonr Jeton R.

    Hi there,
    Just a few changes to the pipe thing, bcz twitter has changed their rss. Need to add regex before loop with this rule : in item.author replace @twitter.com.(.* with leave empty and then in loop string builder 1st row: RT @ 2nd row: item.author 3rd row: 1 space 4th row item.description. Check the image I upload!

  • francisco

    Matt great work! I was wondering if there is a way to autoretweet the exact twit received instantly (or in less than 5 min)

  • http://twitter.com/UitTip Uittip

    My string builder doesn’t add the RT @ ? Any idea why not?

  • Alejandro

    Hi! Im currently using this very same technique to find a keyword and replying the user who tweeted. However im not able to tweet the reply as a reply of the user tweet, its like a separate tweet with no link with the original.

    I would like it to be as if I hit the “reply” button on the original tweet, so when they click on the tweeted reply, it shows the original tweet.

    Any idea how through this method?

    thanks!

  • d7ibril

    Hi Matt,

    I tried to follow all your instructions but I couldn’t find ‘RT @’ on my retweet..looks like those are my original tweet..please help..thx

  • 1MattHopkins

    Did you get anything at all?

  • d7ibril

    Yes I did, I’ll try to start all over again to see if something missed and get back to you soon..thx for your reply..

  • d7ibril

    Hi Matt,

    I made a mistake with the feedburner..it’s working now..great tutorials..! btw is it possible to exclude a twitter username which is a similar twitter account that I don’t want to retweet? Please help..thx

  • Wayne P

    Unfortunately this method no longer works – Twitter doesn’t parse “RT @” to post on you’re behalf, it’s just you reposting the exact text. If I go onto Twitter and manually click “Retweet”, the message I post says “@username retweed:” above the message. The message has a picture of the user I retweeted and the content is what they posted. By using the method posted (and a number of variations of it that use the Twitter API as the source), it’s as if I just write a message mentioning them. I am guessing it has to do with Twitterfeed in between but maybe there’s a way with pipes to post to the Twitter API?

  • 1MattHopkins

    This method does still work – but you are correct that they are no longer considered “retweets”.. but they are now considered “mentions”. You could replace the “RT @” with anything before the “@” with the same effect – e.g. “.@” — but the approach is still valid today.

  • bigajm

    I’ve been using this system of Twitter search results via RSS >> a Yahoo Pipe >> dlvr.it >> Twitter to retweet certain keywords successfully for over a year. However, I’ve recently read that Twitter is ending support for search results via RSS in March 2013.

    Is there any other method of acquiring a stream of Twitter search results and feeding them into Yahoo Pipes?

  • http://thebrokerlist.com/ Customer Service

    Check that your twitter url in Regex ends with a /.

  • http://thebrokerlist.com/ Customer Service

    Did you figure that out?

  • http://thebrokerlist.com/ Customer Service

    No matter what I do, the RT @username does not appear in the tweet. All else is working perfectly. I have stared at this for hours and do not see what the problem is. Anyone else have this issue?

  • 1MattHopkins

    Can you send me a screen shot of your Yahoo Pipe? Perhaps I can see if there is anything missing. Or – here’s a screen grab of the whole pipe I use for the “London Zoo” example above if that helps.

  • http://thebrokerlist.com/ Customer Service

    On the loop entry, what do you actually do to get the space. Do you actually type in a space using the space bar or do you type in ” “? Also on Regex, I have a space between RT and @ sign. On the filter does it end with “.”? thanks so much as this is driving me crazy and I am determined to figure out what I am doing incorrectly.

  • 1MattHopkins

    On the loop entry – you need that 2nd line and it has a space – a ” ” in it. There is also a space on the Regex section (between the RT and @) and the filter is “@.” (with the period at the end). Hope this helps.

  • http://thebrokerlist.com/ Customer Service

    I put a note on the string and it will not let me leave it blank or type in a space. What do you actually type in on the keyboard for that center string? thanks for the help.

  • http://thebrokerlist.com/ Customer Service

    Also, I am blocking some Twitter accounts that I do not wish to mention. That would not impact it, but in the field of Block – item.author.uri I just have the twitter account name only. So if the account were http://twitter.com/twitterapi, I only have twitterapi in that field for the account I wished to block. Is that correct?

  • http://thebrokerlist.com/ Customer Service

    Yes, it all helps, except the space issue. It will not let me save the pipe with a space in that field. I guess I am not entering the exact string for space correctly. All other items you pointed out are correct.

  • 1MattHopkins

    Mine doesn’t have “for each *item*” – try with a blank string builder

  • http://thebrokerlist.com/ Customer Service

    What I do notice is that you cannot edit the string once you do it. I had to delete the entire loop and add it back in and start over with string again. I have simply skipped that center box completely and left it blank so I am testing it now. Blank meaning, nothing was entered at all. When I refresh in the bottom of the preview screen should I see the RT @name in front of that preview too?

  • http://thebrokerlist.com/ Customer Service

    I wonder if they changed something and they are not permitting the space now. If you did this again, does it give you the space on a new pipe like this? Do not mess with your old pipe, because it is working, but if you did a new pipe?

  • http://thebrokerlist.com/ Customer Service

    It seems to take the RT from the string builder center box ,but is ignoring the Regex box completely. It seems it just ignores regex completely for me.

  • http://about.me/talbottsw Steven Talbott

    Did you ever figure this out? Having the name in “()” takes up too much room. How do you eliminate?

  • Eco Log

    I guess this post is quite old now. I see your zoo bot is still tweeting well. I’m trying to do this now, but it seems that yahoo pipes have chaged the way twitter authors are published.

    Everything works perfectly, but I don’t get “item.author.uri” as an option for author. All I get is “item.author”, which posts differently from what you describe. What am I doing wrong?

  • 1MattHopkins

    Are you using Feedburner for your RSS feed? Pipes just provides the fields that it has been given – check to make sure that you are pulling your Twitter search feed via Feedburner.

    This whole approach has a limited lifespan anyway considering the changes that Twitter will be making soon (deprecating their REST feed model). And won’t work for much longer – for any of us.

  • MJN

    When I search on twitter I cannot get the RSS get feed button (I think Twitter have changed things) can this still be done?

  • 1MattHopkins

    They have changed it and are dropping / have dropped the functionality for the whole approach mentioned in this blog post which means that you can no longer get twitter searches using RSS.

  • Naukhaiz

    Undoubtedly the most helpful blog on the internet. Kudos!

  • Tyrion, O Meio Homem

    I made this configuration today and my tweet was duplicated. I mean, was like: “RT @user User @user tweet….” – why? :(