Giter Site home page Giter Site logo

xdevplatform / autohook Goto Github PK

View Code? Open in Web Editor NEW
151.0 151.0 32.0 8.13 MB

Automatically setup and serve webhooks for the Twitter Account Activity API

License: MIT License

JavaScript 100.00%
api twitter twitter-account-activity twitter-api webhook webhook-server

autohook's People

Contributors

alechp avatar andypiper avatar iamdaniele avatar leocabeza avatar owlwalks avatar sachushaji avatar simonl07 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autohook's Issues

Error code 104: ngrok is not yet ready to start tunnels

Getting a 104 error when trying to run the out of the box example.

Expected behavior

$ node index.js
Getting webhooks…
Removing webhooks…
Removing https//.../webhook
Registering https://.../webhook as a new webhook…
Webhook created.
Subscribed to ... activities.

Actual behavior

$ node index.js
Getting webhooks…
Removing webhooks…
{
  error_code: 104,
  status_code: 503,
  msg: 'ngrok is not yet ready to start tunnels',
  details: {
    err: 'a successful ngrok tunnel session has not yet been established'
  }
}

Steps to reproduce the behavior

index.js

require('dotenv').config()
const { Autohook } = require('twitter-autohook');

async function initWebhook(oauth_token, oauth_token_secret) {
    try {
        const webhook = new Autohook();

        // Removes existing webhooks
        await webhook.removeWebhooks();

        // Listens to incoming activity
        webhook.on("event", event => console.log("Something happened:", event));

        // Starts a server and adds a new webhook
        await webhook.start();

        // Subscribes to a user's activity
        await webhook.subscribe({ oauth_token, oauth_token_secret });
    } catch (e) {
        console.log(e);
    }
}

initWebhook(
    process.env.TWITTER_ACCESS_TOKEN,
    process.env.TWITTER_ACCESS_TOKEN_SECRET
);

.env

TWITTER_CONSUMER_KEY= ...
TWITTER_CONSUMER_SECRET= ...
TWITTER_ACCESS_TOKEN= ...
TWITTER_ACCESS_TOKEN_SECRET= ...
TWITTER_WEBHOOK_ENV=...

package.json

...
  "dependencies": {
    "dotenv": "^8.2.0",
    "twitter": "^1.7.1",
    "twitter-autohook": "^1.4.2"
  }
...

'token' is empty or not set. Check your configuration and try again.

'token' is empty or not set. Check your configuration and try again.

Expected behavior

To output what's written on this article by Twitter Developers

$ node index.js
Getting webhooks…
Removing webhooks…
Removing https://ce085a0d.ngrok.io/webhook…
Registering https://e3fd0ff6.ngrok.io/webhook as a new webhook…
Webhook created.
Subscribed to <username>'s activities.

Actual behavior

$ npm start

> [email protected] start D:\Jaagrav's Stuff\Coding\NodeJS Projex\supcoder
> node src/index

TypeError: 'token' is empty or not set. Check your configuration and try again.
    at D:\Jaagrav's Stuff\Coding\NodeJS Projex\supcoder\node_modules\twitter-autohook\index.js:131:15
    at Array.map (<anonymous>)
    at new Autohook (D:\Jaagrav's Stuff\Coding\NodeJS Projex\supcoder\node_modules\twitter-autohook\index.js:128:85)
    at D:\Jaagrav's Stuff\Coding\NodeJS Projex\supcoder\src\index.js:5:21
    at Object.<anonymous> (D:\Jaagrav's Stuff\Coding\NodeJS Projex\supcoder\src\index.js:23:3)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node src/index`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Jaagrav\AppData\Roaming\npm-cache\_logs\2021-02-16T15_43_25_427Z-debug.log

Steps to reproduce the behavior

This is the exact code I have written after following the article,

const { Autohook } = require("twitter-autohook");

(async (start) => {
  try {
    const webhook = new Autohook();

    // Removes existing webhooks
    await webhook.removeWebhooks();

    // Starts a server and adds a new webhook
    await webhook.start();

    // Subscribes to your own user's activity
    await webhook.subscribe({
      oauth_token: process.env.TWITTER_ACCESS_TOKEN,
      oauth_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
    });
  } catch (e) {
    // Display the error and quit
    console.error(e);
    process.exit(1);
  }
})();

215 error: Bad Authentication data

Receiving 215 'Bad Authentication data'. Is this up to date with Twitter's AAA Api ref?

Expected behavior

Expecting Autohook to generate the webhook

Actual behavior

This does not happen. I get the below in my terminal instead.

Getting webhooks…
Removing webhooks…
Registering https://e82a-2a00-23c5-fd87-6601-6006-e738-4301-de4f.ngrok.io/webhook as a new webhook…
Cannot create webhook: AuthenticationError: Bad Authentication data. (HTTP status: 400, Twitter code: 215)
    at tryError (C:\Users\leona\AppData\Roaming\npm\node_modules\twitter-autohook\errors\index.js:53:12)
    at Autohook.setWebhook (C:\Users\leona\AppData\Roaming\npm\node_modules\twitter-autohook\index.js:208:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Autohook.start (C:\Users\leona\AppData\Roaming\npm\node_modules\twitter-autohook\index.js:277:7)
    at async C:\Users\leona\AppData\Roaming\npm\node_modules\twitter-autohook\cli.js:60:5 {
  code: 215
}
Error: Bad Authentication data. (HTTP status: 400, Twitter code: 215)

Steps to reproduce the behavior

Install via npm: npm i -g twitter-autohook
Create .env.twitter file in home dir with correct details. (I know the details are correct because I used them in other calls to twtr API.) I didn't include a ngrok link
Run autohook -rs

Brief thoughts

It looks to me like this may not send enough authentication data, per the Premium API Ref. Are oauth nonce, signature, and timestamp not needed?

Getting error while trying to use autohook to generate a webhook

While runnning the index.js file, I get this error ==>

Getting webhooks…
Removing webhooks…
Registering https://4d2a94bf.ngrok.io/webhook as a new webhook…
ReferenceError: URL is not defined
at setWebhook (/Users/mikeashleycedric/node_modules/twitter-autohook/index.js:169:20)
at Autohook.start (/Users/mikeashleycedric/node_modules/twitter-autohook/index.js:287:29)
at
at process._tickCallback (internal/process/next_tick.js:188:7)

Twitter Autohook silently fails to receive furthur reqests after a few hours

I have successfully integrated twitter autohook and every functionality seems working fine. But after a few hours, it silently stops taking requests without throwing much error.

Expected behavior

It should work perfectly after the server is up even after several hours and should error out if something failed

Actual behavior

Autohook get subscribed and after a few hours it doesn't receive any response

Steps to reproduce the behavior

Configure autohook and deploy to a server. After few hours it doesn't accept webhook requests.

Error Logs

My server is configured to automatically restart if the application errors out. Sometimes, I see this error coming up

image

The codebase is opensource. So you can also view my implementation here

Autohook suddenly stops sending messages

After starting the Autohook and it's working normally, suddenly it stops sending messages yet in console logs it shows that it is still listing to the events and processing, it's just not sending the response to the sender, this happens may be after sending around 20 messages between sender and autohook.

and after sometime it becomes normal again and starts responding to messages again.

is this issue related to using the free twitter developer account, should I upgrade to another account type?

Cannot find module 'qs'

When using it as a node module, it throws because it couldn't find the qs dependency.

Expected behavior

Not to throw

Actual behavior

It throws:
image

Steps to reproduce the behavior

install as a node module with npm install twitter-autohook --save, then:

import { Autohook } from 'twitter-autohook';

new Autohook({
  token: process.env.TWITTER_ACCESS_TOKEN,
  token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
  consumer_key: process.env.TWITTER_CONSUMER_KEY,
  consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
  env: process.env.TWITTER_WEBHOOK_ENV
});

TypeError: Cannot read property 'name' of undefined

One line summary of the issue here.

Cannot start with autohook -rs

Expected behavior

I stored my credentials in ~/.env.twitter, and ran autohook -rs but I am not able to start due to following errors:

Actual behavior

Getting webhooks…
Removing webhooks…
(node:25498) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of undefined
    at /usr/local/share/.config/yarn/global/node_modules/twitter-autohook/cli.js:68:33
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:25498) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:25498) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Steps to reproduce the behavior

  1. Configure .env.twitter
  2. run autohook -rs

I have also tried to pass credentials by command line but the same error appears

Freezing during installation

Installation freezes when trying to install using 'npm i -g twitter-autohook'

Freezing happens on following line:
(##################) ⠴ reify:ngrok: timing reifyNode:node_modules/twitter-autohook/node_modules/lodash Completed in 393ms

After force stopping with 'ctrl+c' terminal shows these:

npm ERR! path /home/user/.nvm/versions/node/v18.12.1/lib/node_modules/twitter-autohook/node_modules/ngrok
npm ERR! command failed
npm ERR! signal SIGINT
npm ERR! command sh -c -- node ./postinstall.js
npm ERR! ngrok - cached download found at /home/user/.ngrok/aHR0cHM6Ly9iaW4uZXF1aW5veC5pby9jLzRWbUR6QTdpYUhiL25ncm9rLXN0YWJsZS1saW51eC1hbWQ2NC56aXA=.zip
npm ERR! ngrok - unpacking binary
npm ERR! ngrok - downloading binary https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
ngrok - downloading progress: 4011224/13832437
npm ERR! ngrok - error unpacking binary Error: Could not find the End of Central Directory Record
npm ERR!     at DecompressZip.findEndOfDirectory (/home/user/.nvm/versions/node/v18.12.1/lib/node_modules/twitter-autohook/node_modules/decompress-zip/lib/decompress-zip.js:176:15)
npm ERR!     at _fulfilled (/home/user/.nvm/versions/node/v18.12.1/lib/node_modules/twitter-autohook/node_modules/q/q.js:854:54)
npm ERR!     at /home/user/.nvm/versions/node/v18.12.1/lib/node_modules/twitter-autohook/node_modules/q/q.js:883:30
npm ERR!     at Promise.promise.promiseDispatch (/home/user/.nvm/versions/node/v18.12.1/lib/node_modules/twitter-autohook/node_modules/q/q.js:816:13)
npm ERR!     at /home/user/.nvm/versions/node/v18.12.1/lib/node_modules/twitter-autohook/node_modules/q/q.js:624:44
npm ERR!     at runSingle (/home/user/.nvm/versions/node/v18.12.1/lib/node_modules/twitter-autohook/node_modules/q/q.js:137:13)
npm ERR!     at flush (/home/user/.nvm/versions/node/v18.12.1/lib/node_modules/twitter-autohook/node_modules/q/q.js:125:13)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
npm ERR! ngrok - install failed, retrying

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2022-12-29T13_01_25_615Z-debug-0.log

Cannot subscribe to activities: Webhook URL must be defined to create subscriptions. Should this not be done automatically?

I'm not able to successfully subscribe to my webhook using autohook.

Expected behavior

I would expect autohook to automatically define the webhook URL for me and subscribe successfully.

Actual behavior

It throws the error Cannot subscribe to [my username's] activities: Webhook URL must be defined to create subscriptions. (Twitter code: 170).

Steps to reproduce the behavior

import { Autohook } from "twitter-autohook";

export default async function initWebhook(oauth_token, oauth_token_secret) {
  try {
    const webhook = new Autohook();

    // Removes existing webhooks
    await webhook.removeWebhooks();

    // Listens to incoming activity
    webhook.on("event", event => console.log("Something happened:", event));

    // Starts a server and adds a new webhook
    webhook.start();

    // Subscribes to a user's activity
    webhook.subscribe({ oauth_token, oauth_token_secret });
  } catch (e) {
    console.log(e);
  }
}

  initWebhook(
    process.env.TWITTER_ACCESS_TOKEN,
    process.env.TWITTER_ACCESS_TOKEN_SECRET
  );

Full error:

Registering https://480a3fc7.ngrok.io/webhook as a new webhook…
(node:106798) UnhandledPromiseRejectionWarning: Error: Cannot subscribe to [username] activities: Webhook URL must be defined to create subscriptions. (Twitter code: 170).
    at Autohook.subscribe (/)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:106798) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:106798) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Webhook created.

"UnhandledPromiseRejectionWarning: Error: Cannot subscribe this user: invalid OAuth credentials provided."

Can't make the example script work with my provided oauth token and secret.

Expected behavior

It should subscribe.

Actual behavior

..but does not.

Steps to reproduce the behavior

copy paste the example script provided - since it does not work as is, I've added two const variables:

const oauth_token = "mytoken"
const oauth_token_secret = "mytokensecret"

However, this returns the error

"UnhandledPromiseRejectionWarning: Error: Cannot subscribe this user: invalid OAuth credentials provided."

Client application is not permitted to access this user's webhook subscriptions.

(node:20122) UnhandledPromiseRejectionWarning: AuthenticationError: Client application is not permitted to access this user's webhook subscriptions. (HTTP status: 401, Twitter code: 348)

Expected behavior

The example code from the README should work

Actual behavior

It fails

Steps to reproduce the behavior

  1. Create .env.twitter file in your home directory

  2. Create a index.js file with the following content

const { Autohook } = require('twitter-autohook');

async function main() {
  const webhook = new Autohook();
  await webhook.removeWebhooks();

  webhook.on('event', (event) => console.log('Something happened:', event));

  await webhook.start();

  await webhook.subscribe({
    oauth_token: process.env.TWITTER_ACCESS_TOKEN,
    oauth_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
  });
}

main();
  1. Run the app using node index.js

  2. The apps fails.

Could not find a declaration for Module 'twitter-autohook'

Could not find a declaration file for module 'twitter-autohook'. '/Users/jerseyetr/Documents/Twitter-Bot/node_modules/twitter-autohook/index.js' implicitly has an 'any' type.
Try npm install @types/twitter-autohook if it exists or add a new declaration (.d.ts) file containing declare module 'twitter-autohook';ts(7016)

As a noob, im not entirely sure what this means. I tried fixing with the recommended fix, but did not work.

The server won't start when a webhookURL is passed to the start() function

When webhook.start(customURL) is called the server won't start.

Expected behavior

When webhook.start(customURL) is called the server should be started with the startServer() function.

Actual behavior

The startServer() function is only executed when no url is passed to webhook.start()

Steps to reproduce the behavior

Call webhook.start() with a custom URL.

Not able to get/listen data of incoming events

One line summary of the issue here.
After adding webhook.on('event', async event => {console.log('You received an event!'); }); line into the code, I am not getting any live activity of the subscribed user.

Expected behavior

Live activity of subscribed user should be available. As soon as I follow someone, or do direct message than that activity of subscribed user should be available.

Actual behavior

Using current sample code mentioned here, while I do some activity at that time I am not able to see any activity data on my console.Whenever I perform a new activity from user's account, I am not able to see any event on the console.

Steps to reproduce the behavior

Using ngrok as tunnel.

const { Autohook } = require('twitter-autohook');
require('dotenv').config();


(async start => {
  try {
    // console.log(process.env.TWITTER_ACCESS_TOKEN)
    // console.log(process.env.TWITTER_CONSUMER_SECRET)
    const webhook = new Autohook();
    
    // Removes existing webhooks
    // await webhook.removeWebhooks();
    
    // Starts a server and adds a new webhook
    await webhook.startServer();

    webhook.on('event', async event => {

        if (event.direct_message_events) {
            console.log("Heyyy");
          }
        console.log(event)
        console.log('You received an event!');
      });
    
    // webhook.unsubscribe(id)
    
    await webhook.subscribe({oauth_token: process.env.TWITTER_ACCESS_TOKEN, oauth_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET}); 
    
    
  } catch (e) {
    // Display the error and quit
    console.error(e);
    process.exit(1);
  }
})();  

Error at (setWebhook[...] twitter-autohook/index.js:129:13) when using manual URL in start() method

Having completed development on my webhook consuming application I would like to move it to production. I have not read anything to suggest Autohook is only for development so I am trying to use it on my production website. When I specify a URL in webhook.start() I am thrown an error at index line 129 which seems to mean "Too many webhooks", but I remove the webhooks before starting. This only happens when a URL is specified. When it automatically connects to an ngrok URL it works fine.

Expected behavior

Webhooks are removed and new one is registered and subscribed to successfully.

Actual behavior

Thrown a "Too many webhooks" error

Steps to reproduce the behavior

Calling the below function.

  oauth_token,
  oauth_token_secret,
  server
) {
  var Twitter = new Twit({
    consumer_key: process.env.TWITTER_CONSUMER_KEY,
    consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
    access_token: process.env.TWITTER_ACCESS_TOKEN,
    access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
  });

  try {
    const webhook = new Autohook();

    // Removes existing webhooks
    await webhook.removeWebhooks();

    // Listens to incoming activity
    webhook.on("event", event => {
      if (event.hasOwnProperty("direct_message_events")) {
        // User sent a DM to the bot
        handleDirectMessage(Twitter, event, server);
      } else if (event.hasOwnProperty("tweet_create_events")) {
        // User sent a tweet to the bot
        handleTweets(Twitter, event, server);
      } else if (event.hasOwnProperty("follow_events")) {
        // New follower for the bot
        handleFollow(Twitter, event, server);
      } else {
        // Unsupported event
        return 0;
      }
    });

    // Starts a server and adds a new webhook
    await webhook.start("http://www.iotxplorer.io/twitter/webhook");

    // Subscribes to a user's activity
    await webhook.subscribe({ oauth_token, oauth_token_secret });
  } catch (e) {
    console.log(e);
  }
}

request.body in undefined when using autohook with express

When receiving a event, request.body in undefined when using autohook with express

Expected behavior

I followed the previously mentioned instruction on adding autohook to Express server. Everything works with the following log

Webhook created.
Subscribed to ACCOUNT_NAME's activities.
Your app is listening on port 3000

But the request.body should contain event data.

Actual behavior

request.body is undefined

Steps to reproduce the behavior

const express = require('express')
const { Autohook,validateWebhook} = require('twitter-autohook');

const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.all('/webhook/twitter', async (req, res) => {
    if(req.query.crc_token){
        const signature = validateWebhook(req.query.crc_token, {
	    consumer_secret: process.env.TWITTER_CONSUMER_SECRET
	});
       res.json(signature);
    }else{
	res.sendStatus(200);
    	console.log('Received a webhook event:', req.body);
    };
});


const listener = app.listen(port, async () => {
	
    const webhook = new Autohook();
    await webhook.removeWebhooks();
    await webhook.start(process.env.WEBHOOK_BASE_URL+'/webhook/twitter');
    await webhook.subscribe({
	oauth_token: process.env.TWITTER_ACCESS_TOKEN,
	oauth_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
    }); 	
    console.log(`Your app is listening on port ${listener.address().port}`);
});

How to avoid autohook - ngrok pitfalls ?

I've followed the instructions from the Twitter autohook tutorial and this repo's readme, however I still managed to get stuck with tunnelling/ngrok related issues.

Expected behavior

Expected behaviours is seeing twitter event data and no errors

Actual behavior

Instead of event data I get connection reset or failed to start tunnel errors:

node index.js
Getting webhooks…
Removing webhooks…
Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:200:27) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read'
}

node index.js
Getting webhooks…
Removing webhooks…
{
  error_code: 103,
  status_code: 502,
  msg: 'failed to start tunnel',
  details: { err: 'remote gone away' }
}

Steps to reproduce the behavior

  1. npm install twitter-autohook
  2. populate %HOMEPATH%.env.twitter:
TWITTER_CONSUMER_KEY="### my API key"
TWITTER_CONSUMER_SECRET="### my API key secret"
TWITTER_ACCESS_TOKEN="### my Access token"
TWITTER_ACCESS_TOKEN_SECRET="### my Access token secret"
TWITTER_WEBHOOK_ENV="dev" (as defined at https://developer.twitter.com/en/account/environments as Dev environment label)
NGROK_AUTH_TOKEN="### my ngrok auth token"
  1. paste example code to index.js:
const { Autohook } = require('twitter-autohook');

(async start => {
  try {
    const webhook = new Autohook();
    
    // Removes existing webhooks
    await webhook.removeWebhooks();
    
    // Starts a server and adds a new webhook
    await webhook.start();
    
    // Subscribes to your own user's activity
    await webhook.subscribe({oauth_token: process.env.TWITTER_ACCESS_TOKEN, oauth_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET});  
  } catch (e) {
    // Display the error and quit
    console.error(e);
    process.exit(1);
  }
})();  
  1. Run code and observe error

I'm using node v12.14.1 on Windows 10 at the moment.

The project looks great and support outstanding 👏
I feel I'm missing a trick with ngrok here.
Any hints/tips to progress are well apreciated!

Many thanks,
George

AuthenticationError: Client application is not permitted to access this user's webhook subscriptions

I am trying to setup a simple webhook, but I am unable to subscribe. I am using the sample index.js file and have double checked that all the tokens are present and correct in my .env.twitter file.

The output I get is:

Removing webhooks…
Removing https://b57d939c.ngrok.io/webhook…
Registering https://6e55eae0.ngrok.io/webhook as a new webhook…
Webhook created.
{ AuthenticationError: Client application is not permitted to access this user's webhook subscriptions. (HTTP status: 401, Twitter code: 348)
    at tryError (/Users/ethomas/Documents/cocktail-bot/node_modules/twitter-autohook/errors/index.js:53:12)
    at Autohook.subscribe (/Users/ethomas/Documents/cocktail-bot/node_modules/twitter-autohook/index.js:285:19)
    at process._tickCallback (internal/process/next_tick.js:68:7) name: 'AuthenticationError', code: 348 }```

`.start()` => "AuthenticationError: High latency on CRC GET request."

I'm trying to run code inside a Docker Container, on a Raspberry Pi.

Expected behavior

My code that runs on a Raspberry Pi 4 Model B itself, should run Docker container on the Pi

  • ✅ successful logs output
pi@raspberrypi ~/r/k-bot> npm run dev

> [email protected] dev /home/pi/repos/k-bot
> ts-node-dev --no-notify --respawn --transpileOnly ./src

Using ts-node version 8.10.1, typescript version 4.0.0-dev.20200512
Getting webhooks…
Removing webhooks…
Removing https://941591d6.ngrok.io/webhook…
__removed
Registering https://b0138eb2.ngrok.io/webhook as a new webhook…
Webhook created.
__started
Subscribed to thekevinwang's activities.
__subscribed

Actual behavior

When running the same code inside a Docker container, something is throwing an error when I call the Autohook instance's .start() method.

  • ❌ error logs output
pi@raspberrypi ~/r/k-bot> docker run --rm -it my-app

> [email protected] dev /usr/src/app
> ts-node-dev --no-notify --respawn --transpileOnly ./src

Using ts-node version 8.10.1, typescript version 4.0.0-dev.20200514
Getting webhooks…
Removing webhooks…
__removed
Registering https://e6af4d6e.ngrok.io/webhook as a new webhook…
$$$ AuthenticationError: High latency on CRC GET request. Your webhook should respond in less than 3 seconds. (HTTP status: 400, Twitter code: 214)
    at tryError (/usr/src/app/node_modules/twitter-autohook/errors/index.js:53:12)
    at Autohook.setWebhook (/usr/src/app/node_modules/twitter-autohook/index.js:205:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Autohook.start (/usr/src/app/node_modules/twitter-autohook/index.js:270:7) {
  code: 214
}
{ name: 'AuthenticationError', code: 214 }

Steps to reproduce the behavior

Clone Repo

git clone https://github.com/thiskevinwang/k-bot.git
cd k-bot

Need the 4 different twitter keys in a .env

touch .env
  • example ts/js usage / env va names
    // this is TS/JS
    token: process.env.APP_ACCESS_TOKEN,
    token_secret: process.env.APP_ACCESS_TOKEN_SECRET,
    consumer_key: process.env.API_KEY,
    consumer_secret: process.env.API_SECRET_KEY,
    

Build Docker Image

docker build --rm -t my-app .

Run Docker Container

docker run --rm -it my-app

See error 😞

There are some deprecated repos

npm i -g twitter-autohook

npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See There’s Math.random(), and then there’s Math.random() · V8 1 for details.
npm WARN deprecated [email protected]: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142 1
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142 1

[feature request] support cloud functions (or include examples)

This project looks awesome for hitting the ground running use twitter webhooks!

That said it seems best if you plan to have a persistent express instance.

Webhooks are a great use for cloud functions, so it would awesome to see this project support cloud functions and/or provide examples for popular cloud function frameworks (I'm personally most familiar with firebase cloud functions)

"High latency on CRC GET request" with 1.7.1 (on Glitch)

I am running the glitch autohook example, thank you so much for such a nice concise example!

Expected behavior

Using 1.2.1 the example runs perfectly, and I see the following output:

Removing webhooks…
Removing https://myapp.glitch.me/webhook…
Registering https://myapp.glitch.me/webhook as a new webhook…
Webhook created.

However, when I upgrade the package to 1.7.1 I consistently get the following error when trying to create the webhook.

Actual behavior

AuthenticationError: High latency on CRC GET request. Your webhook should respond in less than 3 seconds. (HTTP status: 400, Twitter code: 214)
    at tryError (/rbd/pnpm-volume/fccb6299-90f3-4bdf-b4a6-46d776e1bbf8/node_modules/.registry.npmjs.org/twitter-autohook/1.7.1/node_modules/twitter-autohook/errors/index.js:53:12)
    at Autohook.setWebhook (/rbd/pnpm-volume/fccb6299-90f3-4bdf-b4a6-46d776e1bbf8/node_modules/.registry.npmjs.org/twitter-autohook/1.7.1/node_modules/twitter-autohook/index.js:205:19)
    at processTicksAndRejections (internal/process/task_queues.js:88:5)
    at async Autohook.start (/rbd/pnpm-volume/fccb6299-90f3-4bdf-b4a6-46d776e1bbf8/node_modules/.registry.npmjs.org/twitter-autohook/1.7.1/node_modules/twitter-autohook/index.js:270:7)

Steps to reproduce the behavior

Run the glitch autohook example but change package.json to the following:

{
  "dependencies": {
    "twitter-autohook": "^1.7.1",
    "request": "^2.88.0"
  }
}

Sometimes webhook not responding

After a while running, sometimes the webhook event listener not returning any mention or Direct Message. Is it any quota or limit time to connect for the free user?

Authentication Error

A one-line summary of the issue here.
Want to use the same webhook URL for different clients(different credentials)

getting following errors:

Cannot create webhook: AuthenticationError: Too many resources already created. (HTTP status: 400, Twitter code: 214)

Expected behavior

I am providing different configs while creating the webhook without removing earlier webhooks

Actual behavior

It is removing existing webhooks even I am providing different config while creating the webhook

Code:

const webhook = new Autohook({
token: this.config.TWITTER_ACCESS_TOKEN,
token_secret: this.config.TWITTER_ACCESS_TOKEN_SECRET,
consumer_key: this.config.TWITTER_CONSUMER_KEY,
consumer_secret: this.config.TWITTER_CONSUMER_SECRET,
// ngrok_secret: 'value', // optional
env: this.config.TWITTER_WEBHOOK_ENV,
});
// Removes existing webhooks
await webhook.removeWebhooks();

// Starts a server and adds a new webhook
const startWebhook = await webhook.start(webhookUrl);

// Subscribes to your own user's activity
const subscribeData = await webhook.subscribe(
{
oauth_token: this.config.TWITTER_ACCESS_TOKEN,
oauth_token_secret: this.config.TWITTER_ACCESS_TOKEN_SECRET
}
);

Here the webhook URL is

/webhook/twitter/:campaing_id

where campaign_id will be different for different clients

Steps to reproduce the behavior

use the above code with different credentials.

TypeError: Cannot destructure property `oauth_token` of 'undefined' or 'null'.

I hard coded the credentials in my app.js to perform some test on Windows 10.

Expected behavior

I assume it should run fine, but the webhook.subscribe() method asks for Oauth and i don't have them as the token and consumer_secret are those of my account/app.

I removed the oauth parameters as this :
// Subscribes to a user's activity
await webhook.subscribe();

The Lambda character in the creation of the async anonymous function produced me an error btw

Actual behavior

I have this error
(node:15380) UnhandledPromiseRejectionWarning: TypeError: Cannot destructure property oauth_token of 'undefined' or 'null'.

Meaning that the .subscribe method wants parameters i can't give.

Steps to reproduce the behavior

Hard Code the credentials in app.js

More infos

Full output :

Debugger listening on ws://127.0.0.1:5858/ac1e92bc-564b-411b-8d62-b589b7067b75
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Getting webhooks…
Removing webhooks…
Removing https://fe70d033.ngrok.io/webhook…
Registering https://c164966a.ngrok.io/webhook as a new webhook…
Webhook created.
(node:12588) UnhandledPromiseRejectionWarning: TypeError: Cannot destructure property `oauth_token` of 'undefined' or 'null'.
    at Autohook.subscribe (D:\Coding\NodeJS\Twitter2Streamlabs\node_modules\twitter-autohook\index.js:296:19)
    at D:\Coding\NodeJS\Twitter2Streamlabs\app.js:23:19
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
(node:12588) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:12588) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Full snipet :

const { Autohook } = require('twitter-autohook');

(async asyncaf => {
    const webhook = new Autohook({
        token: xxxxx,
        token_secret: xxxxx,
        consumer_key: xxxxx,
        consumer_secret: xxxxx,
        env: xxxxx,
        port: xxxxx
    });

    // Removes existing webhooks
    await webhook.removeWebhooks();

    // Listens to incoming activity
    webhook.on('event', event => console.log('Something happened:', event));

    // Starts a server and adds a new webhook
    await webhook.start();

    // Subscribes to a user's activity
    await webhook.subscribe();

})();

EDIT :
I also tried using just the { screen_name: "xxx" } in the subscribe method, doesn't work either. Does this library handles self auth ?

Error: spawn UNKNOWN, errno: -4094, code: 'UNKNOWN', syscall: 'spawn'

I have set up the project, gave it all the permissions, created an "Account Activity/APISandbox" for it and entered the .env file properly. I used the example code on here and here. I'm getting this error.

Getting webhooks…
Removing webhooks…
Error: spawn UNKNOWN
at ChildProcess.spawn (node:internal/child_process:412:11)
at spawn (node:child_process:698:9)
at startProcess (D:\Documents\Web Development\Twitter Autohook Example\node_modules\ngrok\process.js:39:16)
at getProcess (D:\Documents\Web Development\Twitter Autohook Example\node_modules\ngrok\process.js:23:20)
at Object.connect (D:\Documents\Web Development\Twitter Autohook Example\node_modules\ngrok\index.js:16:22)
at Autohook.start (D:\Documents\Web Development\Twitter Autohook Example\node_modules\twitter-autohook\index.js:272:31)
at D:\Documents\Web Development\Twitter Autohook Example\index.js:12:19
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
errno: -4094,
code: 'UNKNOWN',
syscall: 'spawn'
}

I've been trying to figure it out but no luck unfortunately.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.