A bot that generates images from Quotes Api and posts it to Twitter.
git clone https://github.com/PiyushSuthar/twitter-bot.git
cd twitter-bot
npm install
node index.js
We will deploy this bot on Heroku, and make it work at a given time everyday. There are 2 ways of doing it.
- Using Heroku's own scheduler, (But we'll have to provide our credit card info)
- Using my own Lifehack/Jugaad.
Doing it with Heroku's own scheduler is easy, you can follow their Documentation. I'll show you how to do it without it.
First of all we'll install ExpressJs. Yes, we will use this one here in our bot.
npm i express
Open the index.js file and put all the code in a function.
request("https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json",{json : true}, async(err,res,body)=>{
...
})
function functionName(){
request("https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json",{json : true}, async(err,res,body)=>{
...
})
}
now require express module in the index.js file.
const express = require("express")
const app = express();
var port = process.env.PORT || 8000;
Now basically what our idea is when we will visit a specific path on the domain, this will trigger the function. So this is how we can do it.
Make sure to make the path very difficult. What I did was, I went ot a random password generaor and generated some and pasted over here.
app.get("/EXvAjMfjhPwqnk7D/vVL7xTXwPr6gkeVJ",(req,res)=>{
funcionName();//calling the function
res.send("I'm tweeting!")//Giving a response back.
})
app.listen(port,()=>console.log(`We are listening on port ${port}`))
Now just add a script in package.json
"start": "node index.js",
That's it now deploy it on heroku through Heroku Cli.
๐ค Piyush Suthar
- Website: https://piyushsuthar.codes
- Twitter: @PiyushSthr
- Github: @piyushsuthar
Give a โญ๏ธ if this project helped you!
This README was generated with โค๏ธ by readme-md-generator