Skip to content

This is a simple twitter bot which favorites, retweets the tweets and follows users who tweet about a keyword; deployed in Hasura.

Notifications You must be signed in to change notification settings

geekysrm/hasura-twitter-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

This is a simple twitter bot which favorites, retweets the tweets and follows users who tweet about a keyword; deployed in Hasura.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published