Testing Facebook Messenger Opt-in callback - facebook-messenger

I am trying to test my webhook that subscribes to the messaging_optins event, but I am struggling to manually trigger the event.
The documentation seems to indicate that using the "Send to Messenger" plugin should fire this event, but after setting up the button no event is triggered. The user is redirected to messenger website and asked to login, and then directed to an empty conversation with my page. I have tried this as my admin user, a random real Facebook account and a test account for my app.
When should this event be fired? And how can i trigger the event manually?
Edit
I would like to note that my webhooks are working and I am able to receive events for messages being received. Just not the opt-ins event.

You can use the curl request below, if you are checking sha1 signature then replace the SHA1OFTHEBODY with sha1 signature of the payload and replace the https://chabotproxy.com/messenger/webhooks with your webhook endpoint url:
curl -X POST -H "x-hub-signature: sha1=SHA1OFTHEBODY" -H "content-type: application/json" -d '{
"object":"page",
"entry":[
{
"id":"PAGE_ID",
"time":1458692752478,
"messaging":[
{
"sender":{
"id":"USER_ID"
},
"recipient":{
"id":"PAGE_ID"
},
"timestamp":1234567890,
"optin":{
"ref":"chatbotproxy.com"
}
}
]
}
]
}' https://chabotproxy.com/messenger/webhooks

Related

I use user_ref which get from checkbox plugin opt-in webhook to send a message to a user, I cannot receive prior_message after the user replying us

I write a demo web page which contains Checkbox plugin. I set user_ref for the plugin during every rendering.
An user click the checkbox and submit subscribe request. Then a opt-in webhook has been sent to me with a unique user_ref.
I send a message to the user_ref (set it as recipient) successfully.
After the user replied my message, I get a webhook in this format:
"sender":{ "id":"PSID" }, "recipient":{ "id":"PAGE-ID" }, "timestamp":XXXXX, "message":{ "mid":"mid.145...", "text":"XXXXX" } According to the official document: https://developers.facebook.com/docs/messenger-platform/discovery/checkbox-plugin#implementation The webhook I expected to receive should be in this format: "sender":{ "id":"PSID" }, "recipient":{ "id":"PAGE-ID" }, "timestamp":XXXXXXX, "message":{ "mid":"mid.145...", "text":"XXXX" }, "prior_message": { "source":"checkbox_plugin", "identifier":"USER-REF" }
The parameter "prior_message" is missing
I hope to get the identifier in the prior_message and use the identifier to distinguish the user that replying to us

get started button for fb messenger in dialog flow

I need some help regarding chatbot development. right now i am doing a project wherein im creating a chatbot using dialogflow and im testing it in FB messenger. one of the modules that i need to accomplish is to put a "get started" button to start a chat and a persistent menu in FB messenger. i've tried to search on how to do it but there's no specific tutorial on how to implement it in dialogflow. i never tried any code so far 'coz i don't know where should i put it. i hope someone out there will help me regarding this matter. thank you so much!
You can do these using Postman (free) but first you should have an Access Token
To get your page Access Token:
Head over to your Facebook App that you created for the bot on Facebook Developers
Go to Messenger --> Settings
Access Token Section
Generate an Access Token for your page
GET STARTED BUTTON
After you get your Access Token Go to Postman
Send a POST Request to: https://graph.facebook.com/v2.6/me/thread_settings?access_token=xxxxx
Replace xxxxx with your Access Token previously fetched
Go to Body and insert the following JSON
{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
{
"payload":"YOU PUT OPTIONAL PAYLOAD HERE"
}
]
}
PERSISTENT MENU
Send a POST Request to: https://graph.facebook.com/v2.6/me/messenger_profile?access_token=xxxxx
Replace xxxxx with your Access Token previously fetched
Go to Body and insert the following JSON (you can edit as you wish)
{
"persistent_menu":[
{
"locale":"default",
"composer_input_disabled":false,
"call_to_actions":[
{
"title":"Title 1",
"type":"postback",
"payload":"payload1"
},
{
"title":"Title 2",
"type":"postback",
"payload":"payload 2"
},
{
"title":"Title 3",
"type":"postback",
"payload":"payload 3"
}
]
}
]
}

Codename One Curl Request oAuth

I am trying to make a call to the Petfinder API from codename one. It requires oAuth authorization. Right now I am able to get access to the API from terminal, but I do not know how to call it from codename one which uses Java. Right now I'm able to pull data from APIs that don't need oAuth but need a key.
From terminal it looks like this:
curl -d "grant_type=client_credentials&client_id={CLIENT-ID}&client_secret={CLIENT-SECRET}" https://api.petfinder.com/v2/oauth2/token
{"token_type": "Bearer","expires_in": 3600,"access_token": "{my access token}"
}
curl -H "Authorization: Bearer {my access token}" GET https://api.petfinder.com/v2/animals?type=dog&page=2
You can use something like this. I haven't tested it though so debugging will be required:
Rest.post("https://api.petfinder.com/v2/oauth2/token").
queryParam("grant_type", "client_credentials").
queryParam("client_id", clientId).
queryParam("client_secret", clientSecret).
fetchAsJsonMap(response -> {
// data is already parsed to Map here
if(response.getResponseData() != null) {
accessToken = (String)response.getResponseData().get("access_token");
// set the auth header for all future requests in this session
addDefaultHeader("Authorization", "Bearer " + accessToken);
}
});
Notice that the code assumes a static import of the CN class exists. You could also store the token into Prefrences and load it dynamically/set it globally as I did here which is the more complete example.

Issue with watch request on gmail api

I am using the below code to send a watch request to gmail. But it is sending push notifications for every action on the mailbox. I need google to send notifications if there is a new email received only. Otherwise I don't want google to send notifications. I am using google-api nodejs client. Can anyone please assist me on this?
watch (cb) {
const params = {
userId: 'me',
resource: {
labelIds: ['INBOX'],
labelFilterAction: 'include',
topicName: configure.Google.TopicName
}
};
this.gmail.users.watch(params, cb);
}
You can do labelIds: ['UNREAD']
When you go to request history.list with the historyId, there is an option to limit the messages returned to messagesAdded, though you will continue to get extraneous push notifications.
labelIds expects the id of the label, not the display name of it.

Quickbook No apptoken detected; (PHP)errorCode=003102; statusCode=401

I am new in quickbooks API implementation, I am always getting one error No apptoken detected; errorCode=003102; statusCode=401 when I am doing API call for customer add etc.
I am giving my steps, please look over that.
My sandbox info like that
Consumer Key: qyprdffbBBInX4a82jG73Mreyy96tC
Consumer Secret: IgpJzJrYvb9FmmdB7A0ECDGHG62Cp7dqVWjfMTvU
Access Token: qyprdlo3WrK0KhGZMTeA857AuKiVy2eaAmpXsRvG3jycYaMQ
Access Token Secret: TdPGpcUI8AiAdWFiCyb8jAAygH16bzU7VRGaspx4
I am Using PHP.
First I have generated oauth_signature.
$URL =
rawurlencode('https://sandbox-quickbooks.api.intuit.com/v3/company/408554291/customer');
$method = 'POST'; $parameter =
rawurlencode('oauth_consumer_key=qyprdffbBBInX4a82jG73Mreyy96tC&oauth_nonce=BlyqIBbv3R4T0P4qglAv1RjoYisMZk1449659733&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1449659733&oauth_token=qyprdlo3WrK0KhGZMTeA857AuKiVy2eaAmpXsRvG3jycYaMQ&oauth_version=1.0');
$ukey =
rawurlencode('IgpJzJrYvb9FmmdB7A0ECDGHG62Cp7dqVWjfMTvU').'&'.rawurlencode('TdPGpcUI8AiAdWFiCyb8jAAygH16bzU7VRGaspx4');
$hasmac = hash_hmac("sha1", $BaseURL,$ukey,1);
and My oauth_signature is jZ8JhECy/e0kpPbUdZp/o/EUC7U=
When i call API with this oauth_signature, i am getting Error 'No apptoken detected; errorCode=003102; statusCode=401'
My CURL call like this
curl -X POST -H 'Content-Type: application/json, Authorization: OAuth
oauth_token=qyprdlo3WrK0KhGZMTeA857AuKiVy2eaAmpXsRvG3jycYaMQ,oauth_consumer_key=qyprdffbBBInX4a82jG73Mreyy96tC,oauth_signature_method=HMAC-SHA1,oauth_timestamp=1449659733,oauth_version=1.0,oauth_nonce=BlyqIBbv3R4T0P4qglAv1RjoYisMZk1449659733,oauth_signature=jZ8JhECy/e0kpPbUdZp/o/EUC7U='
-d '{"data": [{"BillAddr":{"Line1":"86 A Topsia","City":"Kolkata","Country":"India","CountrySubDivisionCode":"WB","PostalCode":"700102"},"Title":"Mr.","GivenName":"ApurbaK","MiddleName":"Kumar","FamilyName":"ApurbaK","PrimaryPhone":{"FreeFormNumber":"564545465"},"PrimaryEmailAddr":{"Address":"apurbahazra12#navsoft.in"}}]}'
'https://sandbox-quickbooks.api.intuit.com/v3/company/408554291/customer'
Please look over that.
Thanks,
Apurba
Firstly, you don't want to be doing this yourself -- use a library. OAuth is complex, and implementing it yourself is going to be a hairy process, rife with errors.
Go grab a library:
https://github.com/consolibyte/quickbooks-php
Follow the quick-start guide linked there, and benefit from the examples:
https://github.com/consolibyte/quickbooks-php/tree/master/docs/partner_platform/example_app_ipp_v3
With that said, if you do decide to write it yourself, make sure you follow the OAuth spec:
https://www.rfc-editor.org/rfc/rfc5849
So far, the issues I immediately see with your implementation are:
You can't hard-code the timestamp like this: &oauth_timestamp=1449659733 The timestamp should be ever-changing, and set to the currenty timestamp.
You can't hard-code a nonce like this: &oauth_nonce=BlyqIBbv3R4T0P4qglAv1RjoYisMZk1449659733 The nonce has to change with every single request so this is going to fail after your first request.
You haven't normalized your request parameters / sorted them, per the spec.
This is the incorrect way to specify multiple headers with cURL: -H 'Content-Type: application/json, Authorization: OAuth .... Please see the cURL docs: http://curl.haxx.se/docs/manpage.html#-H
In the code you posted, you haven't actually set $BaseURL anywhere, so right now you're signing an empty string (unless you forgot to paste some code somewhere?)
What is $ukey set to? It doesn't appear to be defined in your code anywhere (did you forget to paste some code in?)

Resources