node.jsexpressslackslack-apislack-bolt

Issue with running node.js app for Slack- invalid signingSecret


I am currently wirting backend for my slack app, that will open small 'Off The Record' chat modal in Slack DM conversation. This app can be opened by command /x, which refers to endpoint (command /x sends a POST request to URL where my app runs- currently on Replit- and app responds with modal view, in which appear chat blocks, etc.)

Here's my app code, in node.js:

const express = require('express');
const bodyParser = require('body-parser');
const { App } = require('@slack/bolt');

const app = express();
const port = 3000;
const SIGNING_SECRET  = 'signing-secret';
const SLACK_APP_TOKEN = 'xoxp-token';
const SLACK_BOT_TOKEN = 'xoxb-token';

// body parser
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

const bolt = new App({
  token: SLACK_BOT_TOKEN,
  appToken: SLACK_APP_TOKEN,
  secret: SIGNING_SECRET
});

// '/x' command that trigger modal view in convo
app.post('/x', async (req, res) => {
  try {
    const triggerId = req.body.trigger_id;
    const view = {
      type: 'modal',
      title: {
        type: 'plain_text',
        text: 'Chat'
      },
      blocks: [
        {
          type: 'section',
          text: {
            type: 'plain_text',
            text: 'This is a chat modal'
          }
        },
        {
          type: 'divider'
        },
        // chat elements
      ],
      close: {
        type: 'plain_text',
        text: 'Close'
      },
      callback_id: 'chat_modal'
    };
    await bolt.views.open({
      trigger_id: triggerId,
      view: view
    });
    res.send('');
  } catch (error) {
    console.error(error);
    res.status(500).send('Internal server error');
  }
});

// Listening for slack events
(async () => {
  await bolt.start(port);
  console.log(`Listening on port ${port}`);
})();

notice that all token variables / signing secret of slack app were changed because of safety

So, im trying to node my index.js file , and:

~/modal$ node index.js 
/home/runner/modal/node_modules/@slack/bolt/dist/App.js:644
            throw new errors_1.AppInitializationError('signingSecret is required to initialize the default receiver. Set signingSecret or use a ' +
            ^

AppInitializationError: signingSecret is required to initialize the default receiver. Set signingSecret or use a custom receiver. You can find your Signing Secret in your Slack App Settings.

The insides of package.json file look like this:

{
  "name": "nodejs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@slack/bolt": "^3.13.0",
    "@slack/events-api": "^3.0.1",
    "@types/node": "^18.0.6",
    "body-parser": "^1.20.2",
    "express": "^4.18.2",
    "http": "^0.0.1-security",
    "node-fetch": "^3.2.6",
  }
}

I've tried everything. Reinstalling to workspace, revoking tokens and adding new one, even reinstalling whole package.json with new packages. Updated whole npm (to the version that Replit allows) and still nothing. And, obviously, i checked milion times for typos in siging secret.


Solution

  • It seems that the key "secret" that you're using does not exist > secret: SIGNING_SECRET

    Instead, you can pass it as "signingSecret"!