Reputation: 11
How can I take advantage of the navigation templates from the facebook messenger with wit.ai?
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.
Is there any way that I can fix that?
Upvotes: 1
Views: 318
Reputation: 369
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
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.
post that change
message: {
text: msg,
},
to
message: {
text: msg,
quick_replies: object_you_created
}
Upvotes: 0
Reputation: 369
you will have to send the elements of structured message to facebook when you send message. Wit.ai will set the structured elements in response objects, its your responsibility to pass it on to 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
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
Upvotes: 0