With this post you can learn to make a Twitter bot that will automatically retweet users talking about keywords that you specify. You can achieve this with (just about) no coding whatsoever.

Why would you want to do this? Lots of reasons I guess, ranging from spammy to fairly genuine. Normally giving somebody a ReTweet is enough to make them follow you and it keeps your profile active, so you can semi-automate accounts and use it as an aide for making connections. That or you can spam the sh*t out of Twitter, whatever takes your fancy really.

Here we go.

Step 1: Make your Twitter Bot account
Head over to Twitter.com and create a new account for your bot. Shouldn’t really need much help at this stage.. Try to pick a nice name and cute avatar. Or something.

Step 2: Find conversations you want to Retweet
Okay, we’ve got our Twitter account and we’re going to need to scan twitter for conversations to possibly retweet. To do this, we’re going to use Twitter Search. In this example, we’re going to search for “SEO Tips”, but to stop our bot Retweeting itself you want to add a negative keyword of your botname. So search for SEO Tips -botname, likely this:

So my bot is called “DigeratiTestBot”. Hit search now, muffin.

Step 3: Getting the feed
The next thing you need to do is get the feed results, which isn’t quite as simple as you’d think you see. Twitter being a bit of a prude doesn’t like bots and services like Feedburner or Pipes interacting with it, so you’re going to need to repurpose the feed or it’s game over for you.

After you’ve done your search you need to get the feed location (top right) so copy the URL of the “Feed for this query”

Store that in a safe place, we’ll need it in a second.

Step 4: Making the feed accessible
Okay, so there’s a teeny-tiny bit of code, but this is all, I promise! You’re going to need to republish the feed so it can be accessed later on, but don’t worry – it’s a piece of cake. All we’re going to do is screen scrape the whole feed results page onto our own server.

which needs to be replaced with whatever your Twitter RSS feed that we carefully saved and stored in a safe place earlier. If you’ve already lost that URL, please proceed back to Step 3 and consider yourself a fail.

So, having completed this and uploaded your myfeed.php to your domain, you can now access the real-time Twitter results feed by accessing http://www.yourdomain.com/myfeed.php.

Step 5: Yahoo Pipes!
Now comes the fun bit, we’re going to set up most of the mechanism for our bot in Yahoo Pipes. You’ll need a Yahoo account, so if you don’t have one, get one and login and click “Create a Pipe” at the top of the screen.

This will give you a blank canvas, so let’s MacGyver us up a god damn Twitter Bot!

Add “Fetch Feed” block from “Sources”
Then in the “URL” field, enter the URL of the feed we repurposed, http://www.yourdomain.com/myfeed.php.

Add “Filter” block from “Operators”
Leave the settings as “Block” and “all” then add the following rules:item.title CONTAINS RT.*RT
item.title CONTAINS @
item.twitter:lang DOES NOT CONTAIN EN

(You click the little green + to add more rules). Once you’ve done that drag a line between the bottom of the “Feed Fetch” box and the top of the “Filter” box to connect them. Hey presto.

Add “Loop” block from “Operators”

Add a “String Builder” from “String” and drag in ONTO the “Loop” block you just added

In the String Builder block you just put inside the Loop block, add these 3 items:item.author.uri
item.y:published.year
item.content.content

Check the radio box of “assign results to” and change this to item.title

Great, now drag a connection between your Filter and Loop blocks. Should look like this now:

Add “Regex” block from “Operators”
Add these two rules:item.title REPLACE http://twitter.com/ WITH RT @
item.title REPLACE 2009 WITH (space character)
Extra points for anyone who writes “(space character)” instead of using a space. Also don’t miss the trailing slash from twitter.com/

Drag a connection between Loop Block and Regex Block, then a connection between Regex and Pipe Output blocks.

Finished! Should look something like this:

All you need to do now is Save your pipe (name it whatever you like) and Run Pipe (at the top of the screen).

Once you run your pipe, you’ll get an output screen something like this:

What you need to do here is save the URL of your pipe’s RSS feed and keep it in a safe place. If you didn’t lose your RSS feed from Step 3, then I’d suggest keeping it in the same place as that.

Step 6: TwitterFeed
Almost there, comrades. All we need to do now is whack our feed into our TwitterBot account, which is made really easy with TwitterFeed.com. Get yourself over there and sign up for an account.

To set up your bot in TwitterFeed:

1) I suggest not using oauth, as it will make it easer to use multiple Twitter accounts. Click the “Having Oauth Problems?” link and enter the username and password for your TwitterBot account and hit test account details.

2) Name your feed whatever you like and then enter the URL of your Yahoo Pipes RSS that we carefully saved earlier, then hit “test feed”.

Post Frequency: Every 30minsUpdates at a time: 5Post Content: Title OnlyPost Link: No (uncheck)

Then hit “Create Feed”

All done!

Have fun and please, don’t buy anything from those losers who are peddling $20 “automate this” Twitter scripts. If you really need to do it, just make it yourself or if you don’t know how leave a comment here and I’ll show you how.

Hey, Thanks for this tutorial I have been playing with these for a few days and struggling, still got an error though. For some reason my feed is pulling a strong in something like “Yahoo::RSS::Type::DateTime=HASH(0x3414484)”
Any ideas what step I messed up on?

I just followed all the steps again with a whole new pipe and it seems fine however the actual pipes look no different from each other, I think I did something at the wrong order at some point maybe? Thanks for a great tutorial anyway.

@Mark: yeah, I hear you about the ideas. I’m giving it a shot now w/ something that I think will bring in enough for an extra 30-pack this month.

BTW, it looks like I’m not getting the “RT @Username” before my retweets…I’m getting the full Twitter URL instead. I’m “guessing” that maybe the Regex portion of my Pipe is borked, but I copied it exactly from your code (and I didn’t write “space character btw”). Any thoughts on what might be wrong?

Ahhh. I found it. You’ve got “www” before Twitter in the body of your post. But it doesn’t look like its in your actual Pipe screenshot. Removed the “www” and now I’m rockin.

Comment by G
September 25th, 2009 @ 7:02 pm

N says:

I got the same problem as G mentioned above. No RT appears and I tried it with “www” and without in my regex block. The only thing I did a bit the other way was creating my basic feed with rssmix based on different search queries on twitter. Might that be a problem Mark?

Good tip about including the -keyword in the tweets to keep from retweeting yourself. It becomes rather retarded when you have 1,000 bots all cannibalizing one another, especially when their content is wholly snatched from other people’s tweets to begin with.

@G, if you can get traffic with this, then you can probably make money with it. It’s just a matter of sending people to the right offer. Enough said.

This blog is so cool that I have become a regular visitos. Twitter can be put to useful things as well. As it happens, Twitter’s application programming interface (API) is particularly convoluted – it seems to have evolved by using many different ways of doing various things. That needn’t worry us, though, because there are plenty of API wrappers for Python.

Normally I browse the blogs waiting for something to capture my attention. Stopping by here, it was another step up in the learning curve. Great info guys, and thanks for sharing with us all this! (…still setting it up…)

Thank you. I started again and followed each step. Just waiting to see if my bot works now. Any tweets with the keywords: maggie thatcher
@thatcherbot (Does it update every 30 minutes?) as nothing has happended yet. I’ve learnt a lot from this tutorial. thanks.

Hey there, Mark! You have written a spectacular post, and it’s really helped me. But I have a problem.

Yahoo! Pipes is not letting me drag and drop the String Builder into the Loop box. I’ve tried both IE8 and Firefox (which is considerably smoother). The inner square in the loop box is greyed out and will not ‘click’ with the String Builder to put it inside. I’ve done everything else to the letter, even reading all the comments before attempting this amazing feat. Can you help?

Twitter bots are, much like irc bots, software that interacts with users by monitoring activity and reacting to certain “commands”. An example of a Twitter bot is TweetCC, an automated user that enables Twitter users to CC license their tweets.

Does anyone know how to integrate google translator into this? I’d really like to make a twitter bot that retweets and translates tweets automatically for English-speaking fans of a twitter feed which is all in Russian…

Comment by Luka
August 17th, 2010 @ 2:24 pm

Surfboy says:

Thanks!!! Really works~ but i did an error on one spot and now i need to start the whole thing again xD Thanks^^

This is a great tutorial.
I know how to follow a tutorial if it’s step by step. This one though is not quite what I want. Maybe there is a way to modify it to meet my desires but I wouldn’t know where to start. I would google it but don’t know what to search for
I’m trying to create a parody bot of friend that takes his tweets and adds a certain hash tag at the end like #InBed. Basically says the exact same thing as my friend but adds #LOL or #FUCKLULZ.
If you can offer any help leave me an @ reply. Thans

Many Thanks for such a lucid tutorial. I did absolutely as you said, and it will help our community to get in contact.

But I got an error after the username for whose twit my program is retwitting for ie “RT @EkendraBlogging is ….” see after my username @Ekendra and Blogging…. there is no extra space which is causing no link to the twitter user name.

What should I do to create a space between @Username and the First word of his tweet?

This article and concept is awesome but I’ve followed it to the letter twice with the same result. If I navigate to http://www.gambling-affiliate.biz/myfeed.php I get the feed pulled through, however once I run through pipes I get “no pipe results” as if theres nothing to draw…its driving me mad, anyone have any ideas? I’ve tried bypassing the filters and loops, removed all and re-added, then completely started from scratch and still can’t get it to pull the feed results…anyone??

@Mark thanks for replying. Tried both. no results given via pipes but comes through with freemyfeed.com. So tried again with the freemyfeed link and nothing…I’ve even tried to just pull the results using some other peoples feeds on this comment chain…and nothing…maybe its coz I’m just a tard with pipes, I’ll do some searching but I just cant work it out, suckaroo!

Fun, fun – I’d like to use this technique to mimic the fun random reply bots like @TheBotLebowski. I”m looking at the YQL module and thinking – if I could only access a table that I populate with my random phrases then I’d have something. Having trouble getting a grasp of what to do. Anyone using this?

Looks like my URL stopped working and I cannot get it to work again.
The URL by it self works fine, but will not produce results in the php script. I can’t figure it out. The code is exactly like you have in your example and I have replaced the ULR with the atom twitter URL. http://search.twitter.com/search.atom?q=%23LOA+-social_msi+-http
Any insight would be good…

Everything worked fine first time around but it’s not been updating. In fact when I refresh the pipe rss feed it doesn’t show any new entries (even though twitter search for the same criteria shows plenty) – it’s as if the pipe feed is fixed at the time I first ran it.