How to use quick replies with attachment - facebook-messenger

In official documentation of quick replies says:
Quick Replies work with all message types including text message, image and template attachments.
But when i try send it with template_type: button, I got error:
{
"error": {
"message": "(#100) Only one of text or attachment can be specified",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "H8w+ZfRbBub"
}
}
That I try to send:
{
"recipient": {"id": "234567890"},
"message": {
"text": "TEXT_MESSAGE",
"quick_replies": [
{
"content_type": "text",
"title": "SOME_TITLE_1",
"payload": "PAY_LOAD_1"
},
{
"content_type": "text",
"title": "SOME_TITLE_2",
"payload": "PAY_LOAD_2"
}
],
"attachment": {
"type": "template",
"payload": {
"template_type": "button",
"text": "TEXT_MESSAGE",
"buttons": [
{
"title": "READ_MORE_BUTTON",
"type": "postback",
"payload": "look:1:c"
}
]
}
}
}
}
when I sent without message.text, I got error:
{
"error": {
"message": "(#100) Cannot use both CTA and quick reply",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "C0DDxGzaUUj"
}
}
What is CTA?
How send quick replies with attachment?

This message structure should work for sending an image attachment with quick replies:
{
"recipient": {
"id": recipient_id
},
"message": {
"attachment":{
"type":"image",
"payload":{
"url": image_url
}
},
"quick_replies": [
{
"content_type":"text",
"title": "Next Image",
"payload": "YOUR_DEFINED_PAYLOAD_FOR_NEXT_IMAGE"
}
]
}
}
Hope that helps dmitry.

try this way. It will insert both buttons and quick replies but button will be at top and quick replies will be at the bottom
"message":{
"quick_replies":[
{"content_type":"text",
"title":"title1",
"payload":"SUPPLEMENT_1"},
{"content_type":"text",
"title":"title2",
"payload":"PAYLOAD_1"
}
],
"attachment":{
"type":"template",
"payload":{
"template_type":"button",
"text":"your text",
"buttons":[
{
"type":"postback",
"title":"Confirm",
"payload":"USER_DEFINED_PAYLOAD"
}
]
}
}
}

So, I've got your same problem and I did some searches around.
What does CTA stands for?
First of all, CTA stands for Call-To-Action. These are the buttons you create with a request for a Button Template, Generic Template or with the Persistent Menu Thread Settings.
It seems that, although as you said FB official documentation explicitly states that Quick Replies are supported with ANY template, for some reason this doesn't include the Button template.
Why is that?
It seems logical to me that the Button Template should be used to present the user with a choice, same thing that the Quick Replies do, so it would be redundant.
Why is that not documented?
I'm assuming that it's probably due to the fact that the Messenger Platform API is still in beta and there are lots of changes from day to day. Personally, I'm working on a Java framework for doing Facebook Messenger bots and I'm finding that many things are not very well documented and often the error messages you get back are misleading. So, you should probably accept the fact that the Button Template and Quick Replies doesn't work together. Quick Replies works with any other template or with text messages though.

This worked for me while using dialogflow
{
"facebook": {
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements":[
{
"title":"Welcome!",
"image_url":"https://petersfancybrownhats.com/company_image.png",
"subtitle":"We have the right hat for everyone.",
"default_action": {
"type": "web_url",
"url": "https://petersfancybrownhats.com/view?item=103",
"webview_height_ratio": "tall"
},
"buttons":[
{
"type":"web_url",
"url":"https://petersfancybrownhats.com",
"title":"View Website"
},{
"type":"postback",
"title":"Start Chatting",
"payload":"DEVELOPER_DEFINED_PAYLOAD"
}
]
}
]
}
},
"quick_replies":[
{
"content_type":"text",
"title":"Search",
"payload":"<POSTBACK_PAYLOAD>",
"image_url":"http://example.com/img/red.png"
},
{
"content_type":"location"
}
]
}
}

Related

I have a datastudio error - basic json config

I've returned to try and make some datastudio custom javascript.
So I started off with a template type settings and basic js. Manifest is listing correctly - datastudio sees the custom item.
I took a long time for it to be authorised.
However, on adding the custome js, the console is reporting a load of erros.
first : data.0.type is not a valid config
second : data.0.elements.data.0.type is not a valid config.
Json:
{
"data": [
{
"id": "idtestviz",
"label": "Dimension Element Heading",
"type":"DIMENSION"
}
]
,
"style": [
{
"id": "idtestvizstyles",
"label": "Test Styles",
"elements":[
{
"id":"idtestvizfontcolor",
"label":"Font Colour",
"defaultValue":"#FFFF00"
}
]
}
]
}
It did have options in before, same error.
And appears to be the same as in https://developers.google.com/datastudio/visualization/define-config
Also it also is erroring on 'is already used in the config'
and that data.0.elements.style.0.elements.0.type required field that cannot be found
Seems like there are more checks that need to be done.
Is there a validator for json etc. before running, or has something updated on google side that their documentation hasn't been updated yet?
Or the more likely aspect, I'm missing some critical stuff...
Regards
Vince
Re checked my json config with a previous one that works, noted some errors in the objects. Corrected those and the json errors in the console have gone away.
JS errors remain - working on those... closing this question.
{
"data": [
{
"id":"test_viz_data",
"label":"Test Viz Data",
"elements":[
{
"id": "text_viz_dimensions",
"label": "Dimension Element Heading",
"type": "DIMENSION",
"options": {
"min": 1,
"max": 1
}
}
,
{
"id": "test_metrics",
"label": "Metric fields",
"type": "METRIC",
"options": {
"min": 1,
"max": 1
}
}
]
}
]
,
"style": [
{
"id": "idstyles",
"label": "Test Styles",
"elements":[
{
"id":"idfontcolor",
"label":"Font Colour",
"type":"FONT_COLOR",
"defaultValue":"#FFFF00"
}
]
}
]
,
"interactions": [
]
}

Alexa Smart Home "Failed to Retrieve State"

I am playing with a sample Alexa Smart Home skill - I am not talking to any real hardware or back-end, just trying to get message flow working. I have set up a simple switch/plug/light that can just support turning On/Off - and I have account linked working and the skill enabled. When I try looking at it via the Alexa app on phone or web (with debug enabled) it always says the device isn't responding, or it's "Failed to Retrieve State". I can definitely see the messages in Cloud Watch as follows.
Any idea why I'd be chronically getting such a response??
Request:
"directive": {
"endpoint": {
"cookie": {},
"endpointId": "endpoint-003",
"scope": {
"token": "<<<SUPRESSING>>",
"type": "BearerToken"
}
},
"header": {
"correlationToken": "<<SHORTENED>>",
"messageId": "50397414-bb9d-412f-8a2c-15669978ab64",
"name": "ReportState",
"namespace": "Alexa",
"payloadVersion": "3"
},
"payload": {}
}
}
Response:
{
"context": {
"properties": [
{
"name": "connectivity",
"namespace": "Alexa.EndpointHealth",
"timeOfSample": "2020-06-29T16:49:59.00Z",
"uncertaintyInMilliseconds": 0,
"value": "OK"
},
{
"name": "powerState",
"namespace": "Alexa.PowerController",
"timeOfSample": "2020-06-29T16:49:59.00Z",
"uncertaintyInMilliseconds": 0,
"value": "ON"
}
]
},
"event": {
"endpoint": {
"endpointId": "endpoint-003",
"scope": {
"token": "Alexa-access-token",
"type": "BearerToken"
}
},
"header": {
"correlationToken": "<<SHORTENED>>",
"messageId": "7a8b9a71-adda-41b8-acba-4d3855374845",
"name": "Response",
"namespace": "Alexa",
"payloadVersion": "3"
},
"payload": {}
}
}
Problem was: The "name" in my header response should have been "ReportState". "Response" is only used for things that set/change values.
My general advice is to always verify that THREE things are good:
Initial "Discovery"
"Response" messages
General "ReportState" queries.
By this - I mean that:
Anything you advertised as should be reported in "discovery" better be reported in other ("ReportState") messages. If you advertise a "PowerController" - if your ReportStates don't contain status for that, you'll either not see the status, or it'll keep retrying forever (continuing to look for it) - or you might get some sort of an error.
If you CHANGED your discovery stuff - make sure that you really removed, re-discovered, and that the states (above) for the new additions/removals are okay
Always make sure that "EndpointHealth" is being reported.

Internal Server Error when creating Conditional Access Policy

I referred to this documentation to make a POST request.
Below is the error while making a POST request to create a conditional access policy
{
"message": "There was an internal server error while processing the request. Error ID: 2dbb1530-4ce6-44f5-9c63-08de28d7218a",
"innerError": {
"request-id": "2dbb1530-4ce6-44f5-9c63-08de28d7218a"
}
}
Payload being passed with the request is below:
{
"displayName": "Test Policy",
"state": "enabled",
"conditions": {
"clientAppTypes": ["modern", "browser"],
"applications": {
"includeApplications": ["None"]
},
"users": {
"includeUsers": [
"08290005-23ba-46b4-a377-b381d651a2fb"
]
},
"locations": {
"includeLocations": ["All"],
"excludeLocations": ["AllTrusted"]
}
},
"grantControls": {
"operator": "OR",
"builtInControls": ["approvedApplication"]
}
}
I've tried using this endpoint to get a policy:
https://graph.microsoft.com/beta/{tenant_id}/conditionalAccess/policies
Which successfully returns an existing policy. However, the above POST request is not working.
The "approvedApplication" requirement only supports the iOS and Android for device platform condition. See details here.
You need to add "includePlatforms" iOS and android into the json body.
{
"displayName": "Test Policy",
"state": "enabled",
"conditions": {
"clientAppTypes": ["modern", "browser"],
"applications": {
"includeApplications": ["None"]
},
"users": {
"includeUsers": [
"08290005-23ba-46b4-a377-b381d651a2fb"
]
},
"platforms": {
"includePlatforms": [
"iOS", "android"
]
},
"locations": {
"includeLocations": ["All"],
"excludeLocations": ["AllTrusted"]
}
},
"grantControls": {
"operator": "OR",
"builtInControls": ["approvedApplication"]
}
}

Alexa "I'm not quite sure what went wrong."

I am having problems with a smart home skill. The discovery part seems to go well but when I try to report state the following happens.
My smart home skill sends this request
{
"directive": {
"header": {
"namespace":"Alexa",
"name":"ReportState",
"payloadVersion":"3",
"messageId":"[ID]",
"correlationToken":"[Token]"
},
"endpoint": {
"scope": {
"type":"BearerToken",
"token":"[AuthToken]"
},
"endpointId":"appliance-002",
"cookie": {}
},
"payload": {}
}
}
I return this
{
"context": {
"properties": [
{
"namespace":"Alexa.TemperatureSensor",
"name":"temperature",
"timeOfSample":"2018-04-08T20:44:33Z",
"uncertaintyInMilliseconds":500,
"value": {
"value":23,
"scale":"CELSIUS"
}
},
{
"namespace":"Alexa.EndpointHealth",
"name":"connectivity",
"timeOfSample":"2018-04-08T20:44:33Z",
"uncertaintyInMilliseconds":0,
"value":"OK"
}
]
},
"event": {
"header": {
"namespace":"Alexa",
"name":"StateReport",
"payloadVersion":"3",
"messageId":"[ID]",
"correlationToken":"[Token]"
},
"endpoint": {
"endpointId":"appliance-002",
"cookie": {},
"scope": {
"type":"BearerToken",
"token":"[AuthToken]"
}
},
"payload": {}
}
}
And Alexa just say
"I'm not quite sure what went wrong."
Well neither am I. Can anybody figure out whats going on here. Any help would be much appreciated.
A process downstream altered my json giving a incomplete response. I am unable to see this in any logs anywhere, so the finding was made by utilizing sleep, coffee and hard work.

"Send To Messenger" page scoped user id, different to messenger id

When using the "Send To Messenger" plugin, the response received is:
{
"object": "page",
"entry": [
{
"id": "410441912660258",
"time": 1506529761355,
"messaging": [
{
"recipient": {
"id": "410441912660258"
},
"timestamp": 1506529761355,
"sender": {
"id": "1388094137927363"
},
"optin": {
"ref": "login"
}
}
]
}
]
}
However, when I interact with Messenger using the same Messenger Account, Facebook sends:
{
"originalRequest": {
"source": "facebook",
"data": {
"sender": {
"id": "1271682282961502"
},
"recipient": {
"id": "1818762375111057"
},
"message": {
"mid": "mid.$cAAZ2J6JWBDZk9XGKQVexCxoKu27Y",
"text": "hi",
"seq": 17289
},
"timestamp": 1506529788481
}
}
}
Note that, despite using the same Messenger account, the sender/recipient IDs are different. So I can't match any users up from the Messenger Chat vs the Send To Messenger button.
I believe this is because the "Send To Messenger" button is using the Page Scoped User ID of the relevant Facebook Page, instead of the Facebook App. Is there any way to match these two IDs or, to tell the Send To Messenger button to use the APP ID instead of the Page ID?
You can use the ID matching API
https://developers.facebook.com/docs/messenger-platform/identity/id-matching

Resources