BEEP BOOP! How to make a Twitter Bot (Part 1)
Tags: twitter, bot, node
Published: 2019-10-29 00:49:22

---
title: BEEP BOOP! How to make a Twitter Bot (Part 1)
published: true
description: 
tags: twitter, bot, node,
---

So, you want to automate tweets on your timeline? Send a thank you to each new person that follows you? Retweet a topic that you are interested in? Or just play around and have fun? Then a Twitter bot is you! And I'll show you the steps to get one step up and working!

But first, we need a little bit of background: what exactly is a Twitter bot? 

A Twitter bot is an account that is programmed in the background to perform a certain function when certain criteria get triggered. Those functions include retweet tweets under a certain hashtag, sending an auto DM when someone follows them or liking certain tweets.

But not all Twitter accounts are fully automated. For example, you may notice certain brand accounts have their bots trigger an auto message when someone mentions them. This helps the Social Media Manager or Customer Service personnel know who needs assistance right away and they jump in to assist.

Sadly bots have gained a negative reputation on Twitter as they can be (and have been) used for evil. However, if you build them properly (and for good), bots can be useful for you and your followers alike! In fact you probably have used a couple of them and not even realized it. Examples of good bots are <a href="https://twitter.com/yayfrens" target="_blank">@yayfrens</a> (a bot that periodically auto-tweets positive affirmations), <a href="https://twitter.com/threadreaderapp" target="_blank"> @threadreaderapp</a> (a bot that takes a thread of tweets and converts it to blog form for easy reading) and <a href="https://twitter.com/this_vid" target="_blank">@this_vid</a> (a bot that takes a video tweet and creates a downloadable video link). There are tons more, but this just gives you an idea of what kind of bots you can create. To see more good bots like these and learn more, check out <a href="https://twitter.com/botwikidotorg" target="_blank">@botwikidotorg.</a>

Now that you have an idea of what you can create, let's start building our own bot! There are a few tips, tricks and warnings to keep in mind, but I will make sure to point those out as we go into building out our bot.

This first blog post will involve getting access to Twitter's API. Since this is a bit of an extensive process, the actual building of the bot will come in part 2 and deploying the bot will be in part 3.

Ready? Of course you are! Let's get started!

<h3>Step 1: Create a Twitter Account</h3>

You can use your own Twitter account for this, but I highly recommend making another account to use. Why? Because 1) You may annoy your followers will all the auto-retweets and testing you'll be doing and 2) If you accidentally violate Twitter's Terms of Service, you could lose your account. Once you make your account, make sure that email address and phone number is verified (you won't be able to do anything else until these are completed)

<h3>Step 2: Apply to Twitter's API</h3>

![Alt Text: Twiiter developer application page](https://thepracticaldev.s3.amazonaws.com/i/08ksobjj8h6jqwn2ewsh.PNG)

<a href="https://developer.twitter.com/en/application/use-case" target="_blank">Go here</a> and apply to use Twitter's API. This part gets a little annoying because you have to answer a lot of questions and clearly explain what you are using the API for. We're going to start out easy on this one. For this purpose, I'm going to make a bot that retweets tweets that tags #pcbuilds and #battlestations to my @cooltechrobot Twitter account (I'm really into desktop setups). You can use these hashtags as well or any other ones you like. Just make sure you clearly explain what you are using your bot for and take your time. 

Once your application is submitted, Twitter will ask you to confirm your email. Make sure you do this step; Twitter won't grant you access to their API until you click the link in the email.

<h4>Pit Stop: Very Important Information!</h4>

**Be sure to read all of Twitter's <a href="https://developer.twitter.com/en/developer-terms/policy.html" target="_blank">Developer Policy</a>, <a href="https://developer.twitter.com/en/developer-terms/agreement.html" target="_blank">Developer Agreement</a> and <a href="https://help.twitter.com/en/rules-and-policies/twitter-automation" target="_blank">Automation Rules.</a> Yes, it's boring, but it's important to be aware of what you can and cannot do on their platform. Twitter takes these rules very seriously and one small mistake could mean you losing access to your account and having to start over.

**In case you decided to skim the rules, let me give you a quick breakdown: Twitter's daily limit on likes/follows/retweets etc apply to bots. There's no way around this and if you try to get around this Twitter will ban you. Also, you can't use the bot to spam followers on their TL or DM's; if you're caught doing this Twitter will suspend you. Later on, I'll share with you more tips and tricks to be sure you're staying in compliance with Twitter's rules.

<h3>Step 3: Create a Twitter App</h3>

![Alt Text: Screenshot of Twitter Developer Dashboard page](https://thepracticaldev.s3.amazonaws.com/i/hd38sk31wu2em9dgc2c3.PNG)

Now that we have access (yay!) we can go ahead and create our app. This will give us the access token keys that we need to get for our bot. Again, you have to fill out some more information. For the website, you can just add your Github, since we'll be deploying there too anyway. Once you create the app, you will be given access to your API keys under the Keys and Tokens tab.

![Alt Text: Screenshot Twitter keys and tokens page with tokens omitted](https://thepracticaldev.s3.amazonaws.com/i/i2o3ctbdqozfi5pkva51.png)

*NOTE: DO NOT SHARE YOUR KEYS WITH ANYONE! Anyone who has these keys will automatically have access and control to your account. If your keys get compromised, make sure to generate new ones as soon as possible (generating new keys will invalidate the old ones). In the next tutorial, I'll show you have to hide the keys before they get deployed to Github/Heroku.

*NOTE: Make sure your keys have read/write access to the access keys. If it says read-only, go to the permission tabs and change it to read/write. You will need to regenerate new access keys in order for the updated permissions to take.

Now that you have your keys you are ready to build your bot! You can use Node or Python to build your bot. In Part 2, I'll show you how to build the bot using Node and test it out!