Day 21: Twitter Bot — Motivational Quotes

Harini Janakiraman
Jun 28, 2016 · 2 min read

#100DaysOfCode

Project (1 Hour): This is a quick fun project to create a twitter bot with Node.js that would tweet a motivational quote every hour. Cos everyone can use some inspiration!

Twitter Bot (Go on follow it!): SpartaaBot

Image for post
Image for post

All the code for this project can be found on my github

Step 1: Create your bot’s Twitter account and Dev App

Create a new account for your twitter bot and create a twitter app on it using this. Create access tokens on this app and note them down.

Step 2: Create your Node.js twitter bot

Sample twitter bot is my github project which tweets a motivational quote from the Forismatic REST API every hour and also favorites any tweets that anyone retweets. Make sure you install npm, node and update the twitter API tokens in the module.

Step 3: Run the bot locally

After “npm install” is complete, run the bot locally to see the tweets in action, you can tweak the time to a shorter duration to see them fly by sooner.

node quote.js

Step 4: Move the bot to server

You could leave the bot running on your computer, however it’s best to move it to some server where you don’t have to worry about downtime or keeping it up. I used heroku and instructions for running Node.js server on heroku can be found here. In addition, since Herooku has cost-saving method of putting your bot to sleep in case of no activity, use an automatic ping service such as site24x7.com to keep you bot awake.

Day 21 of #100DaysOfCode DONE

If you enjoyed this, please click 👏 so that others can enjoy it as well. Follow me on Twitter @HariniLabs to get the latest updates or just to say Hi :)

PS: I curate a bi-weekly #WomenInTech newsletter for a dose of inspiration from the world of tech and yes men can signup too! Get it here :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store