Let's Create a Twitter Bot using Node.js and Heroku (1/3)
Tags: node, twitter, javascript, tutorial
Published: 2020-02-05 20:07:15

Do you want to automatically retweet topics you're interested in? Maybe you want to send thank every new follower you gain? Or maybe you just want to mess around and create a fun side project? If you answered yes to any of these than a twitter bot is exactly what you're looking for and I'll walk you through step by step on how to build your own.

First, I want to warn you that you'll want to be careful when building out your bot because you don't want to spam users as you can get your account suspended. There are some great examples of some twitter bots like [@dscovr_epic](https://twitter.com/dscovr_epic) (a bot that tweets photos from NASA's DSCOVR spacecraft), [@museum_bot](https://twitter.com/MuseumBot) (which tweets out high-res images from the Metropolitan Museum of Art), and (@codedailybot)[https://twitter.com/codedailybot] (a bot that retweets code related tweets). These are just a few examples but there are many more out there in the Twitter-verse. 

Alright, now that you've had a chance to see some examples of twitter bots let's get down to the fun and build our own. I'll be breaking up this walkthrough into 3 separate blog posts so this first one will just focus on getting your twitter account and API access setup. 

If you want to see my twitter bot in action you can check it out here [@coolnatureshots](https://twitter.com/coolnatureshots). 

# 1. Create your Twitter Account

I recommend creating a [new](https://twitter.com/i/flow/signup) twitter account for your bot so your followers aren't bombarded with your endless retweets and if you accidentally violate Twitter's Terms of Service and they shut your account down you don't lose your personal account. Once you create your account just make sure to verify your email address and phone number because you won't be able to anything until you have. 

# 2. Setup A Developer Account

![Twitter Developer signup homepage](https://github.com/agyin3/images/blob/master/Twitter%20Bot%20Blog/twit-dev-access.png?raw=true)

Now you'll want to [signup](https://developer.twitter.com/en/apply-for-access) for a developer account to gain access to Twitter's API.

![Twitter Developer signup options](https://github.com/agyin3/images/blob/master/Twitter%20Bot%20Blog/twit-dev-signup.png?raw=true)

There are many different options to choose but for our purposes just go on ahead and select bot. After you'll have to answer some questions on how you plan to use Twitter's API. For this project, I'll be retweeting tweets with '#photography' and '#nature'. 

![Twitter Developer signup questions](https://github.com/agyin3/images/blob/master/Twitter%20Bot%20Blog/twit-questions.png?raw=true)

![Twitter Developer signup questions](https://github.com/agyin3/images/blob/master/Twitter%20Bot%20Blog/twit-questions3.png?raw=true)

![Twitter Developer signup questions](https://github.com/agyin3/images/blob/master/Twitter%20Bot%20Blog/twit-questions2.png?raw=true)

For this project, I'll be retweeting tweets with '#photography' and '#nature'. Feel free to use these as well or you can change them how you please. While answering the questions you'll want to answer the ones you see above. Once you complete these you'll receive an email from Twitter to complete your application. It's important that you open this email and click on the provided link or else you won't be able to have a developer account. 

# 3. Create Your App 


![Twitter Developer create an app](https://github.com/agyin3/images/blob/master/Twitter%20Bot%20Blog/twit-dev-create-app.png?raw=true)

Now that your application is complete, you can create an app. You'll have to give your app a name (I called mine "Nature Photo Bot"), give a brief description of what your app will do. You can use the same information you put for your application here. 

 
 ![Twitter Developer signup options](https://github.com/agyin3/images/blob/master/Twitter%20Bot%20Blog/twit-dev-permissions.png?raw=true) 

After completing that you can edit your permission options. I'm using 'Read and write' permissions which will allow my bot to both search tweets and read tweets. If you'd like your bot to be able to send messages as well as select the 'Read, write and Direct Messages' option. You can always change these later but you'll have to regenerate your tokens if you do. Speaking of tokens...

 ![Twitter Developer signup options](https://github.com/agyin3/images/blob/master/Twitter%20Bot%20Blog/twit-dev-tokens.png?raw=true) 

Your API keys will already be generated for you so you'll just need to generate your Access tokens. Click on the generate button and a popup should appear with your keys. Be sure to copy those down and save them somewhere safe as you'll only be able to view them once. We'll also be using these in [Part 2](https://dev.to/developer_buddy/let-s-create-a-twitter-bot-using-node-js-and-heroku-2-3-22g3) once we get to building out the actual bot. 

Whew!!! We made it through the first part. I know you're probably thinking when the heck are we actually going to start writing some code? Well head on over to [Part 2](https://dev.to/developer_buddy/let-s-create-a-twitter-bot-using-node-js-and-heroku-2-3-22g3) with your API keys and let's get down to business. 

If you'd like to check mine out you can at [@coolnatureshots](https://twitter.com/coolnatureshots). You can also find the GitHub repo for it [here](https://github.com/agyin3/tweetbot-photo)