EDIT: Forgot to mention, yes the app has been whitelisted
I have been reading through the various similar threads here but cannot find a solution for my case. I have configured an AWS lambda with an API Gateway which responds in under 1s according to Postman. My Node code is below.
I followed a really good guide from Frederik Willaert
https://www.linkedin.com/pulse/handling-twitter-webhooks-aws-lambda-step-functions-frederik-willaert
module.exports.webhookGET = (event, context, callback) => {
const appConsumerSecret = 'appConsumerSecret';
const crcToken = event.query.crc_token;
if (!crcToken) {
return callback(null, { statusCode: 400 });
}
try {
const crcTokenHash = computeHmac('sha256', appConsumerSecret, crcToken);
// wait for promise to resolve before sending response
crcTokenHash.then((finalCRCTokenHash) => {
const response = {
statusCode: 200,
body: JSON.stringify({ response_token: "sha256=" + finalCRCTokenHash })
};
callback(null, response);
})
} catch (error) {
return callback(null, { statusCode: 400 });
}
}
function computeHmac(algorithm, key, payload) {
const hmac = crypto.createHmac(algorithm, key);
return new Promise((resolve, reject) => {
hmac.on('readable', () => {
const data = hmac.read();
if (!data) return reject("No data");
return resolve((data).toString('base64'));
});
hmac.write(payload);
hmac.end();
})
}
If I open the API endpoint in my browser and pass a query string, e.g.
https://xxxxxxxxxxxxxxxxx.amazonaws.com/dev/webhook/?crc_token=test
I get a 200 response:
{
statusCode: 200,
body: "{"response_token":"sha256=b/ntLgVhZchtBCeefIB0ym7lB/Q9FI5HnMXJk4G8ZAU="}"
}
When POSTing
the callback URL I am doing so in the following format using Postman => Import => Paste raw text
Then I modify the Authorization to use OAuth 1.0 and add the keys
curl -X POST \
https://api.twitter.com/1.1/account_activity/webhooks.json \
-H 'content-type: application/x-www-form-urlencoded' \
-d url=https://xxxxxxxxxxxxxxxxxxxx.amazonaws.com/dev/webhook
Anyone have any idea what I am doing wrong? Any help would be much appreciated!