您的代理可以撤消已发送但尚未送达的消息。最好在未送达的消息过期之前撤消它们。具体时间取决于代理的使用场景。例如,您可能在十分钟后撤消一次性密码 (OTP) 消息,但在特定失效日期撤消促销消息。为了及时送达消息,请务必及时撤消消息,以便您通过短信等替代渠道发送消息。
您可以通过以下两种方式撤消消息:
发送撤消请求 以触发撤消。200 OK 响应确认消息已撤消并从用户的队列中删除。404 Not Found 响应表示撤消尝试失败,因为消息已送达。
设置消息失效时间 以便在适当的时间自动撤消消息。RBM 平台会在消息过期时通知您的代理,并确认消息是否已成功撤消。如需了解详情,请参阅服务器生成的事件 。
在极少数情况下,撤消可能会失败。例如,您的代理可能会在 RBM 平台正在送达消息时尝试撤消消息。如果
撤消失败,请在 Webhook 中检查 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); });
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(); }
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)
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");