bolt-js: Slack bolt slack_webapi_platform_error `trigger_id` expired

Description

Hello folks, i am using slack@bolt 2.0.1 with “express”: “^4.17.1” in a slack app which i built 1 year ago.

In my local slack bot i am having this issue with instantiating a command,

app.command(global.config.slack.commandConfig.createTicket, createTicketCommand(app));

export const createTicketCommand = (app: App): Middleware<SlackCommandMiddlewareArgs> => async ({
  ack,
  body,
  context,
}): Promise<void> => {
  // Acknowledge the command request
  await ack();

 app.client.views.open({
      token: context.botToken,
      trigger_id: body.trigger_id,
      view: {
        type: 'modal',
        title: {
          type: 'plain_text',
          text: 'Workplace check-in',
        },
        close: {
          type: 'plain_text',
          text: 'Cancel',
        },
        blocks: [
          {
            type: 'section',
            text: {
              type: 'plain_text',
              text: ':man-biking: Now loading...',
            },
          },
        ],
      },
    });

 
  } catch (error) {
   console.log(error);
  }
};

And i get this error, it looks to me there is something wrong with trigger_id.

{“level”:1,“time”:“2021-04-23T07:44:39.725Z”,“msg”:{“code”:“slack_webapi_platform_error”,“data”:{“ok”:false,“error”:“invalid_arguments”,“response_metadata”:{“messages”:[“[ERROR] trigger_id expired [json-pointer:/trigger_id]”],“scopes”:[“channels:history”,“chat:write”,“commands”,“files:read”,“groups:history”,“im:history”,“incoming-webhook”,“mpim:history”,“users:read”]}},“name”:“Error”,“message”:“An API error occurred: invalid_arguments”,“stack”:“Error: An API error occurred: invalid_arguments\n at Object.platformErrorFromResult (/usr/src/app/node_modules/@slack/web-api/src/errors.ts:94:5)\n at WebClient.apiCall (/usr/src/app/node_modules/@slack/web-api/src/WebClient.ts:188:13)\n at processTicksAndRejections (internal/process/task_queues.js:93:5)”}}

Any help, any suggestion what it might be?

Does reinstalling the app and refreshing the new slack bot token and signin secrets would help?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

bolt-js v3 does not have any breaking changes but if you have some reason to keep using v2, you can have the following global middleware to print received requests.

// you can remove this if statement if you want to always enable this
if (process.env.SLACK_REQUEST_LOG_ENABLED === "1") {
  app.use(async (args) => {
    const copiedArgs = JSON.parse(JSON.stringify(args));
    copiedArgs.context.botToken = 'xoxb-***';
    if (copiedArgs.context.userToken) {
      copiedArgs.context.userToken = 'xoxp-***';
    }
    copiedArgs.client = {};
    copiedArgs.logger = {};
    args.logger.debug(
      "Dumping request data for debugging...\n\n" +
      JSON.stringify(copiedArgs, null, 2) +
      "\n"
    );
    const result = await args.next();
    args.logger.debug("next() call completed");
    return result;
  });
}