xdevplatform / autohook Goto Github PK
View Code? Open in Web Editor NEWAutomatically setup and serve webhooks for the Twitter Account Activity API
License: MIT License
Automatically setup and serve webhooks for the Twitter Account Activity API
License: MIT License
黃河樺
Getting a 104 error when trying to run the out of the box example.
$ node index.js
Getting webhooks…
Removing webhooks…
Removing https//.../webhook
Registering https://.../webhook as a new webhook…
Webhook created.
Subscribed to ... activities.
$ 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'
}
}
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.
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.
$ 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
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);
}
})();
Autohook relies on the request package, which is now deprecated. Find an alternative, and replace requests with that alternative.
Receiving 215 'Bad Authentication data'. Is this up to date with Twitter's AAA Api ref?
Expecting Autohook to generate the webhook
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)
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
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?
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)
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.
It should work perfectly after the server is up even after several hours and should error out if something failed
Autohook get subscribed and after a few hours it doesn't receive any response
Configure autohook and deploy to a server. After few hours it doesn't accept webhook requests.
My server is configured to automatically restart if the application errors out. Sometimes, I see this error coming up
The codebase is opensource. So you can also view my implementation here
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?
When using it as a node module, it throws because it couldn't find the qs
dependency.
Not to throw
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
});
One line summary of the issue here.
Cannot start with autohook -rs
I stored my credentials in ~/.env.twitter, and ran autohook -rs
but I am not able to start due to following errors:
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.
autohook -rs
I have also tried to pass credentials by command line but the same error appears
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
New feature request
another util function to verify x-twitter-webhooks-signature header
none
none
I'm not able to successfully subscribe to my webhook using autohook.
I would expect autohook to automatically define the webhook URL for me and subscribe successfully.
It throws the error Cannot subscribe to [my username's] activities: Webhook URL must be defined to create subscriptions. (Twitter code: 170).
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.
After running the app for several hours it stops receiving events.
Can't make the example script work with my provided oauth token and secret.
It should subscribe.
..but does not.
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."
(node:20122) UnhandledPromiseRejectionWarning: AuthenticationError: Client application is not permitted to access this user's webhook subscriptions. (HTTP status: 401, Twitter code: 348)
The example code from the README should work
It fails
Create .env.twitter
file in your home directory
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();
Run the app using node index.js
The apps fails.
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.
When webhook.start(customURL)
is called the server won't start.
When webhook.start(customURL)
is called the server should be started with the startServer()
function.
The startServer()
function is only executed when no url is passed to webhook.start()
Call webhook.start()
with a custom URL.
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.
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.
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.
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);
}
})();
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.
Webhooks are removed and new one is registered and subscribed to successfully.
Thrown a "Too many webhooks" error
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);
}
}
When receiving a event, request.body in undefined when using autohook with express
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.
request.body is undefined
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}`);
});
Add eslint to check and enforce code style (thanks @sachushaji for the suggestion).
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 behaviours is seeing twitter event data and no errors
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' }
}
npm install twitter-autohook
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"
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);
}
})();
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
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 }```
I'm trying to run code inside a Docker Container, on a Raspberry Pi.
My code that runs on a Raspberry Pi 4 Model B itself, should run Docker container on the Pi
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
When running the same code inside a Docker container, something is throwing an error when I call the Autohook instance's .start()
method.
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 }
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
// 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 😞
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
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)
Is there a way to use autohook without ngrok? I'm deploying it on a VPS.
I am running the glitch autohook example, thank you so much for such a nice concise example!
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.
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)
Run the glitch autohook example but change package.json
to the following:
{
"dependencies": {
"twitter-autohook": "^1.7.1",
"request": "^2.88.0"
}
}
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?
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)
I am providing different configs while creating the webhook without removing earlier webhooks
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
use the above code with different credentials.
I hard coded the credentials in my app.js to perform some test on Windows 10.
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
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.
Hard Code the credentials in app.js
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 ?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.