0

I'm implementing a chat bot using messenger API. In a scenario like this, how to match answers with the question when both of them are in text message format. I can't use pattern matching here.

bot q1: How much is it? 
user: 250

bot q2: How many? 
user: 5

Is there a way to send meta data with a text message and get it as a post back. Is it required to store the last message.?

aravindaM
  • 978
  • 8
  • 15
  • 3
    The way I handle this is I do it all locally. I keep track of the state for each user so I know what they're going to mean when they respond the next time. I also store any information for users such as the answer to bot q1 locally. – user2322082 Aug 03 '16 at 16:12
  • That's what am thinking of doing, since there is no other option. – aravindaM Aug 03 '16 at 16:16

1 Answers1

0

In the message field, in the same level of text field, you can define a field metadata, like defined in the doc (which has a 1000 character limit):

Custom string that will be re-delivered to webhook listeners

So it could be sth like that:

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "message":{
    "text":"hello, world!",
    "metadata": "my meta data"
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"    
j0k
  • 22,600
  • 28
  • 79
  • 90
  • Which event triggered by this, Is that a post back? Can you explain little more. All i get is another text message. It doesn't have the meta data included in the previous message. – aravindaM Aug 03 '16 at 10:53
  • 1
    Well I just made some tests on a random bot of mine and it seems that the metadata value is never sent back, maybe you should subscribe to more fields for you webhook, I don't know. But I was almost sure that this field was implemented for that purpose ... :-/ – j0k Aug 03 '16 at 11:51
  • Yes i had the same feeling, and tried , didn't work so far. Will do more testing. – aravindaM Aug 03 '16 at 13:45
  • same here, when you attach a metadata and send it, I dont get it back – PirateApp Aug 21 '16 at 16:08
  • Ya, the docs (https://developers.facebook.com/docs/messenger-platform/reference/send-api/) say that it comes back as an echo, but it definitely doesn't. Just checked that I'm getting the echo, but no meta data. I do see the message sent though in that scenario. – Individual11 Apr 09 '18 at 17:26