{"id":13570811,"url":"https://github.com/spences10/twitter-bot-bootstrap","last_synced_at":"2025-04-04T07:32:09.399Z","repository":{"id":68893129,"uuid":"79264567","full_name":"spences10/twitter-bot-bootstrap","owner":"spences10","description":"Twitter bot bootstrap :boot: using node and twit :bird:","archived":true,"fork":false,"pushed_at":"2018-11-10T05:42:58.000Z","size":11581,"stargazers_count":231,"open_issues_count":0,"forks_count":104,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-11-05T03:36:52.475Z","etag":null,"topics":["bootstrap","bot","javascript","node","now","now-cli","nowsh","personal","setup-twitter","twitter","twitter-account","twitter-application","twitter-bot","twitter-bot-bootstrap","twitter-keys"],"latest_commit_sha":null,"homepage":"https://medium.freecodecamp.com/easily-set-up-your-own-twitter-bot-4aeed5e61f7f#.dw898leyj","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spences10.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-01-17T19:40:49.000Z","updated_at":"2024-10-30T22:00:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"dd130ea1-dce8-4c96-817e-490922a712e7","html_url":"https://github.com/spences10/twitter-bot-bootstrap","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spences10%2Ftwitter-bot-bootstrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spences10%2Ftwitter-bot-bootstrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spences10%2Ftwitter-bot-bootstrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spences10%2Ftwitter-bot-bootstrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spences10","download_url":"https://codeload.github.com/spences10/twitter-bot-bootstrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247138982,"owners_count":20890147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bootstrap","bot","javascript","node","now","now-cli","nowsh","personal","setup-twitter","twitter","twitter-account","twitter-application","twitter-bot","twitter-bot-bootstrap","twitter-keys"],"created_at":"2024-08-01T14:00:55.201Z","updated_at":"2025-04-04T07:32:04.388Z","avatar_url":"https://github.com/spences10.png","language":"JavaScript","readme":"# Twitter bot bootstrap\n\n[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](http://opensource.org/licenses/MIT)\n[![Chat](https://badges.gitter.im/awesome-twitter-bots/Lobby.svg)][gitter-url]\n\n\u003c!--links--\u003e\n[gitter-url]: https://gitter.im/awesome-twitter-bots/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to expand TOC\u003c/summary\u003e\n\n\u003c!-- TOC --\u003e\n\n- [Twitter bot bootstrap](#twitter-bot-bootstrap)\n  - [What you'll need](#what-youll-need)\n  - [Setup twitter](#setup-twitter)\n  - [Setup development environment](#setup-development-environment)\n  - [Node 8](#node-8)\n  - [Set up the bot](#set-up-the-bot)\n  - [Project structure](#project-structure)\n  - [Node dependencies](#node-dependencies)\n  - [Deploy with now](#deploy-with-now)\n  - [Handy tip](#handy-tip)\n  - [Links](#links)\n  - [License](#license)\n\n\u003c!-- /TOC --\u003e\n\n\u003c/details\u003e\n\nThis 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.\n\nAs a primer for this, there is a great post by [@amanhimself](https://twitter.com/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.\n\nBefore starting the clock you'll need to set up some accounts if you don't have them already.\n\n## What you'll need\n\n- Twitter account\n- Development environment with Node.js and npm\n- [Zeit account](https://zeit.co/login)\n\n## Setup twitter\n\nSet up an application on the Twitter account you want to retweet from via: [https://apps.twitter.com/app/new](https://apps.twitter.com/app/new)\n\nAs an example, I'll configure the old [@DroidScott](twitter.com/droidscott) twitter account I have so you can follow along.\n\nStraight 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.\n\n![](/images/twitter-application-setup.png)\n\nYou 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.\n\n## Setup development environment\n\nIf you don't already have a dev environment with node installed then for a quick-start I'd suggest using [Cloud9](https://c9.io/) you can be up and running in minutes with one of the pre made Node.js environments.\n\nNote 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](https://glitch.com) 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.\n\n![](/images/c9-node-env.png)\n\n## Node 8\n\nIf 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:\n\n```shell\nnvm install 8 # install node 8\nnvm use 8 # set it to use node 8\nnvm alias default 8 # default to 8 so version persists after reboots\n```\n\n`nvm` stands for Node Version Manager which comes installed by default on c9 machines :+1:\n\n## Set up the bot\n\nIn 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.\n\n![](/images/delete-c9-starter.gif)\n\nIn your new Node.js c9 environment go to the terminal and enter:\n\n```shell\ngit clone https://github.com/spences10/twitter-bot-bootstrap\n```\n\n## Project structure\n\nThe environment project tree will look something like this:\n\n```text\ntwitter-bot-bootstrap/\n├─ images\n├─ node_modules/\n├─ src/\n│  ├─ api\n│  │  ├─ reply.js\n│  │  └─ retweet.js\n│  ├─ bot.js\n│  ├─ config.js\n│  └─ rando.js\n├─ .env\n├─ .gitignore\n├─ .snyk\n├─ CODE_OF_CONDUCT.md\n├─ CONTRIBUTING.md\n├─ LICENSE\n├─ README.md\n├─ index.js\n├─ package-lock.json\n└─ package.json\n```\n\n## Node dependencies\n\nBefore 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:\n\n```shell\nnpm install\n```\n\nThis will install all the dependencies listed in the `package.json` file.\n\nIf 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:\n\nHere is an example of the `dependencies` in the `package,json` file:\n\n```json\n  \"dependencies\": {\n    \"dotenv\": \"4.0.0\",\n    \"snyk\": \"1.31.0\",\n    \"twit\": \"2.2.5\",\n    \"unique-random-array\": \"1.0.0\"\n  }\n```\n\nThe npm command to install them all:\n\n```shell\nnpm install --save dotenv twit unique-random-array snyk\n```\n\nNow you can configure the bot. From the terminal enter:\n\n```shell\nnpm init\n```\n\nThis will configure the `package.json` file with your details as desired. Just keep hitting return if you're happy with the defaults.\n\n**Make a `.env` file:** make a file named `.env` do it with the terminal with the following command:\n\n```shell\ntouch .env\n```\n\nThis should be at the root of your project directory.\n\nNow you'll need to add your Twitter keys to the `.env` file. Just input the keys in their corresponding fields and save the file.\n\nThe file structure should look as follows:\n\n```\nTWITTER_CONSUMER_KEY=\nTWITTER_CONSUMER_SECRET=\nTWITTER_ACCESS_TOKEN=\nTWITTER_ACCESS_TOKEN_SECRET=\n\nQUERY_STRING=my super awesome query string!,google,android\n\nRANDOM_REPLY=Hi @${screenName} thanks for the follow! What are you working on today?|@${screenName} thanks for following! What are you working on today?\n\nRESULT_TYPE=mixed\nTWITTER_LANG=en\n\nTWITTER_RETWEET_RATE=.1\nTWITTER_SEARCH_COUNT=20\n```\n\nNote 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.\n\nIf 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.\n\n![](/images/c9-hidden-files-check.gif)\n\nAdd your API keys to the `.env` file :key:\n\nThe `.env` file is where we can configure our bot, here we set what we want to search on, check out the [`twitter-bot-playground`][twee-bot-play] for information on Twitter search.\n\n`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.\n\n\u003c!--Link--\u003e\n[twee-bot-play]: https://github.com/spences10/twitter-bot-playground#use-twitter-search\n\n\u003eNOTE none of the `.env` items have quotes `''` round them or spaces between the key and the value `KEY=value`\n\n```text\nTWITTER_CONSUMER_KEY=Fw***********P9\nTWITTER_CONSUMER_SECRET=TD************Cq\nTWITTER_ACCESS_TOKEN=31**************UC\nTWITTER_ACCESS_TOKEN_SECRET=r0************S2\n\nQUERY_STRING=mango,horses,\"donald -trump -duck\"\nRANDOM_REPLY=Hi @${screenName} thanks for the follow! What are you working on today?,@${screenName} thanks for following! What are you working on today?\n\nRESULT_TYPE=mixed\nTWITTER_LANG=en\n\nTWITTER_RETWEET_RATE=120\nTWITTER_SEARCH_COUNT=20\n```\n\n![](/images/clone-and-install.gif)\n\nThat should be it. Go to the terminal, enter `npm start` and you should get some output:\n\n![](/images/bot-output.png)\n\nCheck the Twitter account:\n\n![](/images/twitter-account.png)\n\nYou 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.\n\n## Deploy with now\n\nGot your [Zeit account](https://zeit.co/login) set up? Now is the time if not, then install `now` from the terminal:\n\n```shell\nnpm i -g now\n```\n\nThen `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!\n\n![](/images/now-setup-deploy.gif)\n\nIf 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:\n\n```shell\nnpm run deploy\n```\n\nThis will use all our environment variables we defined within our `.env` file for use on the now servers.\n\nYou will get terminal output with a URL for where your bot is located, click the link and you can watch it get built.\n\n## Handy tip\nIf you want to add this to your own GitHub repo and don't want to share your API keys :key: with the world then you should turn off tracking on the `.env` file. From the terminal enter this git command:\n\n```shell\ngit update-index --assume-unchanged .env\n```\n\nI have added my most used git commands I use in this [repo][cheetsheets] I use it on a daily basis, please feel free to use it.\n\n\u003c!--link--\u003e\n[cheetsheets]: https://github.com/spences10/cheat-sheets/blob/master/git.md\n\n## Links\n\nCredit for the inspiration for this should go to [@amanhimself](https://twitter.com/amanhimself) and his posts on creating your own twitter bot.\n\n* [create-a-simple-twitter-bot-with-node-js](https://hackernoon.com/create-a-simple-twitter-bot-with-node-js-5b14eb006c08#.flysreo60)\n\n* [how-to-make-a-twitter-bot-with-nodejs](https://chatbotslife.com/how-to-make-a-twitter-bot-with-nodejs-d5cb04fdbf97#.h5ah8dq5n)\n\n* [twitter-mctwitbot](https://medium.com/@spences10/twitter-mctwitbot-4d15cd005dc0#.dp9q5f427)\n\n* [awesome-twitter-bots](https://github.com/amandeepmittal/awesome-twitter-bots)\n\n---\n\n## License\n\nMIT License\n\nCopyright (c) 2017, Scott Spence. All rights reserved.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspences10%2Ftwitter-bot-bootstrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspences10%2Ftwitter-bot-bootstrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspences10%2Ftwitter-bot-bootstrap/lists"}