Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Messenger API: Send Structured Message

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.

like image 526
skylan22 Avatar asked Mar 11 '26 20:03

skylan22


1 Answers

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

like image 74
skylan22 Avatar answered Mar 14 '26 09:03

skylan22



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!