Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Autohook silently failing issue #36 #37

Merged
merged 6 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ TWITTER_CONSUMER_SECRET= # https://developer.twitter.com/en/apps ➡️ Your app
TWITTER_ACCESS_TOKEN= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ Access token
TWITTER_ACCESS_TOKEN_SECRET= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ Access token secret
TWITTER_WEBHOOK_ENV= # https://developer.twitter.com/en/account/environments ➡️ One of 'Dev environment label' or 'Prod environment label'
NGROK_AUTH_TOKEN= # https://ngrok.com/ - Create a free account to get your auth token for stable tunnels
```

Autohook will pick up these details automatically, so you won't have to specify anything in code or via CLI.
Expand All @@ -82,9 +83,10 @@ export TWITTER_CONSUMER_SECRET= # https://developer.twitter.com/en/apps ➡️ Y
export TWITTER_ACCESS_TOKEN= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ Access token
export TWITTER_ACCESS_TOKEN_SECRET= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ Access token secret
export TWITTER_WEBHOOK_ENV= # https://developer.twitter.com/en/account/environments ➡️ One of 'Dev environment label' or 'Prod environment label'
export NGROK_AUTH_TOKEN= # https://ngrok.com/ - Create a free account to get your auth token for stable tunnels

# To other services, e.g. Heroku
heroku config:set TWITTER_CONSUMER_KEY=value TWITTER_CONSUMER_SECRET=value TWITTER_ACCESS_TOKEN=value TWITTER_ACCESS_TOKEN_SECRET=value TWITTER_WEBHOOK_ENV=value
heroku 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
```
## Directly

Expand All @@ -98,6 +100,7 @@ new Autohook({
token_secret: 'value',
consumer_key: 'value',
consumer_secret: 'value',
ngrok_secret:'value'
env: 'env',
port: 1337
});
Expand All @@ -111,7 +114,8 @@ $ autohook \
--secret $TWITTER_ACCESS_TOKEN_SECRET \
--consumer-key $TWITTER_CONSUMER_KEY \
--consumer-secret $TWITTER_CONSUMER_SECRET \
--env $TWITTER_WEBHOOK_ENV
--env $TWITTER_WEBHOOK_ENV \
--ngrok-secret $NGROK_AUTH_TOKEN \
```

## Install
Expand Down
1 change: 1 addition & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const argv = require('commander')
.option('--secret <secret>', 'your OAuth access token secret. (Env var: TWITTER_ACCESS_TOKEN_SECRET)')
.option('--consumer-key <consumerKey>', 'your OAuth consumer key. (Env var: TWITTER_CONSUMER_KEY)')
.option('--consumer-secret <consumerSecret>', 'your OAuth consumer secret. (Env var: TWITTER_CONSUMER_SECRET)')
.option('--ngrok-secret <authToken>', 'your ngrok authtoken. (Env var: NGROK_AUTH_TOKEN)')
.option('--env <env>', 'your Premium environment label as defined in https://developer.twitter.com/en/account/environments. (Env var: TWITTER_WEBHOOK_ENV)')
.option('--port <port>', 'port where the local HTTP server should run. Default: 1337. (Env var: PORT)')
.option('--url <url>', 'URL to an existing webhook configured to respond to Twitter')
Expand Down
3 changes: 2 additions & 1 deletion env.twitter.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ TWITTER_CONSUMER_KEY= # https://developer.twitter.com/en/apps ➡️ Your app ID
TWITTER_CONSUMER_SECRET= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ API secret key
TWITTER_ACCESS_TOKEN= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ Access token
TWITTER_ACCESS_TOKEN_SECRET= # https://developer.twitter.com/en/apps ➡️ Your app ID ➡️ Details ➡️ Access token secret
TWITTER_WEBHOOK_ENV= # https://developer.twitter.com/en/account/environments ➡️ One of 'Dev environment label' or 'Prod environment label'
TWITTER_WEBHOOK_ENV= # https://developer.twitter.com/en/account/environments ➡️ One of 'Dev environment label' or 'Prod environment label'
NGROK_AUTH_TOKEN= # https://ngrok.com/ - Create a free account to get your auth token
5 changes: 4 additions & 1 deletion examples/standalone-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ const startServer = (port, auth) => http.createServer((req, res) => {

(async () => {
try {

const NGROK_AUTH_TOKEN = process.env.NGROK_AUTH_TOKEN;
if (NGROK_AUTH_TOKEN) {
await ngrok.authtoken(process.env.NGROK_AUTH_TOKEN);
}
const url = await ngrok.connect(PORT);
const webhookURL = `${url}/standalone-server/webhook`;

Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ class Autohook extends EventEmitter {
token_secret = (process.env.TWITTER_ACCESS_TOKEN_SECRET || '').trim(),
consumer_key = (process.env.TWITTER_CONSUMER_KEY || '').trim(),
consumer_secret = (process.env.TWITTER_CONSUMER_SECRET || '').trim(),
ngrok_secret = (process.env.NGROK_AUTH_TOKEN || '').trim(),
env = (process.env.TWITTER_WEBHOOK_ENV || '').trim(),
port = process.env.PORT || DEFAULT_PORT,
headers = [],
} = {}) {

Object.entries({token, token_secret, consumer_key, consumer_secret, env, port}).map(el => {
Object.entries({token, token_secret, consumer_key, consumer_secret, ngrok_secret, env, port}).map(el => {
const [key, value] = el;
if (!value) {
throw new TypeError(`'${key}' is empty or not set. Check your configuration and try again.`);
Expand All @@ -132,6 +133,7 @@ class Autohook extends EventEmitter {

super();
this.auth = {token, token_secret, consumer_key, consumer_secret};
this.ngrokSecret = ngrok_secret;
this.env = env;
this.port = port;
this.headers = headers;
Expand Down Expand Up @@ -262,6 +264,9 @@ class Autohook extends EventEmitter {

if (!webhookUrl) {
this.startServer();
if (this.ngrokSecret) {
await ngrok.authtoken(this.ngrokSecret);
}
const url = await ngrok.connect(this.port);
webhookUrl = `${url}${WEBHOOK_ROUTE}`;
}
Expand Down