撤消消息

您的代理可以撤消已发送但尚未送达的消息。最好在未传送的消息过期之前将其撤消。时间安排取决于代理的应用场景。例如,您可能会在 10 分钟后撤消一次性密码消息,但在特定失效日期撤消促销消息。为了及时递送消息,请务必及时撤消消息,以便您通过短信等备用路线发送消息。

您可以通过以下两种方式撤消消息:

  • 发送撤消请求以触发撤消。200 OK 响应确认消息已撤消并从用户的队列中删除。“404 Not Found”响应表示撤消尝试失败,因为消息已送达。

  • 设置消息失效时间,以便在适当的时间自动撤消消息。RBM 平台会在消息过期时通知您的代理,并确认消息是否已成功撤消。如需了解详情,请参阅服务器生成的事件

在极少数情况下,撤消可能会失败。例如,您的代理可能会在 RBM 平台正在传送消息时尝试撤消该消息。如果撤消失败,请检查网络钩子中是否存在 DELIVERED 事件。如果消息尚未送达,您可以发送新的撤消请求,然后将消息改用其他渠道(例如短信)发送,以便及时送达。

示例

以下代码会发送撤消请求。如需了解格式设置和值信息,请参阅 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);
});
此代码摘自 RBM 示例代理

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();
}
此代码摘自 RBM 示例代理

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)
此代码摘自 RBM 示例代理

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");
此代码摘自 RBM 示例代理