In which case meta's whatsapp payload examples will receive with multiple element in array - facebook

Meta's whatsapp API integration and response on webhook,
https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/payload-examples
I am new to the whatsapp cloud integration and I am confused why inbound message response of webhook is too weird with nested array, in which cases facebook(meta) will give an multiple elements in nested of nested array.
Is it good way to get entry[0].changes[0].value.messages[0].text.body or I require to add loop on every case?
What are the changes we will received multiple elements?
{
"object": "whatsapp_business_account",
"entry": [{
"id": "WHATSAPP_BUSINESS_ACCOUNT_ID",
"changes": [{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": PHONE_NUMBER,
"phone_number_id": PHONE_NUMBER_ID
},
"contacts": [{
"profile": {
"name": "NAME"
},
"wa_id": PHONE_NUMBER
}],
"messages": [{
"from": PHONE_NUMBER,
"id": "wamid.ID",
"timestamp": TIMESTAMP,
"text": {
"body": "MESSAGE_BODY"
},
"type": "text"
}]
},
"field": "messages"
}]
}]
}

You can read the documentation of graph-api webhook,
https://developers.facebook.com/docs/graph-api/webhooks/getting-started#validate-payloads
Event Notifications are aggregated and sent in a batch with a maximum of 1000 updates. However batching cannot be guaranteed so be sure to adjust your servers to handle each Webhook individually.
You can also check the property-wise batch possibility in the provided link.

Related

How to properly pass the session_id to GA4 via Measurement protocol

GA4 purchase events are sent from client server via measurement protocol. But there is no session_id parameter in the queries, because of that source and medium is lost. We tried to pass the session_id parameter in MP request, but no data were received.
Example of submitted request:
{
"timestamp_micros": "1664522406546590",
"non_personalized_ads": false,
"events": [
{
"name": "purchase_balance_top_up",
"params": {
"user_id": "11111111",
"crm_id": "11111111",
"balance": 990,
"payment_method": "paymore"
}
}
],
"client_id": "1119492379.1652295143",
"session_id": "1664522264",
"user_id": "11111111"
}
Attaching a screenshot of the raw data from BigQuery on events sent by MP.
Screenshot of the raw data from BigQuery
Help, how to properly pass the session_id? Or how to make sure that events don't lose source param?
We found a solution to the problem. It's simple. The parameter "session_id" must be passed inside the array "params" of the event.
Here is an example of the correct event data array to be sent via measurement protocol:
{
"timestamp_micros": "1664522406546590",
"non_personalized_ads": false,
"events": [
{
"name": "purchase_balance_top_up",
"params": {
"user_id": "11111111",
"crm_id": "11111111",
"balance": 990,
"payment_method": "paymore",
"session_id": "1664522264"
}
}
],
"client_id": "1119492379.1652295143",
"user_id": "11111111"
}
Actually we are sending purchase events similarly with such request:
{
"client_id": "xxx.xxx",
"user_id" : "xxxx",
"non_personalized_ads": false,
"user_properties": {
"user_id_dimension": {
"value": "xxxx"
}
},
"events": [{
"name": "purchase",
"params": {
"currency": "USD",
"transaction_id": "T_12345",
"value": 12.21,
"engagement_time_msec": 10,
"session_id": "XXXXXXXXXX",
"items": [
{
"item_name": "Top-up"
}
]
}
}]
}
but we are not sending timestamp_micros. And we send 'user_id_dimension' as user property with the same value as 'user_id' parameter to observe user id further in Exploration reports. We've created user-scoped custom dimension in GA4 interface with dimension name User ID and this user property 'user_id_dimension'. Everything works

Infobip API. How to create list of list of objects by api

I would like to create custom attribute list of list of objects in Infobip by API.
I have try to sent POST but in doesn't work.
Can you give me please the example of POST request to create the list of the list.
Thx!
Off Doc: https://www.infobip.com/docs/api#customer-engagement/people/create-a-custom-attribute
Request examples:
1.{
"name": "payrollData",
"dataType": "LIST_OF_OBJECTS",
"objectSchema": {
"DATE": "DATE",
"Transactions": "LIST_OF_OBJECTS"
}
}
2.{
"name": "payrollData",
"dataType": "LIST_OF_OBJECTS",
"objectSchema": {
"DATE": "DATE",
"Transactions":{
"Input": "DECIMAL",
"Output": "DECIMAL"
}
}
}
Responses:
1.{
"errorCode": 40001,
"errorMessage": "Bad Request",
"validationErrors": [
{
"code": 501,
"message": "Custom attribute schema is invalid.",
"propertyPath": "valueSchema"
}
]
}
2.{
"requestError": {
"serviceException": {
"messageId": "BAD_REQUEST",
"text": "Bad request"
}
}
}
At this point is not possible to achieve what you are trying via using Infobip API.
The functionality for creating custom attributes is limited only to top layer and does not support nesting of the list objects.
The team in charge will include that explanation in API docs description. But, there are no plans on including additional complexity layers on this endpoint in the short future.
So generally, you can use LIST_OF_OBJECTS as described on the endpoint URL you also linked to. But you are not able to layer it furthermore.
Valid example for LIST_OF_OBJECTS usage:
{
"name": "ShoppingCartList",
"dataType": "LIST_OF_OBJECTS",
"objectSchema": {
"productName": "STRING",
"productPrice": "DECIMAL",
"productCategory": "STRING",
"productImage": "STRING"
}
}
I know it does not resolve your issue as you would have hoped for, but it is a correct answer. :)

Facebook - Get All Messages from Page

Response from request for getting messages about specific conversation are returning just IDs from the all separate messages that are contained in that conversation. So, if I want to get all of the messages from all conversation, there will be a lot of request...
Are there any solution for getting all of the messages(text from messages) from specific conversation in one request? Or any other workaround for this kind of issue?
Here is the example:
Request: XXX?fields=subject,message_count,messages -> (where XXX are id of conversation)
Response:
{
"message_count": 4,
"id": "XXX",
"messages": {
"data": [
{
"created_time": "2016-05-11T08:29:56+0000",
"id": "id1"
},
{
"created_time": "2016-05-11T08:29:54+0000",
"id": "id2"
},
{
"created_time": "2016-05-11T08:21:56+0000",
"id": "id3"
},
{
"created_time": "2016-05-09T14:04:17+0000",
"id": "id4"
}
]
}
}
I suppose you are using the conversation details endpoint; have you tried using the /messages/edge of the same endpoint?
Try to rewrite your request as:
XXX/messages?fields=message,subject,to

Facebook realtime.. How are different objects batched together

Facebook realtime docs specify that the callback data is of the following format
{
"object": "user",
"entry": [
{
"uid": 1335845740,
"changed_fields": [
"name",
"picture"
],
"time": 232323
}, {
"uid": 1234,
"changed_fields": [
"friends"
],
"time": 232325
}]}
If two different objects, say 'user' and 'page' are to be sent back, does facebook
Batch them together?
Send them separately?
Different objects are sent in different requests. But if there are many user requests then it will batch those user requests and send it. And also you can have different end points for user and page. The format of page request is also different.
It looks something like this
{
"object": "page",
"entry": [
{
"id": "408518775908252",
"time": 1360643280,
"changes": [
{
"field": "feed",
"value": {
"item": "like",
"verb": "add",
"user_id": 5900878
}
}
]
}
]
}

Getting poll results from Facebook Graph

How can I (if I can) get the results of a poll/question from Facebook graph? Currently I get back something similar to what is below:
"data": [
{
"id": "12345_12345",
"from": {
"name": "My Company Name",
"category": "Category",
"id": "12345"
},
"story": "This is my question",
"icon": "https://s-static.ak.facebook.com/rsrc.php/v1/yy/r/pz5wRf7MB0H.png",
"privacy": {
"description": "Public",
"value": "EVERYONE"
},
"type": "question",
"object_id": "12345",
"application": {
"name": "Questions",
"id": "12345"
},
"created_time": "2012-04-25T12:23:03+0000",
"updated_time": "2012-04-25T12:23:03+0000",
"comments": {
"count": 0
}
}
Can I get more information back about this question? I'm currently using PHP + CURL to get the feed.
Thanks!
From the looks of it, you have queried for the specific post (post-id:12345_12345) : https://graph.facebook.com/12345_12345 .
To get to the question's data we have to query for the question id that is given in this post's data itself:
"type": "question",
"object_id": "12345",
from here we have the question's id, i.e object_id:12345. Using this id we can get the question's info, so query url is : https://graph.facebook.com/12345.
In the question's returned info, we'll also have the options of the poll, it'll be a field named options. Each option's info will be given within this field, and each option has a votes field, which will tell you the number of votes that option received. So you'll have the results of the poll.
Use the graph explorer, to test these things, before you code them. And do read the documentation links to know more about questions.
In general the metadata=1 GET parameter tells you if there is more related data available.