1

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?

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205

2 Answers2

0

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

samuelhard
  • 369
  • 3
  • 14
  • first of all thanks for your help. the problem is that i'm using [his code](https://github.com/hunkim/Wit-Facebook) and that i'm not sure how to implement this correctly. would you mind taking a quick look at this? – user6942447 Oct 14 '16 at 18:28
  • you will have to implement quick replies in the library it's not available currently in library. you will need to edit this file. https://github.com/hunkim/Wit-Facebook/blob/master/facebook.js and this 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 }, – samuelhard Oct 20 '16 at 09:23
0

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 
}
samuelhard
  • 369
  • 3
  • 14