javascript – How do I display validation error in Slack modal

I am building a modal in slack. The idea is to validate the user’s input upon finishing editing an
input element (without submitting and closing the view).

Slack says I can do it by replying to playload with response_action and error object. I’ve been trying to do this but I still can’t display the error. How do I respond to the payload?

I’m completely new at this, so please talk to me as to a newbie.

Here’s my code for validating the error:

app.action("dispatch_1", async ({ action, ack, respond }) => {
  await ack();

  var text = action.value;

  try {
    if (/^(ftp|http|https)://(^ ")+$/.test(text)) {
      await ack();
    } else {
      await ack({
  "response_action": "errors",
  "errors": {
    "dispatch_1": "Sorry, this isn't a valid input"
  } catch (error) {