node.js - Wit.ai 如何添加动态快速回复

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

这是 Wit.ai 文档中的一句话:https://wit.ai/docs/recipes#categorize-the-user-intent

如何添加动态快速回复

If you want to programmically create Quick Replies, you will need to use a Bot Executes to trigger a function on your side that will create these Quick Replies.

好的,我可以轻松做到!

You can then store them in your context. In the send function on your side, if you have them in the context you will send them with the bot’s answer.

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

最佳答案

我正在使用 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'] 然后您可以格式化并附加这些选项。

关于node.js - Wit.ai 如何添加动态快速回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41519103/

相关文章:

javascript - Jade/PUG JSON 插值

node.js - express-session:文档中未列出 NPM 依赖项?

flash - 如何学习在 facebook 上制作一个社交游戏,比如快乐水族馆,farmville

javascript - 使用带有 Node 的 facebook graph api 获取性别和年龄

facebook-messenger - 如何以编程方式检索 Facebook Messenger 代码(唯一图像 ID)

javascript - 回调不调用

node.js - 在构建管道中使用 yarn 时 Codeship 超时

html - 如何从 (Messenger) 预览中删除脚本代码?

ios - iOS5 上的 Facebook SDK 导致崩溃

node.js - nodeJs 中的 Facebook Messenger 位置