Starter web app for consuming events via Account Activity API (beta).
- A Twitter app created on apps.twitter.com
- Node.js
- Heroku CLI (optional)
-
Create a Twitter app on apps.twitter.com
-
On the Permissions tab > Access section > enable Read, Write and Access direct messages.
-
On the Keys and Access Tokens tab > Your Access Token section > click Create my access token button.
-
On the Keys and Access Tokens tab, take note of the
consumer key
,consumer secret
,access token
andaccess token secret
.
-
Clone this repository:
git clone https://github.com/twitterdev/twitter-webhook-boilerplate-node.git
-
Install Node.js dependencies:
npm install
-
Create a new
config.json
file based onconfig.sample.json
and fill in your Twitter keys and tokens. -
Run locally:
node index
-
Deploy app. To deploy to Heroku see "Deploy to Heroku" instructions below.
Take note of your webhook URL. For example:
https://your.app.domain/webhooks/twitter
-
Create webhook config. Update
WEBHOOK_URL
in source code.node example_scripts/webhook_management/create-webhook-config.js
Take note of returned
webhook_id
. -
Add user subscription. Update
WEBHOOK_ID
in source code.node example_scripts/webhook_management/add-subscription.js
Subscription will be created for user the context provided by the access tokens.
-
Test configuration by sending a DM to or from the subscribed account. You should receive a message event on your deployed webhook app.
See the example scripts in the example_scripts
directory to:
- Send Direct Messages.
- Manage webhook configs and subscriptions.
- Setup Welcome Message deeplinks and defaults.
-
Init Heroku app.
heroku create
-
Run locally.
heroku local
-
Confgirue environment variables. Set up an environment variable for evey propertey on config.json. See Heroku doucmentations on Configuration and Config Vars.
-
Deploy to Heroku.
git push heroku master
Note: The free tier of Heroku will put your app to sleep after 30 minutes. On cold start, you app will have very high latency which may result in a CRC failure that deactivates your webhook. To trigger a CRC request and re-validate run the following script with your WEBHOOK_ID
:
node example_scripts/webhook_management/trigger-crc-request.js