Bolt-js: How to respond to Modal's view_submission events

Created on 21 Jul 2020  路  4Comments  路  Source: slackapi/bolt-js

Description

The documentation mentions in several places (1, 2, 3) that when a modal is submitted, you get a view_submission payload. But I can't find anything on how you get the payload - it doesn't seem to be an app.event() or app.action() based one. I can't find any example code either.

I've tried tons of things like:

app.event('view_submission', async (everything: any) => {
    everything.ack();
    console.log("I'm here");
});

But the callback never triggers. I always get a

[ERROR]  bolt-app An incoming event was not acknowledged within 3 seconds. Ensure that the ack() argument is called in a listener.

Stranger still, the Events API doesn't contain anything about view_submission either, but the Error confirms it is an event.

So my question is - How are you supposed to respond to a Modal submit using Bolt?

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

  • [ ] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [ ] 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.
question

Most helpful comment

The part is callback_id in your modal view. If you put veiw_b as callback_id in your view, app.view("view_b", async should work for you.

All 4 comments

You can use app.view instead of app.event. https://slack.dev/bolt-js/concepts#view_submissions

Thanks @seratch. I've changed my code to look like this:

app.view(/e/g, async (everything: any) => {
  everything.ack();
  console.log("I'm here");
});

(where the regex pattern should match anything 馃)

But still no luck. I've also tried app.view('view_b' ... like the documentation says, but it doesn't get triggered either. Do you have any other suggestions?

The part is callback_id in your modal view. If you put veiw_b as callback_id in your view, app.view("view_b", async should work for you.

THANK YOU!!! The callback_id was the missing piece. For future readers, it's needed in the first level of the view JSON, i.e. your JSON looks like this:

view: {
  "title": ...,
  "submit": ...,
  "blocks": [...],
  "type": "modal",
  "callback_id": "a_unique_id",
}

Then you can respond to it with:

app.view('a_unique_id', async (everything) => {
  everything.ack();
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnsonyick picture johnsonyick  路  4Comments

st3fan picture st3fan  路  3Comments

simonsayscode picture simonsayscode  路  3Comments

dschinkel picture dschinkel  路  4Comments

jacklein picture jacklein  路  4Comments