How do you know if a message has been succesfully sent? #39
-
When I call: I am receiving something like this in the result variable: does the "wamid" means that the message has been sent? I am asking because I just sent a large volume of messages and saved the responses to my database, but I want to know how many were succesfully sent |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 6 replies
-
The "wamid" is just the message identifier for the sent message. If you want to know if the message is sent, the message status is sent through the message webhook since it will be triggered every time the user views it. The message statuses also include failed or deleted. Below is the sample message status json sent to the webhook since the response will be dynamic changing to different objects. You can compare the "wamid" with the id field in the statuses object and then do a database update. Message status json {
"object": "whatsapp_business_account",
"entry": [
{
"id": "8856996819413533",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "",
"phone_number_id": ""
},
"statuses": [
{
"id": "wamid.gBGGFlCGg0cvAglAxydbAoy-gwNo",
"status": "sent", // delivered, failed, deleted or read
"timestamp": "",
"recipient_id": ""
}
]
},
"field": "messages"
}
]
}
]
} var changesResult = messageReceived["entry"][0]["changes"][0]["value"];
if (changesResult["statuses"] != null)
{
var messageStatus = Convert.ToString(messageReceived["entry"][0]["changes"][0]["value"]["statuses"][0]["status"]);
if (messageStatus.Equals("sent")) // one tick
{
var messageStatusReceived = JsonConvert.DeserializeObject<UserInitiatedMessageSentStatus>(Convert.ToString(messageReceived)) as UserInitiatedMessageSentStatus;
var messageStatusResults = new List<UserInitiatedStatus>(messageStatusReceived.Entry.SelectMany(x => x.Changes).SelectMany(x => x.Value.Statuses));
_logger.LogInformation(JsonConvert.SerializeObject(messageStatusResults, Formatting.Indented));
return Ok(new
{
Message = $"Message Status Received: {messageStatus}"
});
}
if (messageStatus.Equals("delivered")) // double tick
{
var messageStatusReceived = JsonConvert.DeserializeObject<UserInitiatedMessageDeliveredStatus>(Convert.ToString(messageReceived)) as UserInitiatedMessageDeliveredStatus;
var messageStatusResults = new List<UserInitiatedMessageDeliveryStatus>(messageStatusReceived.Entry.SelectMany(x => x.Changes).SelectMany(x => x.Value.Statuses));
_logger.LogInformation(JsonConvert.SerializeObject(messageStatusResults, Formatting.Indented));
return Ok(new
{
Message = $"Message Status Received: {messageStatus}"
});
}
if (messageStatus.Equals("read")) // blue tick
{
return Ok(new
{
Message = $"Message Status Received: {messageStatus}"
});
}
} |
Beta Was this translation helpful? Give feedback.
-
Thanks @gabrieldwight that is what I was looking for |
Beta Was this translation helpful? Give feedback.
-
Hey guys, and the return or result is of type Task<ActionResult> How do I get the wamid from result? thanx |
Beta Was this translation helpful? Give feedback.
-
By default, it is 1 message from the cloud API side. If you are sending messages in bulk you must create your implementation to handle batch processing and tracking their respective WAMId. |
Beta Was this translation helpful? Give feedback.
-
Yes, so after every send i grab the WAMId and save it to that record.
I will then, when my app is live, focus on the web hooks to check if the message was delivered, red, not a WhatsApp number, etc..
Get BlueMail for Android
…On 20 Feb 2024, 22:37, at 22:37, Gabriel Odero ***@***.***> wrote:
> ok, so from the Send (us using APIs) side not the Receive side
(WebHook) there should not be more than 1 Message? you see, I am also
writing code to do bulk sends:
>
> 1. Reading a CSV
> 2. Send 1 WhatsApp per line
> 3. If the message went out, i need to capture this WAMId to keep
track in the Webhook if a client is responding to my message sent..
By default, it is 1 message from the cloud API side. If you are sending
messages in bulk you must create your implementation to handle batch
processing and tracking their respective WAMId.
--
Reply to this email directly or view it on GitHub:
#39 (comment)
You are receiving this because you commented.
Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
The "wamid" is just the message identifier for the sent message. If you want to know if the message is sent, the message status is sent through the message webhook since it will be triggered every time the user views it. The message statuses also include failed or deleted. Below is the sample message status json sent to the webhook since the response will be dynamic changing to different objects. You can compare the "wamid" with the id field in the statuses object and then do a database update.
Message status json