With the Delivery Receipts feature, you can obtain information about the status of Conversations Messages sent to non-Chat Participants (i.e. SMS and WhatsApp channels).
You can verify if the Messages were sent
, delivered
or even read
(for OTT) by other Conversations Participants.
Let's get started!
Delivery Receipts are summaries that contain detailed information about the messages sent to Participants in non-Chat channels.
This feature includes information about:
Delivery Receipts can contain the following message statuses:
sent
delivered
read
failed
undelivered
An Aggregated Delivery Receipt contains a general summary of the delivery statuses of a Message to all non-Chat Participants in the Conversation.
Use aggregated receipts to represent the overall delivery status of a Message.
You can retrieve the Aggregated Delivery Receipts summaries from any Message object in a Conversation that contains non-Chat recipients. This is often enough to confirm successful delivery of the message.
1/* Retrieving Delivery Receipts (aggregated and detailed) for rendering */23const aggregatedDeliveryReceipt = message.aggregatedDeliveryReceipt;45// get amount (DeliveryAmount) of participants with particular delivery status6const deliveredReceipts = aggregatedDeliveryReceipt?.delivered;7const failedReceipts = aggregatedDeliveryReceipt?.failed;8const readReceipts = aggregatedDeliveryReceipt?.read;9const sentReceipts = aggregatedDeliveryReceipt?.sent;10const undeliveredReceipts = aggregatedDeliveryReceipt?.undelivered;11// get the amount of participants which have the status for the message12const totalReceipts = aggregatedDeliveryReceipt?.total;1314if (undeliveredReceipts !== "none") {15// some delivery problems16alert(`Out of ${totalReceipts} sent messages, ${deliveredReceipts} were delivered, ${failedReceipts} have failed.`);17}
A Detailed Delivery Receipt represents the Message delivery status to a specific non-Chat Participant in the Conversation.
Use detailed receipts when you want to show the specific recipient who didn't receive the message.
You can also get a list of the Detailed Delivery Receipts by calling the correct method on the same object. This is useful if you want to render separate sent/delivered/read statuses for specific Participants.
1// get the list of of delivery receipts2const detailedDeliveryReceipts = await message.getDetailedDeliveryReceipts();34const statusMap = {};56detailedDeliveryReceipts.map((detailedDeliveryReceipt) => {7// get status of the delivery receipts8const receiptStatus = detailedDeliveryReceipt.status;9const participantSid = detailedDeliveryReceipt.participantSid;10statusMap[participantSid] = receiptStatus;1112});
Retrieving detailed receipts is necessary for error retrieval and handling. Each detailed receipt for a message that failed will contain a Twilio error code indicating the failure reason.
If the message status is failed
or undelivered
, you can handle the error code accordingly.
Read more in the Troubleshooting Undelivered Twilio SMS Messages support article.
1/* Checking delivery receipts for errors */23// get the list of aggregated delivery receipts4const aggregatedDeliveryReceipt = message.aggregatedDeliveryReceipt;56// retrieve delivery receipt status7if (aggregatedDeliveryReceipt.failed !== "none" || aggregatedDeliveryReceipt.undelivered !== "none") {8// handle error9}1011// get the list of delivery receipts12const detailedDeliveryReceipts = await message.getDetailedDeliveryReceipts();1314detailedDeliveryReceipts.map((detailedDeliveryReceipt) => {15// check delivery receipt status16if (!detailedDeliveryReceipt.status === "undelivered" && !detailedDeliveryReceipt.status === "failed") {17return;18}1920// handle error. the error codes page: https://www.twilio.com/docs/sms/api/message-resource#delivery-related-errors21if (detailedDeliveryReceipt.errorCode === 30006) {22alert("The destination number is unable to receive this message.");23return;24}2526if (detailedDeliveryReceipt.errorCode === 30007) {27alert("Your message was flagged as objectionable by the carrier.");28}29});
Great work! You've learned the foundations of Delivery Receipts, you can continue with any of the following guides: