Git Product home page Git Product logo

twitter-bot's Introduction

Twitter-Bot

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.

How to use

  1. Install node.js if needed: https://nodejs.org/en/download/
  2. Create a dev account for the Twitter API if you don't already have one: https://developer.twitter.com/en
  3. Register your WhatsApp number on callmebot.com (cmb): Follow: https://www.callmebot.com/blog/free-api-whatsapp-messages/
  4. Insert your Twitter API keys and cmb key in the data/data.json
  5. Run "node bot.js"

Customize 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
        };

Note

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.

Run on e.g. a Raspberry PI

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.

Sources

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/

twitter-bot's People

Contributors

patpatwithhat avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.