An open API service indexing awesome lists of open source software.

https://github.com/osscameroon/caparledev-bot

Twitter bot for the hashtag #caparledev
https://github.com/osscameroon/caparledev-bot

hashtag twitter-api twitter-bot twitter-streaming-api

Last synced: 2 months ago
JSON representation

Twitter bot for the hashtag #caparledev

Awesome Lists containing this project

README

          

# CaParleDev Bot

#### Twitter bot used to retweet all tweets having the hashtag `#caparledev`

## Prerequisites
- Node.js
- MongoDB
- Typescript

## Installation
- Clone the repository
```shell
git clone https://github.com/osscameroon/caparledev-bot.git [project_name]

cd [project_name]
```

- **Create configuration file and edit with your own value**
```shell
cp .env.example .env
nano .env
```

- **Create a Twitter application**
1. Login to your Twitter account on [developer.twitter.com](developer.twitter.com).
2. Navigate to the [Twitter App dashboard](https://developer.twitter.com/en/portal/projects-and-apps)
3. If you have an existing app, go to the next step. If not, to create an app, you will be first asked to create a
project. You can give the app the name you want. When asked the access level required for your app, select Read Only,
it will be enough for the script to work.
4. Open the app and navigate to the "keys and tokens" page.
5. Copy the Consumer Key and Secret, Access Token and Secret

- **Set credentials in .env**
```dotenv
TWITTER_APP_CONSUMER_KEY=consumer_key
TWITTER_APP_CONSUMER_SECRET=consumer_secret
TWITTER_APP_ACCESS_TOKEN_KEY=access_token_key
TWITTER_APP_ACCESS_TOKEN_SECRET=access_token_secret
```
- **Start application**
```shell
yarn watch # On Terminal 1
yarn start # On Terminal 2
```

- **Launch ngrok tunnels to the app**
```shell
yarn ngrok
```

- **Register the auth callback in twitter application**

Copy the url generated by Ngrok, go to to your Twitter app in developer portal,
locate the section the section "CALLBACK URLS", paste the url and save the changes.

- **Call the endpoint to set generate auth URL**
```shell
# The call
curl http://localhost:7432/auth/url

# The response
{"url":"https://api.twitter.com/oauth/authenticate?force_login=true&oauth_token=Qj8UOwBBAAABTOKhAAABdCZxfsI"}
```

- **Authenticate with the bot account**

Navigate to the URL in the browser and login with the bot account.
After successful login, you will receive a JSON reponse with OAuth access token key and OAuth access token secret
```json
{
"oauthToken": "OAuth access token key",
"oauthTokenSecret": "OAuth access token secret"
}
```

- **Set in config file the OAuth token key and secret generated**
```dotenv
TWITTER_BOT_ACCESS_TOKEN_KEY=oauth_access_token_key
TWITTER_BOT_ACCESS_TOKEN_SECRET=oauth_access_token_secret
```

- **Generate Bearer token**
```bash
yarn bearer:token
```
Open the .env file and set the generated bearer token
```dotenv
TWITTER_BEARER_TOKEN=bearer_token
```

- **Enable Twitter stream and set the hashtag(s) you want to stream.**

Separate hashtag with a comma if you have many. You can set up to 5000
```dotenv
ENABLE_STREAM=true
HASHTAG_TO_TRACK=#hastag1,#hastag2,#hastag3,....,#hastagn
```

- **Restart the app**
```shell
yarn start
```