This is my first time creating a Slack app, and I have followed the Events API docs to set up my Express app. I am using ngrok to develop locally.
const express = require('express');
const bodyParser = require('body-parser');
const { createEventAdapter } = require('@slack/events-api');
const slackSigningSecret = process.env.SLACK_SIGNING_SECRET;
const PORT = process.env.PORT || 4390;
const app = express();
const slackEvents = createEventAdapter(slackSigningSecret);
app.use('/slack/events', slackEvents.requestListener());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
slackEvents.on('app_mention', async (event) => {
try {
console.log("I got a mention in this channel", event.channel);
} catch (e) {
}
});
// Starts server
app.listen(PORT, function() {
console.log('Bot is listening on port ' + PORT);
});
What I want to do is listen for the app_mention event, but when I run:
SLACK_SIGNING_SECRET=<signing secret> SLACK_BOT_TOKEN=<slack bot token> node app.js
the command runs fine on and returns Bot is listening on port 4390.
However I notice 2 problems:
/slack/events), I get this error:Error: Slack request signing verification failed
...
code: 'SLACKHTTPHANDLER_REQUEST_SIGNATURE_VERIFICATION_FAILURE'
I'm not sure if the two issues are related. My signing secret seems to work since my Request URL has been verified. I have also subscribed to the app_mention event. Is there something I am missing? Let me know if I should add more information. Thanks in advance!
x in one of the [ ])x in each of the [ ])Select all that apply:
@slack/web-api@slack/events-api@slack/interactive-messages@slack/rtm-api@slack/webhooks@slack/oauthpackage version:
"@slack/events-api": "^2.3.4"
"body-parser": "^1.19.0"
"express": "^4.17.1"
node version: v12.13.0
OS version(s): OSX Catalina 10.15.6
Looks like I just needed to add the slack app to a channel 馃槄
Hey @chauluckynguyen, glad you were able to solve the issue!
I just finished recreating your issue with your source code. Thanks for providing it! Everything worked on my end and I was able to suggest you double-check your bot is invited to your channel. 馃槅
Glad to hear you're up and running!