I am trying to implement a task creation workflow using slack modal. The task creation workflow sometimes takes more than 3 seconds to execute and come up with the result. So, based on the documentation, I called await ack() to acknowledge at the beginning of the workflow but ack() is not sending the acknowledgement response at the beginning of the workflow. Instead, it is waiting for the workflow to complete and is then sending the acknowledgement response.
To test this, I replaced the workflow with a sleep statement and called the ack() function with an await statement before the sleep. This code fails to acknowledge within 3 seconds. So, the slack app shows an error message enter image description here
// handle create task modal submission
app.view('create-task', async ({ ack, ...options }) => {
await ack()
logger.debug(`Sleeping ${new Date().getTime()}`);
await new Promise((r) => setTimeout(r, 5000));
logger.debug(`Woke up ${new Date().getTime()}`);
});
On the other hand, if I reduce the sleep interval to 2 seconds, the above code works and I get no error. This indicates that the acknowledgement is happening after the workflow completes (callback function is fully executed). So, how can I acknowledge the request before entering the sleep (task creation workflow)?
Do you use AwsLambdaReceiver
or processBeforeResponse: true
option for running your code on FaaS? If so, this is an intentional behavior of bolt-js framework. Refer to https://github.com/slackapi/bolt-js/issues/1119 for its context.
As workarounds, I would suggest going with either of the following: