【发布时间】:2019-01-19 07:16:08
【问题描述】:
我正在尝试构建一个 Botpress 机器人,它可以从后端获取问题的回复。我正在尝试从支持中注入一个动态的多项选择问题作为对用户的回复。我怎样才能做到这一点?我在 Botpress 文档或示例中找不到方法。
【问题讨论】:
我正在尝试构建一个 Botpress 机器人,它可以从后端获取问题的回复。我正在尝试从支持中注入一个动态的多项选择问题作为对用户的回复。我怎样才能做到这一点?我在 Botpress 文档或示例中找不到方法。
【问题讨论】:
你能在你的 src/actions.js 文件中试试这个吗?我正在使用单选选项来响应用户。
getDataFromAPI: async (state, event) => {
const endPoint = 'https://api.github.com/repos'
try {
let response = await instance.get(`${endPoint}`)
console.log(response.data);
await event.reply('#builtin_single-choice', JSON.parse(response.data))
} catch (exception) {
console.log(exception);
await event.reply('#builtin_text', { text: `Failed to fetch data for this repo` })
}
}
API 调用的响应应为 JSON 格式,格式如下
{
"text": "Offerings",
"choices": [
{
"title": "Standard",
"value": "standard"
},
{
"title": "Custom",
"value": "custom"
},
{
"title": "Enterprise",
"value": "enterprise"
}
],
"typing": true
}
【讨论】: