• This repository has been archived on 11/Nov/2018
  • Stars
    star
    234
  • Rank 171,630 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 6 years ago

Reviews

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

Repository Details

Twitter bot bootstrap ๐Ÿ‘ข using node and twit ๐Ÿฆ

Twitter bot bootstrap

Renovate enabled license Chat

Click to expand TOC

This is a bootstrap for setting up a simple Twitter bot with Node.js using the npm twit module. The bot will retweet what you specify when configuring it. It will also reply to followers with a selection of canned responses.

As a primer for this, there is a great post by @amanhimself on making your own twitter bot, check it out in the Links section. This is an expansion on that with further detail on configuration and deployment with now from Zeit.

Before starting the clock you'll need to set up some accounts if you don't have them already.

What you'll need

  • Twitter account
  • Development environment with Node.js and npm
  • Zeit account

Setup twitter

Set up an application on the Twitter account you want to retweet from via: https://apps.twitter.com/app/new

As an example, I'll configure the old @DroidScott twitter account I have so you can follow along.

Straight forward enough for the twitter application, make sure you add your phone number to your Twitter account before clicking the Create your Twitter application button.

You should now be in the 'Application Management' section where you will need to take note of your keys. You should have your 'Consumer Key (API Key)' and 'Consumer Secret (API Secret)' already available. You'll need to scroll to the bottom of the page and click the Create my access token to get the 'Access Token' and 'Access Token Secret' take note of all four of them as you'll need them when setting up the bot.

Setup development environment

If you don't already have a dev environment with node installed then for a quick-start I'd suggest using Cloud9 you can be up and running in minutes with one of the pre made Node.js environments.

Note that in some regions you will be prompted to enter credit card information to use Cloud9 you will not be charged, there are other options to use like Glitch if you don't have a credit card. For this guide I'm going to be using Cloud9 which is what will be in the images.

Node 8

If you're using a c9 environment then you'll need to upgrade node which I think comes pre-installed at version 6 which will cause some errors with the code in this repository, so we're going to go with version 8 for this, so, in the terminal:

nvm install 8 # install node 8
nvm use 8 # set it to use node 8
nvm alias default 8 # default to 8 so version persists after reboots

nvm stands for Node Version Manager which comes installed by default on c9 machines ๐Ÿ‘

Set up the bot

In the project tree for the default c9 node application delete the example project files of client, node_modules, package.json, README.md and server.js. You won't need them, but you can leave them there if you so desire.

In your new Node.js c9 environment go to the terminal and enter:

git clone https://github.com/spences10/twitter-bot-bootstrap

Project structure

The environment project tree will look something like this:

twitter-bot-bootstrap/
โ”œโ”€ images
โ”œโ”€ node_modules/
โ”œโ”€ src/
โ”‚  โ”œโ”€ api
โ”‚  โ”‚  โ”œโ”€ reply.js
โ”‚  โ”‚  โ””โ”€ retweet.js
โ”‚  โ”œโ”€ bot.js
โ”‚  โ”œโ”€ config.js
โ”‚  โ””โ”€ rando.js
โ”œโ”€ .env
โ”œโ”€ .gitignore
โ”œโ”€ .snyk
โ”œโ”€ CODE_OF_CONDUCT.md
โ”œโ”€ CONTRIBUTING.md
โ”œโ”€ LICENSE
โ”œโ”€ README.md
โ”œโ”€ index.js
โ”œโ”€ package-lock.json
โ””โ”€ package.json

Node dependencies

Before configuring the bot we'll need to install the dependencies, cd into the project folder with cd tw* in the terminal this will move you to :~/workspace/twitter-bot-bootstrap (master) $ from the terminal enter:

npm install

This will install all the dependencies listed in the package.json file.

If you get an errors then I suggest installing the dependencies one by one from the package.json file with the same command and the package name at the end:

Here is an example of the dependencies in the package,json file:

  "dependencies": {
    "dotenv": "4.0.0",
    "snyk": "1.31.0",
    "twit": "2.2.5",
    "unique-random-array": "1.0.0"
  }

The npm command to install them all:

npm install --save dotenv twit unique-random-array snyk

Now you can configure the bot. From the terminal enter:

npm init

This will configure the package.json file with your details as desired. Just keep hitting return if you're happy with the defaults.

Make a .env file: make a file named .env do it with the terminal with the following command:

touch .env

This should be at the root of your project directory.

Now you'll need to add your Twitter keys to the .env file. Just input the keys in their corresponding fields and save the file.

The file structure should look as follows:

TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=

QUERY_STRING=my super awesome query string!,google,android

RANDOM_REPLY=Hi @${screenName} thanks for the follow! What are you working on today?|@${screenName} thanks for following! What are you working on today?

RESULT_TYPE=mixed
TWITTER_LANG=en

TWITTER_RETWEET_RATE=.1
TWITTER_SEARCH_COUNT=20

Note that RANDOM_REPLY is split with a pipe | and the QUERY_STRING is split by a comma , this is so that RANDOM_REPLY can have a comma in the reply text.

If you can not find the .env file in the file structure of your c9 project then you will need to enable the Show Hidden Files option. In the file view select the settings cog then tick the Show Hidden Files option if it is not already checked.

Add your API keys to the .env file ๐Ÿ”‘

The .env file is where we can configure our bot, here we set what we want to search on, check out the twitter-bot-playground for information on Twitter search.

QUERY_STRING should be what you want to retweet tweets on with the search terms separated with commas. RANDOM_REPLY again is comma separated replies with the ${ScreenName} which is replaced when replying to the follower. TWITTER_RETWEET_RATE is in minutes.

NOTE none of the .env items have quotes '' round them or spaces between the key and the value KEY=value

TWITTER_CONSUMER_KEY=Fw***********P9
TWITTER_CONSUMER_SECRET=TD************Cq
TWITTER_ACCESS_TOKEN=31**************UC
TWITTER_ACCESS_TOKEN_SECRET=r0************S2

QUERY_STRING=mango,horses,"donald -trump -duck"
RANDOM_REPLY=Hi @${screenName} thanks for the follow! What are you working on today?,@${screenName} thanks for following! What are you working on today?

RESULT_TYPE=mixed
TWITTER_LANG=en

TWITTER_RETWEET_RATE=120
TWITTER_SEARCH_COUNT=20

That should be it. Go to the terminal, enter npm start and you should get some output:

Check the Twitter account:

You now have a tweet bot, if you want to have this deployed so it's not just running from your machine or from the c9 machine [which is against their terms of service] then we can go over that next.

Deploy with now

Got your Zeit account set up? Now is the time if not, then install now from the terminal:

npm i -g now

Then now from the terminal and you will be prompted to enter your email, you will be sent a confirmation email, click the link and you're ready to go!

If you take a look at the package.json file in the "scripts" section you see there is one for "deploy" this is the command to deploy the bot to now, so from the terminal:

npm run deploy

This will use all our environment variables we defined within our .env file for use on the now servers.

You will get terminal output with a URL for where your bot is located, click the link and you can watch it get built.

Handy tip

If you want to add this to your own GitHub repo and don't want to share your API keys ๐Ÿ”‘ with the world then you should turn off tracking on the .env file. From the terminal enter this git command:

git update-index --assume-unchanged .env

I have added my most used git commands I use in this repo I use it on a daily basis, please feel free to use it.

Links

Credit for the inspiration for this should go to @amanhimself and his posts on creating your own twitter bot.


License

MIT License

Copyright (c) 2017, Scott Spence. All rights reserved.

More Repositories

1

cheat-sheets

Cheat Sheets ๐Ÿญ๐Ÿค–๐Ÿ‘€
Svelte
228
star
2

sveltekit-embed

SvelteKit embed components
TypeScript
203
star
3

VBA-IDE-Code-Export

Export & Import VBA code for use with Git (or any VCS)
VBA
119
star
4

sveltekit-mdsvex-starter-blog

A Markdown blog built with SvelteKit, MDSveX, Tailwind CSS and DaisyUI
Svelte
79
star
5

sveltekit-theme-switch-example

Demo app using theme-change in SvelteKit with Tailwind and DaisyUI
Svelte
69
star
6

svead

Svead ๐Ÿบ, a component that allows you to set head meta information, canonical, title, Twitter and Facebook Open Graph tags, and schema.org data.
Svelte
67
star
7

twitter-bot-playground

Want to build your own twitter bot ๐Ÿฃ check out the documentation.
JavaScript
62
star
8

vscode-vba

VBA syntax highlighting and snippets for use in VSCode
TypeScript
52
star
9

pacellman

Pac-Man in Excel
VBA
48
star
10

scottspence.com

My blog made with SvelteKit and MDSveX
Svelte
47
star
11

sveltekit-vendure-commerce

SvelteKit and Vendure Commerce example ๐Ÿค
Svelte
39
star
12

VBA-Coding-Standards

VBA Code Guidelines
35
star
13

react-seo-component

A React SEO component
TypeScript
33
star
14

cv

My online CV using Svelte
Svelte
33
star
15

settings

Settings, for when things die and you can't quite remember how things were ๐Ÿ™ƒ
JavaScript
20
star
16

thelocalhost

Modern web development guides hints and tips.
JavaScript
19
star
17

scottspence.me

Personal portfolio built with Gatsby
JavaScript
17
star
18

blog.scottspence.me

My personal blog made with Gatsbyjs
JavaScript
15
star
19

sveltekit-reactions

๐ŸŽ‰ An emoji reactions component to use on your site
Svelte
14
star
20

last.scottspence.com

My Letter Beautiful Mysterious Notebook.
HTML
13
star
21

sparkles-blog

Svelte
13
star
22

gatsby-starter-chakra-ui

The Gatsby default starter using chakra UI
JavaScript
13
star
23

graphcms-sveltekit-portfolio-and-blog-starter

A SvelteKit portfolio and blog starter with GraphCMS
Svelte
12
star
24

vba-snippets

VBA code snippets for Microsoft VSCode.
11
star
25

dotfiles

dot files and configurations ๐Ÿ’ ๐Ÿ—ƒ
JavaScript
11
star
26

sveltekit-starter-blog

Svelte
9
star
27

sveltekit-and-airtable-contact-form-example

SvelteKit form submission example with Airtable
Svelte
9
star
28

sveltekit-with-urql

An example of using URQL with SvelteKit
Svelte
8
star
29

sveltekit-authentication-cookies

TypeScript
7
star
30

sveltekit-short-urls

Short URLs with SvelteKit
TypeScript
6
star
31

sveltekit-with-auth0

SvelteKit with Auth0 example from Chris Ellis' blog
JavaScript
6
star
32

sveltekit-graphcms-starter-blog

SvelteKit starter blog with GraphCMS
Svelte
6
star
33

sveltekit-contact-form-example

Contact form example with SvelteKit using nodemailer
Svelte
6
star
34

react-tic-tac-toe

React Tic Tac Toe
JavaScript
5
star
35

gradient-animation-example

Gradient text animation example with Tailwind CSS and daisyUI in SvelteKit
JavaScript
5
star
36

kitql-with-sveltekit-and-graphcms

Svelte
4
star
37

sveltekit-data-loading-examples

TypeScript
4
star
38

tech-twitter-irl

JavaScript
4
star
39

sveltekit-auth

JavaScript
4
star
40

vscode-vba-icons

Simple VBA IDE icons theme for VSCode
4
star
41

kitql-with-graphcms

TypeScript
4
star
42

developer-hub-crm

TypeScript
4
star
43

github-user-information

Serverless function to display GitHub user information as images
TypeScript
4
star
44

og-image-gen

Open Graph Image Gen with SvelteKit and Satori
TypeScript
3
star
45

svelteflix

Example SvelteKit project from the Frontend Masters workshop with Rich Harris
Svelte
3
star
46

nextjs-mdx-landing-page

JavaScript
3
star
47

hackernews-react-apollo

Graphcool Hackernews clone in React with Apollo
JavaScript
3
star
48

VBA-Import-Eport-to-SQL-Server

Excel with validation for a SQL server backend
PLpgSQL
3
star
49

sveltekit-env-example

TypeScript
3
star
50

urql-with-sveltekit-and-graphcms

Svelte
3
star
51

gatsby-starter-styled-components

JavaScript
3
star
52

vba-custom-calendar-control

vba-custom-calendar-control
Visual Basic
3
star
53

svelte-pod

RSS podcast player
Svelte
2
star
54

JavaScript30

Learn the new hotness with @WesBos and JavaScript30, these are my follow along files
HTML
2
star
55

html-all-the-things

A recreation of the HTML All The Things website using SvelteKit and GraphCMS
Svelte
2
star
56

sveltekit-local-fonts

Using local fonts with Tailwind in a SvelteKit project
JavaScript
2
star
57

find-tech-conferences

An open source directory of global tech conferences
Svelte
2
star
58

httpcodes-dev

A searchable list off HTTP codes with details
TypeScript
2
star
59

burnt.scottspence.com

My personal site built with Toast, Tailwind and MDX.
HTML
2
star
60

load-markdown-via-endpoint

TypeScript
2
star
61

javascript-stack-boilerplate

JavaScript stack boilerplate ๐Ÿณ๐Ÿ‘จโ€๐Ÿณ
JavaScript
2
star
62

dang-thats-delicious

Learn node coursework ๐Ÿ‘€:squirrel:
JavaScript
2
star
63

table-of-contents-example-gatsby-and-mdx

Example of smooth scroll in Gatsby with a Table of Contents component
JavaScript
2
star
64

night-fever

JavaScript
2
star
65

insta-styled

๐Ÿคณ Instagram filters list from https://github.com/picturepan2/instagram.css in a SvelteKit page
CSS
2
star
66

sveltekit-slides

Svelte
2
star
67

github-user-repos

Vercel serverless function to get GitHub user repos
TypeScript
2
star
68

now-short-urls

Short URLs for Vercel's Now.sh
2
star
69

sveltekit-and-turso-analytics

๐Ÿง Roll your own analytics with SvelteKit and Turso
TypeScript
2
star
70

robots-txt-syntax-highlighting

robots.txt syntax highlighting for VS Code
2
star
71

personal-goals

Personal goals for accountability!
2
star
72

autohotkey

AutoHotkey
2
star
73

hacker-nuxt

Simple hackernews clone in nuxt
Vue
1
star
74

sveltest

TypeScript
1
star
75

gatsby-netlify-cms

CSS
1
star
76

slidev-theme-dark-night-owl

CSS
1
star
77

twitter-bot-twit

Basic Twitter bot for my likes and retweets, uses the `twit` npm package
JavaScript
1
star
78

svelte-quiz

Svelte Quiz app using the Open Trivia Database
Svelte
1
star
79

graphql-request-with-sveltekit-and-graphcms

Svelte
1
star
80

houdini-with-sveltekit-example

Example of using Houdini with SvelteKit
JavaScript
1
star
81

gatsby-eats-apis

Slides for API Days London talk - November 14th 2019
JavaScript
1
star
82

generate-og-image

TypeScript
1
star
83

c-counter

Cryptocurrency ticker with Svelte
Svelte
1
star
84

gatsby-wordpress-example

JavaScript
1
star
85

framework-of-the-day

Get your fresh JavaScript frameworks here!
JavaScript
1
star
86

gatsby-starter-file-system-route-api-mdx

MDX
1
star
87

actions-deploy-to-vercel

TypeScript
1
star
88

svelte-actions-demo

Svelte
1
star
89

sveltekit-ui

Svelte
1
star
90

shiki-magic-move-svelte

TypeScript
1
star
91

markdown-showdown

JavaScript
1
star
92

jobba-jobba-jobba

HTML
1
star
93

jamstack-conf-workshop-2021

Building with SvelteKit and GraphQL workshop - Jamstack Conf 2021
Svelte
1
star
94

positivity-api

Positive quotes
JavaScript
1
star
95

fcc-example-mar-22-my-developer-portfolio

My developer portfolio built with SvelteKit and GraphCMS
Svelte
1
star
96

blog-name-generator

JavaScript
1
star
97

characters-from-password

Pick characters from password
Svelte
1
star
98

pomodoro

Svelte
1
star
99

sveltekit-skeleton

JavaScript
1
star
100

sveltekit-and-fathom

Add Fathom analytics to your SvelteKit site!
Svelte
1
star