Twitter Bot



A quick guide to building a twitter bot that helps people quit twitter.

Note — this tutorial assumes you have basic knowledge of javascript and node.js You can find the final code in this github repo.

  1. TweSocial is a Twitter bot that works every day, all day to grow your Twitter page organically and consistently on your behalf. I like that they provide high-end services at affordable prices. They’re currently one of the most affordable Twitter growth and engagement companies in the industry. There are no downloads required with Twesocial.
  2. Twitter bot solutions Programming a Twitter bot is definitely a fun side project, but there are greater uses outside this for business users. For example, you can build out a robust Twitter bot as part of your fleet of social media marketing solutions. Your bot can provide valuable customer service when a human isn’t active.
  3. Twitter bots tend to get a bad rap. And sure, tricking your followers (and followees) into conversing with a glorified algorithm could be seen as morally questionable. But beyond the spam and the impersonal nature, there’s actually a lot of good that Twitter bots can do.

Before we begin, we’ll take a look at what a twitter bot can do, and some examples of existing twitter bots.

Twitter Bot

What is a twitter bot and what can they do?

A twitter bot is an automated program that tweets, likes, follows, or does any other action that a normal (human) twitter user can do.

But, unlike a human, a twitter bot can perform tasks over and over without becoming bored, sleep deprived, or dead. Here’s some examples of what a twitter bot can do:

  • Monitor every tweet being tweeted everywhere in the world in real time.
  • Automatically respond to tweets that mention a specific word, phrase, or hashtag.
  • Collect vast amounts of data and display that data in real-time anywhere on the web.
  • Automatically tweet in response to some event. e.g. 70% chance of snow in Colorado.
  • Interfere with democracy by pushing false naratives that sway the electorate to the far-right.

One tricky part of making a bot for Twitter is that if you want your bot to be able to actually post on Twitter, rather than just read from it, you will need to add a phone number to your account. There is a few ways to solve this. Most popular Twitter bots Make your own Despite the rules concerning the Twitter API use having gotten stricter throughout the years, Twitter remains a popular network for bot makers and enthusiasts, which can be easily proved by the variety of bots operating on it.

Types of twitter bots and some notable examples

Generally, twitter bots fall into one of these categories…

Bots that tweet at regular intervals

@tinycarebot — tiny care bot tweets a self care reminder every hour, like “please remember to listen to some music that helps you feel calm”

@poem_exe — generates tiny poems (“micro-poetry”) every few hours.

Bots that tweet based on an event

@earthquakebot — Tweets about any earthquake that registers 5.0 or above.

Bots that reply to you performing some action towards the bot

This could be as simple as an auto-responder for your business. Or a complex chat bot.

@botifuldingbot — the now shut-down beautiful dingbats font changing bot. It got a little carried away.

Twitter Bot

Free Twitter Bot

Bots that reply to your tweets when you didn’t interact with it at all!

@yesyoureracist — This bot retweets any tweet that starts with the phrase “I’m not racist, but…” The results are always racist.

@grammar — A bot that corrects you’re your grammar.

This is the kind of bot we’ll be making in this tutorial. Let’s get started.

How to make a twitter bot…

I don’t really like twitter — it’s reinforces toxic behaviour and is complicit in the downfall of democracy. So we’re going to make a twitter bot that helps people quit twitter.

Our twitter bot will find people who seem like they’re on the edge of quitting twitter, and will give them encouragement and the instructions on how to do it.

Getting Started (non-coding bit)

Create an account

First you’ll need a twitter account for your bot. If you already have one, great. Otherwise go to twitter.com and follow the normal steps for making an account.

Create a developer account

You’ll also need to signup for a developer account. It doesn’t take long, just follow the instructions below…

  1. Navigate to https://developer.twitter.com/en/apply/user.html
  2. Click Apply (if you’re not logged into your twitter account, you’ll be asked to now.)
  3. Fill out the form. It contains a few steps including, why you want to join the twitter developer program, details about you, and the intended use of your bot.
  4. Create an app, navigate to ‘apps’ in the dropdown under your username it will take you to the apps page. Then click, ‘create an app.’ Fill out the form on the create and app page. It contains some repetitive information.
  5. Once you’ve created your app. You’ll be taken to the app details page. Click on “keys and tokens,” then generate consumer api keys, and access tokens. We’ll need all four tokens in a minute.

That’s the non-coding bit out of the way.

Coding our twitter bot

Running a node.js server.

Now you’ll need to set up a server running node.js If you don’t know node.js you’ll need to get familiar with it before we continue. There are lots of tutorials out there that cover how to make a basic node server.

Javascript is normally used just for front-end web development, for building functionality on a web page. Node allows us to use javascript, a language front-end developers are familiar with, on the back-end.

If you want to run your server for free, I recommend using a service like Heroku.

Find bots on twitter

Installing and setting up ‘twit’

First install the twitter Api Client for Node. In your terminal type…

We’ll be making our twitter bot in one file called app.js First require ‘twit’ and create an instance of twit with your twitter app’s keys and tokens.

That’s the initial variables set up. Now we need to write the code that will run while our twitter bot is active. When our node server starts, we need it to connect to twitter and verify itself with the credentials we defined above.

Sending our first tweet

Let’s see if we can get the bot to tweet. We’ll create a tweet function and test it by having it tweet ‘hello world’ after it’s authenticated with twitter.

Okay, now run your node app. Hopefully it worked and you’ll see that your twitter account has tweeted ‘hello world.’

Monitoring Tweets

Now, we want our bot to reply to people based on what they tweet. To do that we need to start monitoring tweets, twitter gives us a way to do this — the streaming api. It sends us a stream of tweets based on a set of words or phrases.

Here I’ve chosen to use the phrases ‘leave twitter’, ‘quit twitter’, ‘delete twitter’.

Now, we can log all the tweets we’re receiving in the console. See how many there are?! We’re getting more than a tweet per second. All that #maga streaming across your console? That’s twitter!

Twitter doesn’t filter the tweets as as accurately as we’d like, so we’ll need to check each of these tweet for exact phrases we want to match. (If we replied to all of these tweets, we’d get banned in an instant.)

We also want to make sure we don’t reply to retweets or to any tweets sent by our own bot too.

Now let’s get it to tweet a reply whenever somebody tweets a tweet with one of our target phrases.

Tweeting a reply

To send a reply to a tweet, you’ll need to add the handle of the account you want to reply to, to the text of your tweet.

Twitter

Twitter Botometer

You’ll also need to include the unique ID of the tweet you’re replying to.

Also, we don’t want our bot to tweet the same thing all the time, so we’re also going to create an array of replies and pick one at random when we respond.

Our bot’s response will contain the handle of the account we’re replying to , a random response from our array, and then instructions on how to quit twitter.

testing the bot

We’ve already made sure our bot doesn’t reply to itself. (As this could cause an infinite loop and ultimately get it banned from twitter.)

To test your twitter bot, use a different account (maybe just ask a friend) and tweet something with one of the terms you want to match.

Twitter Bot Maker

Release your bot into the wild.

Does your bot work? Great. Time to release it to the public. You can check out @qwitterbot here.

Bonus Round — Updating our profile if our bot gets rate limited.

Twitter has a limit on how many tweets your bot can send. You can read more about rate limits here: https://developer.twitter.com/en/docs/basics/rate-limiting

Your bot can tweet 15 tweets every 15 minutes — if you tweet more than that, your bot will be temporarily disabled.

You might want to let people know that your bot has been disabled, to do that we use the callback function on our tweet function. If it responds with an error, we check what caused the error.

If that error code is 88 we know it’s because we’ve reached our rate limit. We can update our profile name and description to let people know.

We also want to update the profile if the bot is no longer disabled.

First we create a global variable named isAsleep and set it to false. Then we write our function…

If you found this tutorial useful (or not), please let me know. (it’s the first coding tutorial I’ve ever written, so any feedback is highly appreciated)

And of course, send me your twitter bots!

June 16, 2020

Scammers are finding success with a tool designed to infiltrate social media accounts and potentially your personal information: Twitter bots.

What are they? If you’ve seen Twitter accounts spreading fake news or tweets falsely claiming they have a cure for COVID-19, you may have spotted Twitter bots.

These social media bots do nefarious things like trolling and propagating misinformation for purposes that include spinning elections, inciting panic, and spreading malware.

It’s a good idea to learn what Twitter bots can do, how prevalent they are, and how to detect these automated accounts to help protect your devices and personal information.

Twitter bots surge: What are they and what can they do?

Twitter bots, also known as zombies, are automated Twitter accounts controlled by bot software. While they are programmed to perform tasks that resemble those of everyday Twitter users — such as liking tweets and following other users — their purpose is to tweet and retweet content for specific goals on a large scale.

The purpose of the bot and its activity can be helpful or harmful.

Twitter bots can be used for helpful purposes, such as broadcasting important content like weather emergencies in real time, sharing informative content en masse, and generating automatic replies via direct messaging.

Twitter bots also can be designed for the malicious purposes of platform intimidation and manipulation — like spreading fake news campaigns, spamming, violating others’ privacy, and sock-puppeting.

You might wonder if one account can cause damage. It usually takes a larger effort. Twitter bots are often part of what’s known as a botnet. A botnet is a broad network of automated accounts that work together to appear legitimate, liking and following each other as if they were real. Worth noting: Bots also operate on other social media platforms.

Twitter bot scams

Twitter bots rely on stealth. As artificial automations, they can pretend to be real people, liking your tweets and content. Or they can act as malicious bots that try to intimidate, bully, persuade, and incite you to believe things that may not be true and act in ways that are fueled by false information.

Cybercriminals have used Twitter bots to spread malicious content that contains malware to large groups of Twitter users at the same time. You can help protect yourself against such malware by not clicking on links in tweets and other communications from unknown or suspicious sources.

Twitter bots also have been used for political propaganda and to influence elections. Countries and interest groups may use Twitter bots to spread discontent or panic. That could potentially affect healthcare system, financial markets, community actions, and elections.

How prevalent are Twitter bots?

How many bots are in the Twittersphere? That’s hard to say. But a Carnegie Mellon University study showed a surge in bot activity while the United States has been under stay-at-home orders.

The Carnegie Mellon study found almost half of the Twitter accounts calling for America to reopen may be bots. The same study looked at more than 200 million tweets since January 2020 that reference the novel coronavirus. It found that of the top 50 retweeters, 41 — 82 percent — were bots.

The lesson? When it comes to Twitter, be careful about believing what appears to be the broad consensus or engaging in the conversation. It could be a misinformation campaign.

7 ways to recognize a Twitter bot

Here are several ways to help detect if a Twitter account is a bot or not. Keep in mind, a bot’s setup and activity often appears automated.

When trying to determine if an account might be a bot, beware of the following red flags:

  1. IP correlation — the geographical location of Twitter accounts.
  2. Time-based correlation — the release of tweets in close proximity.
  3. Automation — when an account tweets short replies that appear automated.
  4. Content similarity — when the same content is tweeted at the same time.
  5. Account creation — Twitter bots with recent creation dates.
  6. Account description — when an account looks automated because its username contains numbers. Also, it appears anonymous in the absence of a photo, biography, or profile description.
  7. Account activity — when a bot follows a lot of accounts but does not have many followers, and it’s retweeting and tweeting content faster than a human could.

What is Twitter doing to combat bots?

Twitter prohibits these malicious uses of its platform, including these activities:

  • Automation meant to undermine public conversation.
  • The creation of multiple accounts to artificially amplify messages.
  • Involvement in fake engagements by generation, solicitation, or purchase.
  • Aggressive use of Twitter in the form of tweets, follows, and other engagements.
  • Hashtag cramming or using hashtags for spamming purposes.

What does Twitter do about automated accounts engaging in the prohibited activities? The social media platforms suspends millions of bot accounts each month.

What can you do to combat Twitter bots?

You can find browser plugins that look at indicators to help identify whether or not a Twitter account is a bot. These third-party tools can help flag suspicious accounts so you won’t be fooled.

Whether you use a third-party tool or learn to recognize bots yourself, it’s smart to understand how automated platforms can enable the mass spread of false information.

Awareness and caution can help. It’s a good idea to watch for red flags and be skeptical about information contained in tweets. Go to reputable sources for fact-checking. And avoid clicking on links in tweets that could be embedded with malware.

Try BotSight for Twitter - FREE Bot Detector Tool

Flag suspected bot accounts on Twitter in real-time. Available on iOS and as a browser extension.


Editorial note: Our articles provide educational information for you. NortonLifeLock offerings may not cover or protect against every type of crime, fraud, or threat we write about. Our goal is to increase awareness about cyber safety. Please review complete Terms during enrollment or setup. Remember that no one can prevent all identity theft or cybercrime, and that LifeLock does not monitor all transactions at all businesses.

Twitter Botnet

Copyright © 2021 NortonLifeLock Inc. All rights reserved. NortonLifeLock, the NortonLifeLock Logo, the Checkmark Logo, Norton, LifeLock, and the LockMan Logo are trademarks or registered trademarks of NortonLifeLock Inc. or its affiliates in the United States and other countries. Firefox is a trademark of Mozilla Foundation. Android, Google Chrome, Google Play and the Google Play logo are trademarks of Google, LLC. Mac, iPhone, iPad, Apple and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other countries. App Store is a service mark of Apple Inc. Alexa and all related logos are trademarks of Amazon.com, Inc. or its affiliates. Microsoft and the Window logo are trademarks of Microsoft Corporation in the U.S. and other countries. The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. Other names may be trademarks of their respective owners.