plsdev89
plsdev89

Reputation: 732

Slack bolt ack() with errors

I am trying to implement email validation in Slack modal. documentation is here. https://slack.dev/bolt-js/concepts#acknowledge If I enter valid email, it works well. And If I enter invalid email, it occurs error. enter image description here

I believe that it occurs because of ack() with errors. So, I want to ask. What is the meaning of "name": "email_address", in below code?

// Regex to determine if this is a valid email
let isEmail = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/
// This uses a constraint object to listen for dialog submissions with a callback_id of ticket_submit 
app.action({ callback_id: 'ticket_submit' }, async ({ action, ack }) => {
  // it’s a valid email, accept the submission
  if (isEmail.test(action.submission.email)) {
    await ack();
  } else {
    // if it isn’t a valid email, acknowledge with an error
    await ack({
      errors: [{
        "name": "email_address",
        "error": "Sorry, this isn’t a valid email"
      }]
    });
  }
});

Upvotes: 0

Views: 2554

Answers (1)

plsdev89
plsdev89

Reputation: 732

I found the solution. block_1 is block_id.

await ack({
  response_action: 'errors',
  errors: {
    block_1: 'Sorry, this isn’t a valid email',
  },
});

Upvotes: 1

Related Questions