Subscribe to Webhooks to get notifications about messages your business receives and customer profile updates.
Whenever a trigger event occurs, the WhatsApp Business Platform sees the event and sends a notification to a Webhook URL you have previously specified. You can get two types of notifications:
Every time a new message is received the event OnMessageReceived is called, where you can access to the content of the Message and mark the message as read.
Find below an example, when a new text message is received, it's echoed to user who sent it.
void OnWhatsAppMessageReceived(TObject *Sender, const TsgcWhatsApp_Receive_Message *aMessage, ref bool aMarkAsRead)
{
if (aMessage->Contacts->Count > 0)
{
string vTo = aMessage->Contacts->Contact[0]->WaID;
if (aMessage->Messages->Count > 0)
{
if (aMessage->Messages->_Message[0]->_Type = wapmrtText)
{
vText = "ECHO ==> " + aMessage->Messages->_Message[0]->Text->Body;
WhatsApp->SendMessageText(vTo, vText);
aMarkAsRead = true;
}
}
}
}
The WhatsApp Business Platform sends notifications to inform you of the status of the messages between you and users. When a message is sent successfully, you receive a notification when the message is sent, delivered, and read. The order of these notifications in your app may not reflect the actual timing of the message status. View the timestamp to determine the timing, if necessary.
Every time a new status is received, the event OnMessageSent is called.
void OnWhatsAppMessageSent(TObject *Sender, const TsgcWhatsApp_Receive_Message *aMessage, TsgcWhatsAppSendMessageStatusType aStatus)
{
string vPhone := aMessage.MetaData.DisplayPhoneNumber
if (aStatus = wapsmstSent) {
DoLog("Message to " + vPhone + " sent.");
} else if (aStatus = wapsmstDelivered) {
DoLog("Message to " + vPhone + " delivered.");
} else if (aStatus = wapsmstRead) {
DoLog("Message to " + vPhone + " read.");
} else {
DoLog("Message to " + vPhone + " unknown status.");
}
}