facebook persistent menu with api.ai - facebook

i tried with custom webhook on my server for FB persistent menu and other features it works fine.
when i am using api.ai as webhook and for NLP understanding and Facebook bot as client interface then in that case how to use persistent menu.

Set the persistent menu (don't forget to set your access token).
curl -X POST -H "Content-Type: application/json" -d '{
"persistent_menu":[
{
"locale":"default",
"composer_input_disabled":false,
"call_to_actions":[
{
"title":"Examples",
"type":"nested",
"call_to_actions":[
{
"type":"postback",
"title":"Option 1",
"payload":"OPTION_1"
},
{
"type":"postback",
"title":"Option 2",
"payload":"OPTION_2"
},
]
},
{
"type":"postback",
"title":"Share Bot",
"payload":"SHARE"
}
]
}
]
}' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=<ACCESS_TOKEN>"
In your bot code, double check that your POST webhook deals with the event.postback. Then check the payload of the postback to action the menu request.
if(event.postback.payload == "OPTION_1") {
// Option 1 bot action
}
if(event.postback.payload == "OPTION_2") {
// Option 2 bot action
}
if(event.postback.payload == "SHARE") {
// Share bot action
}

Related

How to perform PATCH operation in Firebase APi?

The firebase doc sys this is how it is supposed to be done:
curl -X PATCH -d '{"last":"Jones"}' \
'https://[PROJECT_ID].firebaseio.com/users/jack/name/.json'
But I dont know how to convert this to a rest based request.
TO be clear I need to send a web request from javascript/java, hence I want to know what should be the body , and header and operation type for this request.
Can someone please help?
If you use the documentation for curl, you can figure out what that command line you showed is trying to tell you.
The HTTP method is: PATCH
The request body is: {"last":"Jones"}
The url is: https://[PROJECT_ID].firebaseio.com/users/jack/name/.json
Where PROJECT_ID is the name of your project. That's all there is to it.
You need teh following structure:
HTTP Request:
https://firestore.googleapis.com/v1/projects/*YOUPROJECT_ID*/databases/(default)/documents/users_admin/*DOCUMENT_ID*?**updateMask.fieldPaths=user_name&updateMask.fieldPaths=permisos.Administrador&updateMask.fieldPaths=user_email**
JSON Body (must be exactly the same structure and type as your database):
{
"fields": {
"user_name": { "stringValue": "Test ActualizaciĆ³n 2" },
"permisos": {
"mapValue": {
"fields": {
"Administrador": {
"booleanValue": true
}
}
}
},
"user_email": { "stringValue": "veviboj548#eyeremind.com" }
}
}

Get secret gists using Github GraphQL

As title, I'm using Github GraphQL explorer to fetch list of my gists.
query {
viewer {
gists(first:5, privacy:ALL) {
edges {
node {
id
description
name
pushedAt
}
}
}
}
}
Everything works fine except that the secret gists are not included in the response. When I tried to fetch secret gists by changing the GistPrivacy from ALL to SECRET as below:
query {
viewer {
gists(first:5, privacy:SECRET) {
edges {
node {
id
description
name
pushedAt
}
}
}
}
}
The following permission error occurred:
{
"data": {
"viewer": {
"gists": {
"edges": []
}
}
},
"errors": [
{
"message": "You don't have permission to see gists."
}
]
}
I wonder is there any way to solve this problem.
I noticed that there was a related questions with irrelevant answer asked 5 years ago.
Any comment or help is much appreciated, thanks in advance.
As it turns out, although one can't get the secret gists from the Github GraphQL explorer directly, by creating a Personal Access Tokens and using it to access the GraphQL API, one can get the secret gists.
The equivalent curl command is as following:
curl --request POST \
--url https://api.github.com/graphql \
--header 'authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN' \
--header 'content-type: application/json' \
--data '{"query":"query {\n viewer {\n gists(first:5, privacy:ALL) {\n\t\t\tedges {\n\t\t\t\tnode {\n\t\t\t\t\tid\n\t\t\t\t\tdescription\n\t\t\t\t\tname\n\t\t\t\t\tpushedAt\n\t\t\t\t}\n\t\t\t}\n\t\t}\n }\n}"}'

Inspect element - how to get parameters sent to a redirected page and simulate it with postman?

In this link there is a quiz when you click on Start Now:
https://www.clinique.com/diagnostics
After the quiz finished, it posts data to a link and immediately redirects to another page with quiz results.
How to find out what data have been posted to the page and is there a way to simulate the final results with the Postman?
Looks like what you're looking for is the Postman Interceptor feature. It allows you to capture and inspect all the requests made from the browser/system you configure it to proxy to.
Then, once your request was captured, and after a bit of filtering (it'll capture every single request made to the server, not only the POST you're interested into) You will be able to replicate it with the Postman client like you'll do with a regular request. e.g. with the quiz you posted:
You'll find the data posted being sent as x-www-form-urlencoded (what a mess!) on a JSON key with the value:
{
"ProfileName":"04-NA-USA ELC Online 4.05.2017",
"QuizVersion":6,
"QuizAnswers":[
{
"attributeName":"welcome",
"attributeRecapValuesLocalized":"mens_concerns",
"recapColumn":1
},
{
"attributeName":"mens_concerns",
"attributeRecapValuesLocalized":"Eye Area",
"recapColumn":0
},
{
"attributeName":"mens_age",
"attributeRecapValuesLocalized":"50 - 59",
"recapColumn":1
},
{
"attributeName":"mens_eye_area_where",
"attributeRecapValuesLocalized":"Lines/Wrinkles",
"recapColumn":0
},
{
"attributeName":"mens_skintype",
"attributeRecapValuesLocalized":"oily-shiny,tight-uncomfortable",
"recapColumn":0
},
{
"attributeName":"mens_sensitivity_frequency",
"attributeRecapValuesLocalized":"Rarely",
"recapColumn":1
},
{
"attributeName":"mens_sensitivity_redness",
"attributeRecapValuesLocalized":"No",
"recapColumn":1
},
{
"attributeName":"recap",
"attributeRecapValuesLocalized":"",
"recapColumn":1
}
],
"SkinType":"2",
"SKUs":[
{
"Eye Area":[
"7YXH-01",
"7ELF-01",
"6TCR-01"
]
},
{
"Daily Care":[
"ZE4L-01",
"ZF7E-01",
"65EM-01",
"Z219-01",
"Z5WW-01"
]
}
],
"UPCs":[
{
"Eye Area":[
"020714632670",
"020714506827",
"020714382742"
]
},
{
"Daily Care":[
"020714734510",
"020714744762",
"020714104726",
"020714649562",
"020714682255"
]
}
],
"Concerns#1":"Eye Area",
"Concerns#2":"Daily Care",
"UsageOrderSKUs":[
"ZE4L-01",
"ZF7E-01",
"65EM-01",
"7YXH-01",
"Z219-01",
"Z5WW-01",
"7ELF-01",
"6TCR-01"
],
"UsageOrderUPCs":[
"020714734510",
"020714744762",
"020714104726",
"020714632670",
"020714649562",
"020714682255",
"020714506827",
"020714382742"
]
}

Facebook Chatbot Persistent Menu doesn't work (parameter setting_type is required)

I'm currently trying to implement a Persistent Menu for my Facebook Chatbot. Sadly there are two (completely different) documentation for the implementation which both don't work for me. (Both should work for API v2.6)
https://developers.facebook.com/docs/messenger-platform/messenger-profile/persistent-menu
https://developers.facebook.com/docs/messenger-platform/thread-settings/persistent-menu
I used this simple call which is returning an error (#100) The parameter setting_type is required
curl -X POST -H "Content-Type: application/json" -d '{
"persistent_menu":[
{
"call_to_actions":[
{
"type":"web_url",
"title":"Einstellungen",
"url":"https://{{url-part}}.cloudfront.net/",
"webview_height_ratio":"full"
}
]
},
{
"locale":"de_DE",
"composer_input_disabled":false
}
]
}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token={{token}}"
If I use the second documentation with "setting_type" : "call_to_actions" the same error occurs.
Why I can't set up a Persistent Menu?
The below works for me.
Make sure you are sending the request to the new endpoint, messenger_profile. You have to provide at least a default locale.
curl -X POST -H "Content-Type: application/json" -d '{
"persistent_menu":[
{
"locale":"default",
"composer_input_disabled":false,
"call_to_actions":[
{
"type":"web_url",
"title":"Einstellungen",
"url":"https://{{url-part}}.cloudfront.net",
"webview_height_ratio":"full"
}
]
}
]
}' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token={{token}}"

Weird error with Facebook Messenger Platform/bot Welcome Confugration

I'm getting a weird error while configuring welcome message for my Messenger bot. I've been using the same code (as shown below) and it has just been working fine until last night. I tried it with both cURL and Postman. Neither of them works.
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"message":{
"text":"Welcome to My Company!"
}
}
]
}' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>"
Error message when executing the code above:
{"error":{"message":"(#100) Invalid keys \"message\" were found in param \"call_to_actions[0]\".","type":"OAuthException","code":100,"fbtrace_id":"Hn42Wa+hapI"}}%
I can confirm both PAGE_ID and PAGE_ACCESS_TOKEN are correct as trying to delete the welcome message with the following code works fine.
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"message":{
"text":"Welcome to My Company!"
}
}
]
}' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>"
Also, the code I'm using is exactly the same as shown on the Facebook official API doc. I don't understand why it's saying "message" is not a valid key. Is anyone experiencing the same problem? Did Facebook change their api?
Any help will be much appreciated!
The docs are now updated, you need to define your payload in payload parameter now (a UTF-8 encoded string), eg:
"call_to_actions":[
{
"payload":"USER_DEFINED_PAYLOAD"
}
]
Docs updated:
https://developers.facebook.com/docs/messenger-platform/thread-settings/greeting-text
Example:
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"greeting",
"greeting":{
"text":"Welcome to My Company!"
}
}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN"
I get the same issue and fix it.
I think your json of request is
let messageData = {
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"payload":"welcome_payload"
}
]
}
request({
url: 'https://graph.facebook.com/v2.6/me/thread_settings',
qs: {access_token:token},
method: 'POST',
json: {
messageData
}
}
but it will not work and log will say you have no "setting_type" = =a
try this one
request({
url: 'https://graph.facebook.com/v2.6/me/thread_settings',
qs: {access_token:token},
method: 'POST',
json: {
setting_type:"call_to_actions",
thread_state:"new_thread",
call_to_actions:[
{
"payload":"welcome_payload"
}
]
}
}
it work for me.
This error was due to an API change.
New call:
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[{
"payload":"START"
}]
}' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_TOKEN>"
Just add a payload like {"payload":"START"}
If a user press the "Getting started" button, you receive this payload in your messageHandler (webhook). Check if $incomingMessage == "START" and send back your structured message, or whatever you want.
Messages like before are not supported anymore.
Bug report: https://developers.facebook.com/bugs/1751749508372552/