@degen/twitter-autohook
Version:
Automatically setup and serve webhooks for the Twitter Account Activity API
38 lines • 5.82 kB
JSON
{
"name": "@degen/twitter-autohook",
"version": "2.0.1",
"description": "Automatically setup and serve webhooks for the Twitter Account Activity API",
"repository": {
"type": "git",
"url": "https://github.com/degen-workgroup/autohook"
},
"main": "index.js",
"bin": {
"autohook": "./cli.js"
},
"author": "Twitter",
"license": "MIT",
"keywords": [
"twitter",
"twitter-api",
"webhooks"
],
"dependencies": {
"commander": "^2.20.0",
"dotenv": "^16.0.0",
"fastify": "^3.27.4",
"fastify-raw-body": "^3.2.0",
"needle": "^2.3.3",
"ngrok": "^3.2.1",
"nock": "^12.0.2"
},
"devDependencies": {
"eslint": "^7.6.0",
"standard-version": "^9.3.2"
},
"scripts": {
"start": "node examples/standalone-server.js",
"release": "standard-version"
},
"readme": "# Autohook 🎣 + Fastify \n\nThis is a fork of [Autohook](https://github.com/twitterdev/autohook) that uses [Fastify](https://www.fastify.io/) instead of needle.\n\n\n\n* 🚀 Spawns a server for you\n* ⚙️ Registers a webhook (it removes existing webhooks if you want, and you can add more than one webhook if your Premium subscription supports it)\n* ✅ Performs the CRC validation when needed\n* 📝 Subscribes to your current user's context (you can always subscribe more users if you need)\n* 🎧 Exposes a listener so you can pick up Account Activity events and process the ones you care about\n\n## Usage\n\nYou can use Autohook as a module or as a command-line tool.\n\n### Node.js module\n\n```js\nconst { Autohook } = require('twitter-autohook');\n\n(async ƛ => {\n const webhook = new Autohook();\n \n // Removes existing webhooks\n await webhook.removeWebhooks();\n \n // Listens to incoming activity\n webhook.on('event', event => console.log('Something happened:', event));\n \n // Starts a server and adds a new webhook\n await webhook.start();\n \n // Subscribes to a user's activity\n await webhook.subscribe({oauth_token, oauth_token_secret});\n})();\n```\n\n### Command line\n\nStarting Autohook from the command line is useful when you need to test your connection and subscriptions.\n\nWhen started from the command line, Autohook simply provisions a webhook, subscribes your user (unless you specify `--do-not-subscribe-me`), and echoes incoming events to `stdout`.\n\n```bash\n# Starts a server, removes any existing webhook, adds a new webhook, and subscribes to the authenticating user's activity.\n$ autohook -rs\n\n# All the options\n$ autohook --help\n```\n\n## OAuth\n\nAutohook works only when you pass your OAuth credentials. You won't have to figure out OAuth by yourself – Autohook will work that out for you.\n\nYou can pass your OAuth credentials in a bunch of ways.\n\n## Dotenv (~/.env.twitter)\n\nCreate a file named `~/.env.twitter` (sits in your home dir) with the following variables:\n\n```bash\nTWITTER_CONSUMER_KEY= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ API key\nTWITTER_CONSUMER_SECRET= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ API secret key\nTWITTER_ACCESS_TOKEN= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ Access token\nTWITTER_ACCESS_TOKEN_SECRET= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ Access token secret\nTWITTER_WEBHOOK_ENV= # https://developer.twitter.com/en/account/environments ➡️ One of 'Dev environment label' or 'Prod environment label'\nNGROK_AUTH_TOKEN= # https://ngrok.com/ - (optional) Create a free account to get your auth token for stable tunnels\n```\n\nAutohook will pick up these details automatically, so you won't have to specify anything in code or via CLI.\n\n## Env variables\n\nUseful when you're deploying to remote servers, and can be used in conjunction with your dotenv file.\n\n```bash\n\n# To your current environment\nexport TWITTER_CONSUMER_KEY= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ API key\nexport TWITTER_CONSUMER_SECRET= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ API secret key\nexport TWITTER_ACCESS_TOKEN= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ Access token\nexport TWITTER_ACCESS_TOKEN_SECRET= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ Access token secret\nexport TWITTER_WEBHOOK_ENV= # https://developer.twitter.com/en/account/environments ➡️ One of 'Dev environment label' or 'Prod environment label'\nexport NGROK_AUTH_TOKEN= # https://ngrok.com/ - (optional) Create a free account to get your auth token for stable tunnels\n\n# To other services, e.g. Heroku\nheroku config:set TWITTER_CONSUMER_KEY=value TWITTER_CONSUMER_SECRET=value TWITTER_ACCESS_TOKEN=value TWITTER_ACCESS_TOKEN_SECRET=value TWITTER_WEBHOOK_ENV=value NGROK_AUTH_TOKEN=value\n```\n## Directly\n\nNot recommended, because you should always [secure your credentials](https://developer.twitter.com/en/docs/basics/authentication/guides/securing-keys-and-tokens.html).\n\n### Node.js\n\n```js\nnew Autohook({\n token: 'value',\n token_secret: 'value',\n consumer_key: 'value',\n consumer_secret: 'value',\n ngrok_secret: 'value', // optional\n env: 'env',\n port: 1337\n});\n```\n\n### CLI\n\n```bash\n$ autohook \\\n --token $TWITTER_ACCESS_TOKEN \\\n --secret $TWITTER_ACCESS_TOKEN_SECRET \\\n --consumer-key $TWITTER_CONSUMER_KEY \\\n --consumer-secret $TWITTER_CONSUMER_SECRET \\\n --env $TWITTER_WEBHOOK_ENV \\\n --ngrok-secret $NGROK_AUTH_TOKEN # optional\n```\n\n## Install\n\n```bash\n# npm\n$ npm i -g twitter-autohook\n\n# Yarn\n$ yarn global add twitter-autohook\n```\n"
}