【问题标题】:Wit.ai How to add dynamic Quick RepliesWit.ai 如何添加动态快速回复
【发布时间】:2017-01-07 07:41:29
【问题描述】:

这是来自 Wit.ai 文档的句子:https://wit.ai/docs/recipes#categorize-the-user-intent

如何添加动态快速回复

如果您想以编程方式创建快速回复,您需要 使用 Bot Executes 触发您身边的功能,该功能将创建 这些快速回复。

好的,我可以轻松做到!

然后您可以将它们存储在您的上下文中。在里面 发送功能在您身边,如果您在上下文中有它们,您将 将机器人的答案发送给他们。

谁能帮我翻译这最后一句话,因为我不明白我的裹尸布是做什么的。我想用 Wit.ai 在我的 Node.js 机器人中添加动态快速回复
谢谢

【问题讨论】:

    标签: node.js facebook facebook-messenger wit.ai facebook-messenger-bot


    【解决方案1】:

    我正在为我的机器人使用 Wit.ai for Facebook Messenger 做类似的事情。

    在我的操作中,我将动态快速回复存储在上下文中:

    myAction({ context, text, entities }) {
      context.quick_replies = [
        { 
          title: 'Option A',
          content_type: 'text',
          payload: 'empty'
        },
        { 
          title: 'Option B',
          content_type: 'text',
          payload: 'empty'
        },
      ]
    }
    

    然后在send() 中,我会在我的短信中附上任何快速回复:

    send(req, res) {
      await textMessage(messenger_id, res.text, req.context.quick_replies)
    }
    

    textMessage() 看起来像这样:

    export async function textMessage(recipientId, text, quick_replies = null) {
      const messageData = {
        recipient: { id: recipientId },
        message: {
          quick_replies: quick_replies,
          text: text
        }
      }
    
      await request({
        url: 'https://graph.facebook.com/v2.6/me/messages',
        qs: { access_token: FB_PAGE_TOKEN },
        method: 'POST',
        json: messageData
      })
    }
    

    基本上,我自己创建并附上快速回复。

    如果您在 Wit.ai 中有静态快速回复,那么您将在 send() 中以以下格式获取它们:res.quickreplies = ['Yes', 'No'],然后您可以格式化并附加这些选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      相关资源
      最近更新 更多