简体   繁体   English

用wit.ai创建结构化消息

[英]create Structured Message with wit.ai

How can I take advantage of the navigation templates from the facebook messenger with wit.ai? 如何利用facebook. Messenger的facebook信使导航模板?

At wit ai I created a fully functional bot with the Structured Messages. 在机智,我用结构化消息创建了一个功能齐全的机器人。

The issue that I'm experiencing is that when I connected the wit ai bot to facebook the structured messages don't disappear. 我遇到的问题是,当我将智能机器人连接到Facebook时,结构化消息不会消失。

Is there any way that I can fix that? 有什么方法可以解决这个问题吗?

you will have to send the elements of structured message to facebook when you send message. 发送消息时,您必须将结构化消息的元素发送到Facebook。 Wit.ai will set the structured elements in response objects, its your responsibility to pass it on to facebook send api. Wit.ai将在响应对象中设置结构化元素,您有责任将其传递给facebook send api。

for example for quick replies wit.ai send it as response['quickreplies'] you have to access it and send to facebook as an array with key quick_replies and extra elements 例如,快速回复wit.ai发送它作为响应['quickreplies']你必须访问它并发送到Facebook作为一个数组与关键的quick_replies和额外的元素

  def send_text_fb_message_with_quickreplies(recipientId, msg, quickreplies)
    qr = []
    quickreplies.each do |i|
    reply_hash = {}
    reply_hash['content_type'] = 'text'
    reply_hash['title'] = i
    reply_hash['payload'] = i
    qr.push(reply_hash)
  end

  Bot.deliver(
    recipient: {
      id: recipientId
    },
    message: {
      text: msg,
      quick_replies: qr
    }
  )
end

send_text_fb_message_with_quickreplies(request['sender_id'], response['text'], response['quickreplies'])

with something similar code you can convert quickreplies from wit.ai to facebook compatible quickreplies 使用类似的代码,您可以将quickreplies从wit.ai转换为facebook兼容的quickreplies

I am adding a little customized answer based on library you are using: 我正在根据您使用的库添加一个小的自定义答案:

In the library you are using change https://github.com/hunkim/Wit-Facebook/blob/master/facebook.js file and is function fbMessage 在库中,您使用的是更改https://github.com/hunkim/Wit-Facebook/blob/master/facebook.js文件,并且是函数fbMessage

Check if msg.quickreplies is present, if it is present do processing and make it facebook compatible format like i did in ruby code above. 检查是否存在msg.quickreplies,如果它存在则进行处理并使其与facebook兼容格式,就像我在上面的ruby代码中所做的那样。

post that change 张贴改变

 message: { 
text: msg, 
}, 

to

 message: {
 text: msg, 
 quick_replies: object_you_created 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM