Node-slack-sdk: Signing Secret Issue

Created on 9 Nov 2020  路  2Comments  路  Source: slackapi/node-slack-sdk

Description

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:

  1. When I head to my workspace and mention my app, I do not see any console logs to validate that the event listener is working.
  2. When I go to my Request Url (ending in /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!

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [x] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Packages:

Select all that apply:

  • [ ] @slack/web-api
  • [x] @slack/events-api
  • [ ] @slack/interactive-messages
  • [ ] @slack/rtm-api
  • [ ] @slack/webhooks
  • [ ] @slack/oauth
  • [ ] I don't know

Reproducible in:

package 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

question

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bmajz picture bmajz  路  14Comments

danielravina picture danielravina  路  16Comments

amkoehler picture amkoehler  路  13Comments

thepont picture thepont  路  17Comments

aoberoi picture aoberoi  路  10Comments