Slack 应用程序在先前的模式提交后打开新模式不一致,为什么?

dan*_*wig 2 modal-dialog view submit slack-api slack-block-kit

我创建了一个新的免费 Slack 工作区来学习 Slack 机器人应用程序 API。我有一个动作处理程序,它监听全局快捷方式并打开一个输入模式作为响应。还有另一个操作处理程序,它侦听模态输入 Submit callback_id,执行一些工作,然后使用trigger_id打开另一个模态。

app.view('do_thing_b.submit', async (slack) => {

  try {
    await slack.ack()
    console.info(`Received modal submit`)

    // TODO: actual work to save the data

    const view = {
      type: 'modal',
      callback_id: 'do_thing_b.received_submission',
      title: {
        text: 'Thing B Done',
        type: 'plain_text',
      },
      blocks: [
        {
          type: 'section',
          text: {
            text: 'My Plain Text',
            type: 'plain_text',
            emoji: true,
          },
        },
      ],
      close: {
        text: 'Close',
        type: 'plain_text'
      }
    }

    const openViewParams = {
      trigger_id: slack.body.trigger_id,
      view,
    }
    console.log(`Opening Done Modal with open view params ${JSON.stringify(openViewParams)}`)
    const result = await slack.client.views.open(openViewParams)
    console.log(`=============================== Done modal opened?`)

    console.debug(result)
  }
  catch (err) {
    console.error(`Error submitting Thing B modal:`)
    console.error(err)
  }
})
Run Code Online (Sandbox Code Playgroud)

不一致之处在于,仅当针对本地代码以 SocketMode 运行应用程序时,这才按预期工作。

当我部署应用程序并禁用套接字模式时,表单提交永远不会触发显示第二个模式。我可以在日志中看到与本地运行时看到的代码行为相同的证据。调用await slack.client.views.open(openViewParams)成功,结果日志显示来自 slack 的 200 ok 响应。

我为事件和交互设置了与全局快捷方式相同的请求 URL。事实上,我还有一个斜杠命令,可以向用户发布临时帮助屏幕,类似于该/polly命令的作用。该消息包含一个按钮,该按钮也会触发显示该模式表单。单击该按钮在本地打开模式会显示完全相同的行为:当应用程序在套接字模式下本地运行时,它会按预期工作,但在提交后永远不会显示后续模式。

后续问题:

如果不允许这样做,那么 Slack 应用程序应如何响应数据输入提交事件?我还尝试将新视图推送到模式上,但关闭提交确认视图只会滑回到原始表单,我希望它关闭整个模型。我是否需要向用户发送一条临时消息以在提交数据输入后进行跟进?

dan*_*wig 5

事实证明我不需要打开模态,我所需要做的就是更新现有模态。我应该这样做,而不是使用await slack.client.views.opena进行调用:trigger_id

app.view('do_thing_b.submit', async (slack) => {

  try {
    console.info(`Received modal submit`)

    // TODO: actual work to save the data

    const view = {
      type: 'modal',
      callback_id: 'do_thing_b.received_submission',
      title: {
        text: 'Thing B Done',
        type: 'plain_text',
      },
      blocks: [
        {
          type: 'section',
          text: {
            text: 'My Plain Text',
            type: 'plain_text',
            emoji: true,
          },
        },
      ],
      close: {
        text: 'Close',
        type: 'plain_text'
      }
    }

    const result = await slack.ack({
      response_action: 'update', view
    })

  }
  catch (err) {
    console.error(`Error submitting Thing B modal:`)
    console.error(err)
  }
})
Run Code Online (Sandbox Code Playgroud)

我一直缺少的文档是: