如何在wit.ai中使用facebook messenger中的导航模板?
在wit ai,我用结构化消息创建了一个全功能的机器人。
我遇到的问题是,当我将wit ai机器人连接到facebook时,结构化消息并没有消失。
我有什么办法可以解决这个问题吗?
发布于 2016-10-11 18:03:45
当您发送消息时,您必须将结构化消息的元素发送到facebook。Wit.ai将在response对象中设置结构化元素,由您负责将其传递给facebook send api。
例如,对于快速回复,wit.ai将其作为响应‘快速回复’发送,您必须访问它并将其作为包含关键quick_replies和额外元素的数组发送到facebook
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'])
用一些类似的代码,你可以将快速回复从wit.ai转换为facebook兼容的快速回复
发布于 2016-10-20 17:28:44
我正在根据你正在使用的库添加一个小的自定义答案:
在库中,您使用的是fbMessage函数的change https://github.com/hunkim/Wit-Facebook/blob/master/facebook.js文件
检查msg.quickreplies是否存在,如果存在,则进行处理并使其与facebook兼容,就像我在上面的ruby代码中所做的那样。
发布该更改
message: {
text: msg,
},
至
message: {
text: msg,
quick_replies: object_you_created
}
https://stackoverflow.com/questions/39936026
复制相似问题