• This repository has been archived on 04/Jul/2023
  • Stars
    star
    256
  • Rank 154,112 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Node js twitter bot to send auto welcome message for your new followers

โš ๏ธ Twitter deleted the Stream API in favor of a new Activities API,

This Package is not working any More.

Create your own auto direct message Twitter Bot ๐Ÿ’ฌ๐Ÿ’ฌ

Create a welcome message for your new followers in twitter is the first step to get more people engage with your tweets and links, As you know there is a lot of online services that help you send auto direct message to your new followers but I think itโ€™s crazy how online services charge between $5 to $15 for a simple tool that creates bots when you can build your own.

In this article, I will introduce my own Twitter bot that I built to send a welcome message to my new followers on Twitter and how it works for me very fine for 6 months.

By the end of this article, you can build your own twitter auto DM for free !! from creating your message to deploy the bot.

What do you need?

To develop this bot we need:

If you are not familiar with Nodejs. or maybe you are not a programmer, you can fork the project from GitHub and use it as your own.

Letโ€™s get started.


Create your Own Twitter Bot ๐Ÿ› ๐Ÿ› 

Step 1: Github.

  • Show you support by a simple star

  • Fork the project repo in Github

  • Now, Customize your welcome message by updating the GenerateMessagefunction and Commit your change.

Step 2 : Twitter

Create a Twitter app: Go to https://apps.twitter.com/ and click to the button Create New App, then complete all the fields as the following:

Go to the Permissions section and give the app the access to send Direct messages by checking the option โ€œRead, Write and Access direct messagesโ€.

Go to tab key and Access Tokens then click the Generate Access Token button at the bottom of the page.

Now copy all your keys Consumer Key, Consumer Secret , Acess TokenA and Acess Token Secret, because we need to add all of them later as Heroku vars.

Step 3: Heroku

  • Create a Heroku account. it is free!
  • Connect to your Heroku account and create a new app by clicking the Newbutton, then the Create new App option.
  • Choose your app name then click Create App

Choose Github as the Deployment method then click the connect button

Tab your bot repo name : twitter-bot in your case.

Now you need to add all keys as Heroku vars on the tab settings and config the Variables section.

Return to the deploy section and click โ€œenable automatic deploysโ€, then โ€œdeploy branchโ€ button to deploy your app for the first time.

Go to resources section and activate the worker Dyno and disable the web dyno.

To know if your app has been started successfully click to the more button at the top right of the page then click view logs option. you will found a simple console with some output similar to this screenshot, I have some new followers and the message has been sent successfully ๐Ÿค“๐Ÿค“.


Live Demo

To make sure thatโ€™s the hole project work perfectly you need just to follow me and my twitter bot will send you a welcome message ๐Ÿค—๐Ÿค—.


How it works ๐Ÿ’ก

If you have already cloned the project to your computer you will see this structure:

$ cd twitter-bot  
$ tree .     
.  
โ”œโ”€โ”€ config.js  
โ”œโ”€โ”€ index.js  
โ”œโ”€โ”€ LICENSE  
โ”œโ”€โ”€ package.json  
โ”œโ”€โ”€ Procfile  
โ”œโ”€โ”€ README.md  
โ””โ”€โ”€ src  
    โ”œโ”€โ”€ AutoDM.js  
    โ””โ”€โ”€ Twit.js

As you can see the project is a simple node js app with an index.js file as an entry point:

infex.js file

The index file is a simple script that imports and calls the AutoDM function.

To make the app more fun we added a simple message when the app has started successfully.

As I have already mentioned I use the twit package to connect to the Twitter API, to do that we need to create a simple twitter app and init the Twit instance with your App config like the following:

Twit.js file

config.js file

process.env.XXXXXXX is an environment variable that we need to add to our Heroku app in deployment step.

Now the fun part is to Create the AutoDM function :

As you can see the AutoDM is a simple arrow function that listens to the stream follow event from the twitter API and executes the SendMessage function.

AutoDM.js file

The sendMessge function gets as a parameter the user who follows you. All we need here is to create an obj with screen_name and a text message and send a post request to the Twitter API for sending a Direct Message to @screen_nameas the following.

SendMessge Function

Now is you your turn to think how you would like to introduce yourself. You can modify the existing GenerateMessage Function to create your own welcome message, donโ€™t forget to add some human behaviour in there, it makes more chance that the user clicks to your link or respond to your message.

GenerateMessge Function

It is easy, doesnโ€™t it? you can read more code from the Github repo.

More Repositories

1

reactjs-popup

React Popup Component - Modals,Tooltips and Menusโ€Šโ€”โ€Š All inย one
TypeScript
1,763
star
2

awesome-new

A list of `.new` domains to perform online actions in one quick action.
381
star
3

parcel-story

Develop your react components with parcel - A simple Alternative to storybook Using parceljs
JavaScript
141
star
4

elazizi.com

My Blog
Astro
22
star
5

reactjs-popup-burger-menu

reactjs-popup burger menu example
JavaScript
19
star
6

spotify-login-animation-with-react-navigation-v5

Spotify login animation with react navigation v5
JavaScript
18
star
7

react-query-auth-token-refresh

Demo code for React Query Auth Token Refresh Article
TypeScript
12
star
8

gatsby-theme-doc

Gatsby theme for your library documentation
JavaScript
11
star
9

react-native-course

React Native Practical Course
JavaScript
11
star
10

story-router

A simple component that's take array of component and return a simple router
JavaScript
9
star
11

react-native-forms-tutorial

A complete React Native Forms Tutorial
TypeScript
9
star
12

react-native-image-picker-example

Java
7
star
13

DEVC_Meetup_React_and_reactNative

JavaScript
5
star
14

Tasker

Tasker Application
TypeScript
4
star
15

react-code-quality-talk

improving react code quality with the right tools https://react-code-quality.elazizi.com/#0
JavaScript
3
star
16

ReactRabatDay1

JavaScript
3
star
17

markdown-docs-starter

A react starter to create docs website with markdown and embed examples
JavaScript
3
star
18

yjose

My Profile Description
2
star
19

my-twitter-bot

My own twitter bot
JavaScript
2
star
20

github-action-demo

1
star
21

react-zero-to-ninja-day2

react-zero-to-ninja-day2
JavaScript
1
star
22

create-react-modal-with-22-line-of-code

Created with CodeSandbox
HTML
1
star