Bolt-js: Listen to a modal view submission in slack/bolt?

Created on 5 May 2020  路  4Comments  路  Source: slackapi/bolt-js

Description

Hello, currently i am using "@slack/bolt": "^2.0.1" package to create a bot for Slack. I want to add some interaction to user, when he types a command a dialog modal will open and he has to fill some data and submit those data.

Here is the command invocation and sending of a view modal..

app.command('/test-zenbot', async ({ ack, body, context }) => {
  // Acknowledge the command request
  await ack();

  try {
    const result = await app.client.views.open({
      token: context.botToken,
      // Pass a valid trigger_id within 3 seconds of receiving it
      trigger_id: body.trigger_id,
      // View payload
      view: createTicketModal()  
    });
    console.log(result);
  }
  catch (error) {
    console.error(error);
  }
});

Now, my question is, how should i listen to form/view/modal data submission?

All the time i am getting this error on modal the moment i click the submit:

We had some trouble connecting. Try again?

I am trying to listen to modal/form submission through the bolt view method

app.view('bot_create_ticket', async ({ ack, body, view, context }) => {

await ack();
});

But, to no avail. Any help on this?

question

All 4 comments

I found out that in order for app.view to work i have to set the request URL in Interactivity and Shortcuts in Slack App Management UI to: /slack/events instead of /slack/actions as was previously.

Now, it works. The only thing i wonder is after the user submits the view/modal/form how can i check in app.view() which channel id he sent the view/modal/form. In app.messages() we have the say() function where you write back to the channel, but in app.view() i cannot find a way to get the channel informations.

Hey @erkand-imeri,

I believe you have access to the channel in your app.command handler. I would include it in the views.open call you make as the private_metadata field. Then, on view.submission, you should have access to that private_metadata field.

Let me know if you have any additional questions related to this!

Yeah, the private_metadata seems to solve this issue.

Thanks!!!

I came here for this exact same issue. For me, the problem was that I hadn't added my request url to the Interactivity & Shortcuts page.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnsonyick picture johnsonyick  路  4Comments

st3fan picture st3fan  路  3Comments

selfcontained picture selfcontained  路  4Comments

simonsayscode picture simonsayscode  路  3Comments

jamesfmac picture jamesfmac  路  5Comments