Code Monkey home page Code Monkey logo

hasura-twitter-bot's Introduction

Building a Twitter Bot on Hasura

In this tutorial, we will create a Twitter Bot deployed on Hasura, which will do the following 3 tasks for a particular keyword(s) which appears in someone's tweet:

  • Favorite the tweet
  • Retweet the tweet
  • Follow the user who tweeted about that keyword

Full code for this tutorial can be found here

Pre-requisites for the tutorial

Getting the bot running

Create a twitter application

  • Login to your new Twitter account you made for the bot.
  • Navigate to https://apps.twitter.com/app/new
  • Fill out the required fields. You can leave the callback URL blank. Also fill out any valid website in your website section.
  • Click on Create your Twitter Application.

Twitter app screen

  • Go to the Keys and Access Tokens tab in the next page and keep a note of the four tokens/keys shown i.e. Consumer Key, Consumer Secret, Access Token, Access Token Secret. You may have to create access token and access token secret for the first time if it was not shown.

Twitter app screen2

In this project, we are using the twit NPM package for fectching tweets and for favoriting, retweeting and following.

Getting the Hasura project

$ hasura quickstart geekysrm/twitter-bot
$ cd twitter-bot
# Add CONSUMER_KEY to secrets.
$ hasura secrets update bot.twitter_consumer_key.key <YOUR-CONSUMER-KEY>
# Add CONSUMER_SECRET to secrets
$ hasura secrets update bot.twitter_consumer_secret.key <YOUR-CONSUMER-SECRET>
# Add ACCESS_TOKEN to secrets
$ hasura secrets update bot.twitter_access_token.key <YOUR-ACCESS-TOKEN>
# Add ACCESS_TOKEN_SECRET to secrets
$ hasura secrets update bot.twitter_access_token_secret.key <ACCESS-TOKEN-SECRET>
# Deploy
$ git add . && git commit -m "Deployment commit"
$ git push hasura master

After the git push completes, run:

$ hasura microservice list

You will get an output like so:

INFO Getting microservices...                     
INFO Custom microservices:                        
NAME   STATUS    INTERNAL-URL(tcp,http)   EXTERNAL-URL
bot    Running   bot.default              http://bot.apology69.hasura-app.io

INFO Hasura microservices:                        
NAME            STATUS    INTERNAL-URL(tcp,http)   EXTERNAL-URL
auth            Running   auth.hasura              http://auth.apology69.hasura-app.io
data            Running   data.hasura              http://data.apology69.hasura-app.io
filestore       Running   filestore.hasura         http://filestore.apology69.hasura-app.io
gateway         Running   gateway.hasura           
le-agent        Running   le-agent.hasura          
notify          Running   notify.hasura            http://notify.apology69.hasura-app.io
platform-sync   Running   platform-sync.hasura     
postgres        Running   postgres.hasura          
session-redis   Running   session-redis.hasura     
sshd            Running   sshd.hasura              
vahana          Running   vahana.hasura

Check that the service named bot is up and running.

That's it! You have created your very first Twitter bot.

Now, your bot will check for recent tweets about '#Hasura' or '#Javascript'. (You can change the keyword(s) you want to look for in the telegram-bot/microservices/bot/src/server.js file.) And your bot will favorite and retweet those recent tweets about that keyword(s); and also will follow the user who tweeted abut that.

Support

If you happen to get stuck anywhere, feel free to raise an issue here. Also, you can contact me via email or Twitter or Facebook.

hasura-twitter-bot's People

Contributors

geekysrm avatar

Watchers

James Cloos 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.