I decided to make a Twitter Bot hosted on
Heroku. And I managed to do it really easily. Surprisingly. The source
code for this is on
Github.
Here are the basic steps I took:
1. Think of
something funny / useful for your bot to do.
- This will have the ability to control your twitter account on your
behalf.
- Make a note of the API keys.
4. Enable Read /
Write Permissions for this App
- Found under ‘Permissions’.
- If you need an extra mobile number, try this
trick.
- Sferik’s twitter gem
makes this very easy in Ruby.
- If you’re looking for inspiration, browse my code.
It’s not very complicated… And the twitter gem is very well
documented.
- Remember to use Environmental
Variables to hide your API keys.
6. Create a
Gemfile / Rakefile for Heroku to latch onto.
- Again, examples of these can be found on my Github
profile.
- The rakefile basically defines an isolated process that can be run
by heroku.
- The Gemfile lists all the Gems you’ll need to install.
- You may need to run
bundle install
(as usual…)
7. Check
you can do what you want from the command line.
- By running your rake task.
9. Push your current files
to Heroku.
- This should be a .rb file, a Rakefile, a Gemfile & a
Gemfile.lock
heroku addons:add scheduler
- the fastest way to add
this.
- This will allow you to customise how often it runs.
- You can set it to run every 10 minutes if you feel the need…
- To customise this, you’ll need to log into you Heroku Account.
11. Add your
Environmental Variables to Heroku.
You should be ready to take Twitter by storm now!
ruby heroku