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 - checkbox

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

Related

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"
}
]
}
]
}

Microsoft graph API --> To see if the message is a reply

I am using the graph API to retrieve the mail from mail folders. For example I got a mail, I will change or edit the subject line and store the conversation id for future use. if I got the reply mail for the same email chain I got different conversation id. How to handle this, I need to find out the reply mail.
"subject": "Test",
"conversationId": "AAQkADU1YWM2MjMyLTVkOGQtNDdiMy05YWM4LTE4NTNlYzg1ZWRiNwAQADofdbq8_JtJkY8M5wnunlU=",
reply msg:
"subject": "Re: Test1",
"conversationId": "AAQkADU1YWM2MjMyLTVkOGQtNDdiMy05YWM4LTE4NTNlYzg1ZWRiNwAQAHu3pWtxNmBFjdfyjYaVGKc=",
I need to find this ts reply message.
I'd suggest you use the In-Reply-To header https://wesmorgan.blogspot.com/2012/07/understanding-email-headers-part-ii.html in that way you can relate multiple replies (to the same replied to message) in a Message chain etc. You can either get the In-Reply-To header by requesting the InternetHeaders https://learn.microsoft.com/en-us/graph/api/resources/internetmessageheader?view=graph-rest-1.0 (this will return all the headers) or you can request the extended property to just get that one property eg
https://graph.microsoft.com/v1.0/users('user#domain.com')/MailFolders('Inbox')/messages/?$select=ReceivedDateTime,Sender,Subject,IsRead,inferenceClassification,InternetMessageId,parentFolderId,hasAttachments,webLink&$Top=10&$expand=SingleValueExtendedProperties($filter=(Id%20eq%20'String%200x1042'))

With GMail API, Is it possible to insert message to INBOX?

With GMail API, it is possible to insert a message to inbox with https://developers.google.com/gmail/api/v1/reference/users/messages/insert
The problem I face is when using insert, messages do not appear in INBOX and user has to go to 'All Mail' in order to see them.
What is the best way to insert messages into INBOX? Import?
You can set the request body based from the documentation:
Request Body: {
"raw": "string" // required property
"labelIds": "["INBOX"]" // add this optional property
"threadId": "string"
}
Here's the complete list for Type of Message labels.

Testing Facebook Messenger Opt-in callback

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

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.

Resources