Revoke messages

Your agent can revoke a message that has been sent but not yet delivered. It's best to revoke undelivered messages before they go stale. The timing depends on your agent's use case. For example, you might revoke an OTP message after ten minutes but revoke a promotional message on a specific expiration date. For timely message delivery, be sure to revoke messages in time for you to send them by an alternate route like SMS.

There are two ways to revoke a message:

  • Send a revocation request to trigger the revocation. When the RBM platform receives a revocation request, the platform returns 200 OK. The 200 OK response doesn't confirm whether or not the message was revoked. If the revocation was successful, the RBM platform stops trying to deliver the message, and it's deleted from the user's queue.

  • Set a message expiration to automatically revoke the message at the appropriate time. The RBM platform notifies your agent when the message has expired and confirms whether or not it was successfully revoked. See Server-generated events for more information.

Revocation could fail on rare occasions. For example, your agent may attempt to revoke a message while the RBM platform is in the process of delivering it. If revocation fails, check for a DELIVERED event at your webhook. If the message hasn't been delivered, you can send a new revocation request and then route the message to an alternate channel like SMS to ensure timely delivery.

Example

The following code sends a revocation request. For formatting and value information, see phones.agentMessages.delete.

cURL

curl -X DELETE "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages/MESSAGE_ID?agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Stop the message associated with messageId from being delivered
rbmApiHelper.revokeMessage('+12223334444', messageId, function(err, response) {
   console.log(response);
});
This code is an excerpt from an RBM sample agent.

Java

import com.google.rbm.RbmApiHelper;
…

try {
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();

   // Stop the message associated with messageId from being delivered
   rbmApiHelper.revokeMessage(messageId, "+12223334444");
} catch(Exception e) {
   e.printStackTrace();
}
This code is an excerpt from an RBM sample agent.

Python

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service

# Stop the message associated with message_id from being delivered
rbm_service.revoke('+12223334444', message_id)
This code is an excerpt from an RBM sample agent.

C#

using RCSBusinessMessaging;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

// Stop the message associated with messageId from being delivered
rbmApiHelper.RevokeMessage(messageId, "+12223334444");
This code is an excerpt from an RBM sample agent.