Facebook Messenger API - 400 Bad Request? - facebook

This is the full JSON below, I'm sending using Facebook's Generic Template.
I've checked it line-by-line with the official documentation here -> https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-template
But I'm getting a 400 Bad Request Error for the following. What am i missing?
{
"recipient":{
"id":"1347939335300515"
},
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements":[
{
"title":"Welcome to Peters Hats",
"image_url":"https://cdn.pixabay.com/photo/2013/07/13/10/41/hat-157581_960_720.png",
"subtitle":"Weve got the right hat for everyone.",
"default_action":{
"type":"web_url",
"url":"https://cdn.pixabay.com/photo/2013/07/13/10/41/hat-157581_960_720.png",
"messenger_extensions":true,
"webview_height_ratio":"tall",
"fallback_url":"https://cdn.pixabay.com/photo/2013/07/13/10/41/hat-157581_960_720.png"
},
"buttons":[
{
"type":"web_url",
"url":"https://cdn.pixabay.com/photo/2013/07/13/10/41/hat-157581_960_720.png",
"title":"View Website"
},
{
"type":"postback",
"title":"Start Chatting",
"payload":"DEVELOPER_DEFINED_PAYLOAD"
}
]
}
]
}
}
}
}

The default_action is a URL Button and not supposed to be a postback button as in the JSON posted in the question.

Related

LinkedIn Share API returns 400 error - "Owner entity type person is not supported"

I am using the below body to hit the LinkedIn Share API endpoint. Unable to figure out what exactly is the reason for this error and no mention of this in the documentation.
POST REQUEST:
{
"content": {
"contentEntities": [
{
"entityLocation": "https://www.sample.com",
"thumbnails": [
{
"resolvedUrl": "https://www.sample.com"
}
]
}
],
"title": "Test Share with Content"
},
"distribution": {
"linkedInDistributionTarget": {}
},
"owner": "urn:li:person:_EELFb0y",
"subject": "Test Share Subject",
"text": {
"text": "Test Share!"
}
}
RESPONSE:
{
"message": "Owner entity type person is not supported",
"status": 400
}
Any help on this?
[Official LinkedIn API DOCS]
In v2 API, LinkedIn uses "author", not "owner"
{
"author": "urn:li:person:8675309",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "Hello World! This is my first Share on LinkedIn!"
},
"shareMediaCategory": "NONE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
May be that is the reason for that status=400

"Get Started" button not working in Facebook Page

I recently setup the "Get Started" button using the following POST method using Postman:
https://graph.facebook.com/v2.6/me/messenger_profile?access_token=<my token>
With the raw text:
{
"get_started": {"payload": "<postback_payload>"}
}
It returns:
{
"result": "success"
}
But nothing show up in my Messenger (deleted the chat already)
If I send the raw data to setup the greeting text, it works normally and showed up:
{
"greeting": [
{
"locale":"default",
"text":"Hello!"
}, {
"locale":"en_US",
"text":"Timeless apparel for the masses."
}
]
}
Can somebody help me, thanks!

Media Response in Custom Payload (Dialogflow)

I'm trying to code a Media Response in a Custom Payload with no luck. I'm surely doing something wrong but I have no idea :) The Media Response does not show up when testing. (Please note that I'm trying this in an english action). Here's the JSON code:
{
"platform": "google",
"type": "custom_payload",
"payload": {
"google": {
"richResponse": {
"items": [
{
"mediaResponse": {
"mediaType": "AUDIO",
"mediaObjects": [
{
"name": "Exercises",
"description": "ex",
"largeImage": {
"url": "https://firebasestorage.googleapis.com/...",
"accessibilityText": "image..."
},
"contentUrl": "https://firebasestorage.googleapis.com/..."
}
]
}
}
]
}
}
}
}
UPDATE:
I've updated the JSON to something like this. But I get an error :"API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: ": Cannot find field."
{
"platform":"google",
"type":"custom_payload",
"payload":{
"google":{
"richResponse":{
"items":[
{
"simpleResponse":{
"textToSpeech":"Hey! Good to see you."
}
},
{
"mediaResponse":{
"mediaType":"AUDIO",
"mediaObjects":[
{
"name":"Exercises",
"description":"ex",
"largeImage":{
"url":"https://firebasestorage...",
"accessibilityText":"..."
},
"contentUrl":"https://firebasestorage.googleapis.com/..."
}
]
}
}
],
"suggestions":[
{
"title":"chips"
}
]
}
}
And here's the debug information:
{
"audioResponse": "//NExAARWG...",
"conversationToken": "GidzaW11bG...",
"debugInfo": {
"agentToAssistantDebug": {
"agentToAssistantJson": "{\"message\":\"Failed to parse Dialogflow response into AppResponse, exception thrown with message: Empty speech response\",\"apiResponse\":{\"id\":\"cd7204ac-ab80-42aa-9755-6123cbb938a6\",\"timestamp\":\"2018-03-11T09:02:35.827Z\",\"lang\":\"en-us\",\"result\":{},\"status\":{\"code\":200,\"errorType\":\"success\"},\"sessionId\":\"1520758955600\"}}"
},
"assistantToAgentDebug": {
"assistantToAgentJson": "{\"user\":{\"userId\":\"AA9douaa4XGkqtmcU_EDjPy7PQ_9\",\"locale\":\"en-US\",\"lastSeen\":\"2018-03-11T09:02:09Z\"},\"conversation\":{\"conversationId\":\"1520758955600\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"VOICE\",\"query\":\"Talk to Zen Coach\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]}]}",
"curlCommand": "curl -v 'https://api.api.ai/api/integrations/google?token=0def1bb6be4b4bf2810ec68bf6f37a6a' -H 'Content-Type: application/json;charset=UTF-8' -H 'Google-Actions-API-Version: 2' -H 'Authorization: eyJhbGciOiJSUzI1NiIsImtpZCI6ImFjMmI2M2ZhZWZjZjgzNjJmNGM1MjhlN2M3ODQzMzg3OTM4NzAxNmIifQ.eyJhdWQiOiJ6ZW4tY29hY2giLCJhenAiOiI0OTYwOTIwOTE1NzEtMGNhY3VtczVkZ3F1OWpkM2k0dHZpOGFiOTVydXQ2NnQuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJleHAiOjE1MjA3NTkwNzUsImlzcyI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbSIsImp0aSI6IjY4NDc0NThhNTNhZGExODAxZjMwMjAyYjkxZGIyODZhMjk1NzA2YmIiLCJpYXQiOjE1MjA3NTg5NTUsIm5iZiI6MTUyMDc1ODY1NX0.e1cqg96F5L-BvD0yJz3UFgsnX_0TRox0Lu8R9K5NhhXcQVfC7mq1QwCqs2DGrUJGquGdW2GhzBU2lzf4ro2TUeieg4ozak1OmiYAMqtiCH0EodeHy59AXXqzb3a35YuD7CmSDu6qVQRfEp8uaaH2t-Sq9lUchudNOgjucip3ex9Rr2XacHm0qWtV69H1o-Yq5INl5HHR0kNqtEIsxUox961imKvDLN5s--F35yTbAhIWibr6OmaACyzSQW5X7OjrJ2781DSmEdYn73poDbuwMS9E2l9B-QTUHAIpUM5b4WqrFkD6XKALdf2pQFwZlRRhDzRiDKWLA-i1w-mcak0LWw' -A 'Mozilla/5.0 (compatible; Google-Cloud-Functions/2.1; +http://www.google.com/bot.html)' -X POST -d '{\"user\":{\"userId\":\"AA9douaa4XGkqtmcU_EDjPy7PQ_9\",\"locale\":\"en-US\",\"lastSeen\":\"2018-03-11T09:02:09Z\"},\"conversation\":{\"conversationId\":\"1520758955600\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"VOICE\",\"query\":\"Talk to Zen Coach\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]}]}'"
},
"sharedDebugInfo": [
{
"name": "ResponseValidation",
"subDebugEntry": [
{
"debugInfo": "API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: \": Cannot find field.\".",
"name": "UnparseableJsonResponse"
}
]
}
]
},
"response": "Zen coach isn't responding right now. Try again soon.",
"visualResponse": {
"visualElements": []
}
}
Are you adding "platform":"google" and "type":"custom_payload" in the custom payload? If so, try removing that.
I made the following work with my Voice Metronome application:
{
"google":{
"richResponse":{
"items":[
{
"simpleResponse":{
"textToSpeech":"Hey! Good to see you."
}
},
{
"mediaResponse":{
"mediaType":"AUDIO",
"mediaObjects":[
{
"name":"Exercises",
"description":"ex",
"largeImage":{
"url":"http://res.freestockphotos.biz/pictures/17/17903-balloons-pv.jpg",
"accessibilityText":"..."
},
"contentUrl":"https://freepd.com/Chill/Chill Air.mp3"
}
]
}
}
],
"suggestions":[
{
"title":"chips"
}
]
}
}
}
The issue is that the richResponse property still needs to follow the rules of the RichResponse object. The first item in it must be a SimpleResponse object. (I haven't tested, but you can probably have that say nothing, but it is a good spot to have an introduction to your audio.)
The error message Failed to parse Dialogflow response into AppResponse, exception thrown with message: Empty speech response suggests that it might also be looking for a speech parameter on the top-level object in the response, which is what Dialogflow v1 expects to duplicate either the simpleResponse ssml or textToSpeech parameters. I'm not sure why that would appear if you're set to v2, but it sounds like something might be confused there. I would make sure you're using v1 and that you have a speech parameter.
Also keep in mind that the reviewers will look for suggestion chips about how to move the conversation forward during or after the audio if this isn't a final response.

Error Response with Google Smart Home (Thermostat)

I am unable to understand the syntax of Json for errors
I have tried
return {
"requestId": self.request_id,
"payload": {
"commands": [{
"ids": [self.device_id],
"status": "OFFLINE",
"errorCode": "deviceTurnedOff"
}]
}
}
and
return {
"requestId": self.request_id,
"payload": {
"errorCode": "authFailure",
"commands": [{
"devices": [{
"ids": [self.device_id],
"status": "ERROR",
"errorCode": "deviceTurnedOff"
}]
}]
}
}
and
return {
"requestId": self.request_id,
"payload": {
"errorCode": self.error_code
}
}
none of above syntax are working, most of the time google home says that your actions is performed but I am returning error Json there.
I have read google actions documentation but failed to understand.
I have come up with a few payloads and have managed to get them successfully triggering errors using the AoG simulator after consulting the docs.
Node.js snippet:
let resBody = {
requestId: request.requestId,
payload: {
"errorCode": "notSupported"
}
}
response.status(200).json(resBody);
Are you sure that the requestId is the same from the smart home request? How are you testing these errors?

"image_aspect_ratio" flag not respected while sharing from Messenger BOT webview

I'm trying to make a share from the webview of my bot. Here's my code
var messageToShare = {
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"image_aspect_ratio":"square",
"elements":[
{
"title":"Welcome to Peter\'s Hats",
"subtitle":"We\'ve got the right hat for everyone.",
"image_url":"https://pbs.twimg.com/profile_images/735453447718338561/9W-MTtOo_400x400.jpg",
"buttons":[
{
"type":"web_url",
"url": "my share url",
"title":"View Website"
}
]
}
]
}
}
}
MessengerExtensions.beginShareFlow(
function success() {},
function error(errorCode, errorMessage) {},
messageToShare,
"broadcast"
);
The share is working, but it's not posting the image as expected. The "image_aspect_ratio" flag is not respected and the image is displayed with horizontal layout.
But the same JSON displays the image as a square when the share is done thru CURL. Is there something wrong with my share object ? Please help
It was a bug on Messenger platform. I reported about it to Facebook and now it has beed fixed.
https://developers.facebook.com/bugs/391245647960177/
You need to add "sharable":true in your payload:
var messageToShare = {
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"image_aspect_ratio":"square",
"sharable": true,
"elements":[
{
"title":"Welcome to Peter\'s Hats",
"subtitle":"We\'ve got the right hat for everyone.",
"image_url":"https://pbs.twimg.com/profile_images/735453447718338561/9W-MTtOo_400x400.jpg",
"buttons":[
{
"type":"web_url",
"url": "my share url",
"title":"View Website"
}
]
}
]
}
}
}