Keep on track with your favorite Twitter accounts and redirect their tweets to your WhatsApp number if you are as lazy as me and don't open Twitter on a regular basis.
In this example, I redirect all Tweets of Elon Musk to my WhatsApp number.
- Install node.js if needed: https://nodejs.org/en/download/
- Create a dev account for the Twitter API if you don't already have one: https://developer.twitter.com/en
- Register your WhatsApp number on callmebot.com (cmb): Follow: https://www.callmebot.com/blog/free-api-whatsapp-messages/
- Insert your Twitter API keys and cmb key in the data/data.json
- Run "node bot.js"
The bot makes a request to the Twitter API every 10 seconds.
customize here (millis)
setInterval(main, 10000);
If you want to look for other accounts etc:
check the getTweets() function
Adjust the params object
Look for an account name and get the last 2 tweets (if the bot runs 24/7 it's not necessary to get more than 2 tweets per cycle)
let params = {
from: 'elonmusk',
count: 2
};
Look for a hashtag and get the last 10 tweets
let params = {
q: '#funstuff',
count: 10
};
All tweets get collected into one message sent by cmb due to cmb only allowing 25 messages per 240 minutes.
If this changes someday, you could also send every tweet in one message.
In the params.json the id of the last tweets gets saved to not redirect the same tweet multiple times.
If you want to run this as a bot for example on a raspberry, check out this post:
https://stackoverflow.com/questions/4681067/how-do-i-run-a-node-js-application-as-its-own-process/28542093#28542093
You have to set "chmod +rwx" for bot.js and params.json to execute the bot and write to params.json.
Check out for a basic understanding of the Twitter API: Level Up Developer: https://www.youtube.com/watch?v=0gFzUYSbJwY
Used for WhatsApp connection: https://www.callmebot.com/blog/free-api-whatsapp-messages/