使用botkit时使用"response_action"响应view_submission
Use "response_action" to respond to view_submission when using botkit
我有一个简单的模式,视图推送使用:
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 是否需要作为视图对象包含在内?感谢任何帮助。
bot.httpBody()
就是你需要的方法。
确保 errors
字典的键与您为其提供错误消息的元素的 block_id
匹配。
在您的情况下,这将起作用:
bot.httpBody({
response_action: 'errors',
errors: {
accblock: 'Your account name is invalid or in use.'
}
})
您不需要 JSON.stringify
响应消息,如果您这样做,该过程确实会失败。
我有一个简单的模式,视图推送使用:
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 是否需要作为视图对象包含在内?感谢任何帮助。
bot.httpBody()
就是你需要的方法。
确保 errors
字典的键与您为其提供错误消息的元素的 block_id
匹配。
在您的情况下,这将起作用:
bot.httpBody({
response_action: 'errors',
errors: {
accblock: 'Your account name is invalid or in use.'
}
})
您不需要 JSON.stringify
响应消息,如果您这样做,该过程确实会失败。