【问题标题】:Botpress : How to reply with a dynamic multiple choiceBotpress:如何使用动态多项选择进行回复
【发布时间】:2019-01-19 07:16:08
【问题描述】:

我正在尝试构建一个 Botpress 机器人,它可以从后端获取问题的回复。我正在尝试从支持中注入一个动态的多项选择问题作为对用户的回复。我怎样才能做到这一点?我在 Botpress 文档或示例中找不到方法。

【问题讨论】:

    标签: bots chatbot


    【解决方案1】:

    你能在你的 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-20
      • 1970-01-01
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      • 2014-12-23
      相关资源
      最近更新 更多