Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal data submission takes too long to acknowledge when processBeforeResponse is true #1374

Closed
4 of 10 tasks
AmanKishore opened this issue Mar 17, 2022 · 8 comments
Closed
4 of 10 tasks
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project

Comments

@AmanKishore
Copy link

Description

I am trying to close the modal and update my database. The code is all running but the modal isn't closing since the acknowledge isn't being sent fast enough.

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

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

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

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

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version: 3.9.0

node version: v14.17.6

OS version(s): macOS Monterey 12.2.1

Steps to reproduce:

  1. Open a modal
  2. Handle Submit
  3. Send ack() and then run code that takes longer than 3s

Expected result:

Modal to close

Actual result:

Modal stays open

Attachments:

app.view('adhoc-modal-identifier', async ({ ack, respond, body, view, client, context, logger }) => {
  // Acknowledge the view_submission request
  await ack({response_action: 'clear'});
  await functions.handleModal(body, view, client, context, logger);
});
@seratch seratch added question M-T: User needs support to use the project needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info labels Mar 17, 2022
@seratch
Copy link
Member

seratch commented Mar 17, 2022

Hi @AmanKishore, thanks for writing in!

Do you use either AwsLambdaReceiver or processBeforeResponse: true option? If that's the case, this is an intentional behavior for avoiding misbehaviors on FaaS. Refer to #361 and the linked URLs from the issue for learning more context.

If you don't use any of the above settings, sharing a bit more details (such as complete app code) for reproducing your situation would be helpful for others here.

I hope this helps!

@AmanKishore
Copy link
Author

I see I am using ExpressReceiver and processBeforeResponse: true

const expressReceiver = new ExpressReceiver({
  logLevel: LogLevel.DEBUG,
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  clientId: process.env.SLACK_CLIENT_ID,
  clientSecret: process.env.SLACK_CLIENT_SECRET,
  scopes: ["channels:history","channels:join","channels:manage","channels:read","chat:write","dnd:read","groups:history","groups:read","groups:write","im:history","im:read","im:write","links:read","mpim:history","mpim:read","mpim:write","pins:read","reactions:read","usergroups:read","users.profile:read","users:read","users:read.email"],
  stateSecret: 'my-secret',
  installationStore: store.installationStore,
  installerOptions: {
    directInstall: true,
  },
  processBeforeResponse: true
});

const app = new App({
  receiver: expressReceiver,
});
const serverlessExpress = require("@vendia/serverless-express");
module.exports.oauthHandler = serverlessExpress({
  app: expressReceiver.app,
});

@AmanKishore
Copy link
Author

Is there a way to ack() and then respond() so that I can update the message twice.

Like this:

app.action('user_choice', async ({ action, ack, respond }) => {
  await ack(UPDATE ORIGINAL);
// DO SOMETHING THAT TAKE TIME
  await respond(UPDATE ORIGINAL);
});

@AmanKishore
Copy link
Author

@seratch Is there documentation for ack() and respond() with bolt?
Can't seem to find it anywhere

@seratch
Copy link
Member

seratch commented Mar 17, 2022

@AmanKishore

I see I am using ExpressReceiver and processBeforeResponse: true

Thanks for sharing the detail. Thus, as I mentioned above, this is an expected behavior. If your code has some time-consuming parts, consider moving them to asynchronous execution such as a different AWS Lambda execution.

Is there documentation for ack() and respond() with bolt?

Here is the reference page for those: https://slack.dev/bolt-js/reference#listener-function-arguments However, the page provides the overview of the available arguments. The details on the topic that you asked here are not mentioned there.

Also, searching https://slack.dev/bolt-js by keyword such as ack(, respond( may be helpful too.

Is there a way to ack() and then respond() so that I can update the message twice.

No, there isn't. Please stop using ack() for your use case. Also, updating a message by respond() requires a user action such as button click in the blocks in a message posted by previous respond() call.

For your use case, I would suggest using say() first plus keeping the returned response.message.ts, and then performing client.chat.update(...) with the ts.

I think that I've provided answers to all your questions here. Thanks again for asking the question! Is everything clear now? If so, would you mind closing this issue?

@AmanKishore
Copy link
Author

What does this mean? Any examples?

such as a different AWS Lambda execution.

One more question, apologies if I missed it, is it possible to send an ack() and then do database calls (that take more than 3 seconds) within the same function? Or do you recommend implementing a queue?

@seratch
Copy link
Member

seratch commented Mar 17, 2022

@AmanKishore

What does this mean? Any examples?

This means invoking a new Lambda function from the internet-facing Lambda function that runs your bolt-js code. Here is a simple example: #914 (comment)

One more question, apologies if I missed it, is it possible to send an ack() and then do database calls (that take more than 3 seconds) within the same function?

As already mentioned above, as long as you use processBeforeReponse: true option, no way to run any time-consuming code such as slow database quires. If you don't enable the option and run the app in a non-Function-as-a-Service (non-FaaS) environment (EC2, container services, Heroku, etc.), you can do that without any issues.

Or do you recommend implementing a queue?

Yes, I do if you have a certain reason to use FaaS. You can have a queue between your internet-facing Lambda and asynchronous Lambda. As I suggested above, a simpler way would be directly calling lambda.invoke AWS API call from the internet-facing one (refer to #914 (comment)).

@seratch seratch changed the title Modal Takes too long to acknowledge Modal data submission Takes too long to acknowledge when processBeforeResponse Mar 18, 2022
@seratch seratch changed the title Modal data submission Takes too long to acknowledge when processBeforeResponse Modal data submission Takes too long to acknowledge when processBeforeResponse is true Mar 18, 2022
@AmanKishore
Copy link
Author

AmanKishore commented Mar 18, 2022

Decided to switch to Heroku! Much better.
Here's an example for future people!

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  clientId: process.env.SLACK_CLIENT_ID,
  clientSecret: process.env.SLACK_CLIENT_SECRET,
  scopes: ['chat:write', 'commands'],,
  stateSecret: 'my-secret',
  installationStore: new FileInstallationStore(),
  installerOptions: {
    directInstall: true,
  }
});

(async () => {
  // Start your app
  await app.start(process.env.PORT || 3000);
  console.log('⚡️ Bolt app is running!');
})();

@seratch seratch changed the title Modal data submission Takes too long to acknowledge when processBeforeResponse is true Modal data submission takes too long to acknowledge when processBeforeResponse is true Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

2 participants