Facebook Messenger API: Send Structured Message

2019-07-05 00:39发布

问题:

When following this example.

messageData = {
"attachment": {
  "type": "template",
  "payload": {
    "template_type": "generic",
    "elements": [{
      "title": "First card",
      "subtitle": "Element #1 of an hscroll",
      "image_url": "http://messengerdemo.parseapp.com/img/rift.png",
      "buttons": [{
        "type": "web_url",
        "url": "https://www.messenger.com/",
        "title": "Web url"
      }, {
        "type": "postback",
        "title": "Postback",
        "payload": "Payload for first element in a generic bubble",
      }],
    },{
      "title": "Second card",
      "subtitle": "Element #2 of an hscroll",
      "image_url": "http://messengerdemo.parseapp.com/img/gearvr.png",
      "buttons": [{
        "type": "postback",
        "title": "Postback",
        "payload": "Payload for second element in a generic bubble",
      }],
    }]
  }
}

I receive an error of:

\"error\":{\"message\":\"(#100) Incomplete element data: title and at least one other field (image url, subtitle or buttons) is required with non-empty value\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"ElbXaF25+0G\"}

Am I missing something? Looks to me that all the relevant fields are present.

回答1:

Figured it out, writing this in ruby and I needed to call to_json on the hash before sending it.



回答2:

Yes, Before sending need to convert to json format Either it is a structured message Or text message.