我正在尝试建立一个Botpress机器人,从后端获得答复的问题。我正在尝试从backed注入一个动态多项选择题作为对用户的回复。我该怎么做呢?我在Botpress文档或示例中找不到这样做的方法。
发布于 2018-09-18 21:13:12
你能在你的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
}https://stackoverflow.com/questions/51807404
复制相似问题