【问题标题】:Use "response_action" to respond to view_submission when using botkit使用botkit时使用“response_action”响应view_submission
【发布时间】:2020-08-12 17:39:19
【问题描述】:

我有一个简单的模式,使用以下方式推送视图:

           const result = await bot.api.views.open({
                trigger_id: message.trigger_id,
                view: {
                    "type": "modal",
                    "submit": {
                        "type": "plain_text",
                        "text": "Submit",
                        "emoji": true
                    },
                    "title": {
                        "type": "plain_text",
                        "text": "Request",
                        "emoji": true
                    },
                    "blocks": [
                        {
                            "type": "input",
                            "block_id" : "accblock",
                            "element": {
                                "type": "plain_text_input",
                                "action_id": "account_name",
                                "multiline": false
                            },
                            "label": {
                                "type": "plain_text",
                                "text": "Account Name",
                                "emoji": true
                            }
                        }
                    ]
                }
            });

如果在view_submission 上输入了某个值,我需要将错误添加到块中。我知道我应该使用以下 JSON 发送响应:

       {
          response_action: 'errors',
          errors: {
            "ticket-desc": 'I will never accept a value, you are doomed!'
          }
        }

但是,我该如何发送呢?我试过使用bot.httpBody()。这个 JSON 是否需要作为视图对象包含在内?任何帮助表示赞赏。

【问题讨论】:

  • 非常感谢任何帮助
  • 我如何用 Java 发送它?

标签: node.js slack-api botkit


【解决方案1】:

bot.httpBody()是你需要的方法。

确保errors 字典的键与您为其提供错误消息的元素的block_id 匹配。

在您的情况下,这将起作用:

bot.httpBody({
  response_action: 'errors',
  errors: {
    accblock: 'Your account name is invalid or in use.'
  }
})

您不需要JSON.stringify 响应消息,如果您这样做,该过程确实会失败。

【讨论】:

  • 谢谢,这是块 ID
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-31
相关资源
最近更新 更多