Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit 29b2f0e

Browse files
committed
now deploy
1 parent ee0895d commit 29b2f0e

File tree

4 files changed

+50
-150
lines changed

4 files changed

+50
-150
lines changed

README.md

Lines changed: 50 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Twitter bot bootstrap
22

3-
[![Greenkeeper badge](https://badges.greenkeeper.io/spences10/twitter-bot-bootstrap.svg)](https://greenkeeper.io/)
3+
[![Greenkeeper badge](https://badges.greenkeeper.io/spences10/twitter-bot-bootstrap.svg)](https://greenkeeper.io/) [![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](http://standardjs.com/) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](http://opensource.org/licenses/MIT) [![Chat](https://badges.gitter.im/awesome-twitter-bots/Lobby.svg)][gitter-url]
44

5-
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](http://standardjs.com/) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](http://opensource.org/licenses/MIT)
5+
<!--links-->
6+
[gitter-url]: https://gitter.im/awesome-twitter-bots/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
7+
8+
<details>
9+
<summary>Click to expand TOC</summary>
610

711
<!-- TOC -->
812

@@ -13,56 +17,58 @@
1317
- [Set up the bot](#set-up-the-bot)
1418
- [Project structure](#project-structure)
1519
- [Node dependencies](#node-dependencies)
16-
- [Heroku](#heroku)
17-
- [Heroku CLI](#heroku-cli)
18-
- [Heroku variables](#heroku-variables)
19-
- [Heroku deployment via GitHub](#heroku-deployment-via-github)
20-
- [Heroku troubleshooting](#heroku-troubleshooting)
20+
- [Deploy with now](#deploy-with-now)
2121
- [Handy tip](#handy-tip)
2222
- [Contributing](#contributing)
23-
- [Links](#links)
24-
- [License](#license)
23+
- [Links](#links)
24+
- [License](#license)
2525

2626
<!-- /TOC -->
2727

28-
This is a bootstrap for setting up a Twitter bot with Node.js using the `twit` library. The bot will favorite and retweet what you specify when configuring it. It will also reply to followers with a selection of canned responses.
28+
</details>
29+
30+
>Since doing this initial guide I have discovered the awesomeness of Zeit's now, the master branch of this project will now use `now` for deployment, if you want to use Heroku you can refer to the [deploy with Heroku][dep-with-heroku] branch 👍.
31+
32+
<!--link-->
33+
[dep-with-heroku]: https://github.com/spences10/twitter-bot-bootstrap/tree/deploy-with-heroku
2934

30-
As a primer for this, there is a great post by [@amanhimself](https://twitter.com/amanhimself) on making your own twitter bot. This is an expansion on that with further detail on configuration on Heroku.
35+
This is a bootstrap for setting up a simple Twitter bot with Node.js using the `twit` module. The bot will retweet what you specify when configuring it. It will also reply to followers with a selection of canned responses.
36+
37+
As a primer for this, there is a great post by [@amanhimself](https://twitter.com/amanhimself) on making your own twitter bot. This is an expansion on that with further detail on configuration and deployment with `now`.
3138

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

3441
## What you'll need
3542

3643
- Twitter account
37-
- Development environment with Node.js and NPM
38-
* c9 account
39-
* Node.js
40-
* NPM
41-
- Heroku account
44+
- Development environment with Node.js and npm
45+
- [Zeit account](https://zeit.co/login)
4246

4347
## Setup twitter
4448

45-
Set up an application on the Twitter account you want to favorite and retweet from via: [https://apps.twitter.com/app/new](https://apps.twitter.com/app/new)
49+
Set 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)
4650

4751
As an example, I'll configure the old [@DroidScott](twitter.com/droidscott) twitter account I have so you can follow along.
4852

49-
Straight forward enough for the twitter application, just make sure you add your phone number to your Twitter account before clicking the **Create your Twitter application** button.
53+
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.
5054

5155
![](/images/twitter-application-setup.png)
5256

5357
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.
5458

5559
## Setup development environment
5660

57-
For this I'm just going to say use [Cloud9](https://c9.io/) as you can be up and running in minutes with one of the pre made Node.js environments.
61+
If 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.
5862

59-
Note that if you choose to use Heroku and/or Cloud9 IDE in building this (like I do in this guide) in some regions you will be prompted to give a credit card number to create these accounts.
63+
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](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.
6064

6165
![](/images/c9-node-env.png)
6266

6367
## Set up the bot
6468

65-
In the project tree delete the example project files of `client`, `package.json`, `README.md` and `server.js`. You won't need them, but you can leave them there if you desire.
69+
In the project tree 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.
70+
71+
![](/images/delete-c9-starter.gif)
6672

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

@@ -72,7 +78,7 @@ git clone https://github.com/spences10/twitter-bot-bootstrap
7278

7379
## Project structure
7480

75-
The environment project tree should look something like this:
81+
The environment project tree will look something like this:
7682

7783
```text
7884
twitter-bot-bootstrap/
@@ -93,7 +99,7 @@ twitter-bot-bootstrap/
9399

94100
## Node dependencies
95101

96-
Before configuring the bot we'll need to install the dependencies, cd into the project folder with `cd tw*` this will move you to `:~/workspace/twitter-bot-bootstrap (master) $ ` from the terminal enter:
102+
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:
97103

98104
```shell
99105
npm install
@@ -110,19 +116,16 @@ Here is an example of the `dependencies` in the `package,json` file:
110116
"dotenv": "4.0.0",
111117
"snyk": "1.31.0",
112118
"twit": "2.2.5",
113-
"unique-random-array": "1.0.0",
114-
"unirest": "0.5.1"
119+
"unique-random-array": "1.0.0"
115120
}
116121
```
117122

118123
The npm command to install them all:
119124

120125
```shell
121-
npm install --save dotenv twit unique-random-array unirest
126+
npm install --save dotenv twit unique-random-array snyk
122127
```
123128

124-
If you get any `WARN` messages such as `npm WARN package.json twitter-bot@1.0.0 No repository field` this will not break the bot so it's safe to ignore.
125-
126129
Now you can configure the bot. From the terminal enter:
127130

128131
```shell
@@ -146,7 +149,7 @@ The `.env` file is where we can configure our bot, here we set what we want to s
146149
<!--Link-->
147150
[twee-bot-play]: https://github.com/spences10/twitter-bot-playground#use-twitter-search
148151

149-
>NOTE none of the `.env` items have quotes `''` round them.
152+
>NOTE none of the `.env` items have quotes `''` round them or spaces between the key and the value `KEY=value`
150153
151154
```text
152155
TWITTER_CONSUMER_KEY=Fw***********P9
@@ -164,6 +167,8 @@ TWITTER_RETWEET_RATE=120
164167
TWITTER_SEARCH_COUNT=20
165168
```
166169

170+
![](/images/clone-and-install.gif)
171+
167172
That should be it. Go to the terminal, enter `npm start` and you should get some output:
168173

169174
![](/images/bot-output.png)
@@ -172,137 +177,29 @@ Check the Twitter account:
172177

173178
![](/images/twitter-account.png)
174179

175-
## Heroku
176-
177-
Cool, now we have a bot that we can test on our dev environment, but we can't leave it there. We'll need to deploy it to Heroku.
178-
179-
If you haven't done so already, set up a [Heroku account](https://signup.heroku.com) then select **Create a new app** from the dropdown box on the top right of your dashboard. On the next screen, name the app if you want and then click **Create App**.
180-
181-
![](/images/heroku-create-new-app.png)
182-
183-
You'll be presented with your app dashboard and instructions for the deployment method.
184-
185-
![](/images/heroku-deploy.png)
186-
187-
Your app name should be displayed on the top of your dashboard. You'll need this when logging in with the Heroku CLI.
188-
189-
![](/images/heroku-app-name.png)
190-
191-
## Heroku CLI
192-
193-
We're going to deploy initially via the Heroku Command Line Interface (*CLI*).
194-
195-
On your c9 environment terminal, log into Heroku [it should be installed by default]
196-
197-
```shell
198-
heroku login
199-
```
200-
201-
Enter your credentials.
202-
203-
```shell
204-
cd twitter-bot-bootstrap
205-
git init
206-
heroku git:remote -a your-heroku-app-name
207-
```
208-
209-
Deploy your application.
210-
211-
```shell
212-
git add .
213-
git commit -am 'make it better'
214-
git push heroku master
215-
```
216-
217-
You should get build output on the terminal:
218-
219-
![](/images/heroku-build.png)
220-
221-
Then check the output with:
222-
223-
```shell
224-
heroku logs -t
225-
```
226-
227-
All good? Cool! :sunglasses:
228-
229-
## Heroku variables
180+
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.
230181

231-
Now that we have our bot on Heroku we need to add environment variables to store our Twitter keys. This is because the `.env` file where we stored our keys is listed in the `.gitignore` file, which tells git not to upload that file to Heroku. It also makes it so if in the future we want to add our code to GitHub we don't have to worry about the `.env` file making our keys public, because the file will automatically be ignored.
182+
## Deploy with now
232183

233-
All you need to do is go to the console of your Heroku app and select the 'Settings' sections and add in your Twitter keys from the `.env` file. Click the 'Reveal Config Vars' button and add in the variables with their corresponding values:
234-
235-
```text
236-
CONSUMER_KEY
237-
CONSUMER_SECRET
238-
ACCESS_TOKEN
239-
ACCESS_TOKEN_SECRET
240-
```
241-
242-
Once you have the Heroku vars set up, take a look at the `config.js` file of this project. You are going to delete this line:
184+
Got your [Zeit account](https://zeit.co/login) set up? Now is the time if not, then install `now` from the terminal:
243185

244186
```shell
245-
require('dotenv').config();
187+
npm i -g now
246188
```
247189

248-
You're now ready to deploy to Heroku again. Your console commands should look something like this:
190+
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!
249191

250-
```shell
251-
git add .
252-
git commit -m 'add environment variables'
253-
git push heroku master
254-
```
192+
![](/images/now-setup-deploy.gif)
255193

256-
Then you can check the Heroku logs again with:
194+
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:
257195

258196
```shell
259-
heroku logs -t
197+
npm run deploy
260198
```
261199

262-
You should now have a bot you can leave to do its thing forever more, or until you decide you want to change the search criteria :smile:
200+
This will use all our environment variables we defined within our `.env` file for use on the now servers.
263201

264-
## Heroku deployment via GitHub
265-
266-
You can also deploy your app by connecting to GitHub and deploy automatically to Heroku each time your master branch is updated on GitHub, this is straight forward enough.
267-
268-
Go to the ‘Deploy’ dashboard on Heroku, select GitHub as the deployment method. If you have connected your GitHub account to your Heroku account then you can search for the repository. If you forked this repo, then you can just enter `twitter-bot-bootstrap` and **Search**. You can then click the **Connect** button and now you can auto deploy from GitHub!
269-
270-
![](/images/heroku-connect-github.png)
271-
272-
## Heroku troubleshooting
273-
274-
What do you mean it crashed!?
275-
276-
![](/images/heroku-crash.png)
277-
278-
Ok, I found that sometimes the `worker` is set as `web` and it crashes out. Try setting the `worker` again:
279-
280-
```shell
281-
heroku ps:scale worker=0
282-
heroku ps:scale worker=1
283-
```
284-
285-
Or try this to be sure there are no web roles:
286-
287-
```shell
288-
heroku scale web=0 worker=1
289-
```
290-
291-
If that still crashes out then try setting the `Resources` on the Heroku dashboard, I found if you toggle between the `web`, `heroku` and `worker` it usually settles down. Basically you need to be set to the **`worker`** Dyno this is what causes the `Error R10 (Boot timeout)` crashes because it's trying to use one of the other resources when it should be using the **`worker`** Dyno.
292-
293-
![](/images/heroku-app-resources.gif)
294-
295-
Other useful Heroku commands I use:
296-
297-
```shell
298-
heroku restart
299-
```
300-
301-
By default you can only push your master branch if you are working on a development branch i.e. `dev` branch. If you want to test on Heroku, then you can use:
302-
303-
```shell
304-
git push heroku dev:master
305-
```
202+
You will get terminal output with a URL for where your bot is located, click the link and you can watch it get built.
306203

307204
## Handy tip
308205
If 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:
@@ -311,14 +208,17 @@ If you want to add this to your own GitHub repo and don't want to share your API
311208
git update-index --assume-unchanged .env
312209
```
313210

314-
I have added my most used git command I use in this [gist](https://gist.github.com/spences10/5c492e197e95158809a83650ff97fc3a)
211+
I 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.
212+
213+
<!--link-->
214+
[cheetsheets]: https://github.com/spences10/cheat-sheets/blob/master/git.md
315215

316216
## Contributing
317217
Please fork this repository and contribute back using pull requests.
318218

319219
Any contributions, large or small, major features, bug fixes and integration tests are welcomed and appreciated but will be thoroughly reviewed and discussed.
320220

321-
#### Links
221+
## Links
322222

323223
Credit for the inspiration for this should go to [@amanhimself](https://twitter.com/amanhimself) and his posts on creating your own twitter bot.
324224

@@ -334,7 +234,7 @@ Credit for the inspiration for this should go to [@amanhimself](https://twitter.
334234

335235
[![Standard - JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
336236

337-
### License
237+
## License
338238

339239
MIT License
340240

images/clone-and-install.gif

2.03 MB
Loading

images/delete-c9-starter.gif

226 KB
Loading

images/now-setup-deploy.gif

257 KB
Loading

0 commit comments

Comments
 (0)