Day 21: Twitter Bot — Motivational Quotes


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

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 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 :)

Global Head of Technology @Antler. Prev: VP - Engineering @BlackRock. Started #100DaysOfCode #WomenInTech

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