new_releases 更新:查看
版本说明,了解新功能和产品动态。
撤消消息
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您的代理可以撤消已发送但尚未送达的消息。最好在未传送的消息过期之前将其撤消。时间安排取决于代理的应用场景。例如,您可能会在 10 分钟后撤消一次性密码消息,但在特定失效日期撤消促销消息。为了及时递送消息,请务必及时撤消消息,以便您通过短信等备用路线发送消息。
您可以通过以下两种方式撤消消息:
在极少数情况下,撤消可能会失败。例如,您的代理可能会在 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 示例代理。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-01。
[null,null,["最后更新时间 (UTC):2025-08-01。"],[[["\u003cp\u003eAgents can revoke undelivered messages, with the optimal timing for revocation depending on the message's context, such as revoking an OTP after ten minutes versus a promotional message on a specific date.\u003c/p\u003e\n"],["\u003cp\u003eMessage revocation can be initiated through a revocation request, which triggers a 200 OK response from the RBM platform without guaranteeing successful revocation; success results in the message being deleted from the user's queue.\u003c/p\u003e\n"],["\u003cp\u003eSetting a message expiration time enables automatic revocation, with the RBM platform confirming whether the message was successfully revoked upon expiration.\u003c/p\u003e\n"],["\u003cp\u003eIn the rare event that revocation fails, an agent can check for a \u003ccode\u003eDELIVERED\u003c/code\u003e event and resend a revocation request before routing the message via an alternative channel, like SMS, to ensure delivery.\u003c/p\u003e\n"],["\u003cp\u003eThe code examples show how to revoke a message through a revocation request in cURL, Node.js, Java, Python, and C#, demonstrating the practical application of message revocation.\u003c/p\u003e\n"]]],[],null,["# Revoke messages\n\nYour agent can revoke a message that has been sent but not yet delivered. It's\nbest to revoke undelivered messages before they go stale. The timing depends on\nyour agent's use case. For example, you might revoke an OTP message after ten\nminutes but revoke a promotional message on a specific expiration date. For\ntimely message delivery, be sure to revoke messages in time for you to send them\nby an alternate route like SMS.\n\nThere are two ways to revoke a message:\n\n- [Send a revocation request](/business-communications/rcs-business-messaging/guides/build/messages/revoke#example)\n to trigger the revocation. The 200 OK response confirms that the message was\n revoked and deleted from the user's queue. A 404 Not Found response means\n the revocation attempt has failed because the message was delivered.\n\n- [Set a message expiration](/business-communications/rcs-business-messaging/guides/build/messages/send#expire)\n to automatically revoke the message at the appropriate time. The RBM\n platform notifies your agent when the message has expired and confirms\n whether or not it was successfully revoked. See [Server-generated events](/business-communications/rcs-business-messaging/guides/build/events#server-generated_events)\n for more information.\n\nRevocation could fail on rare occasions. For example, your agent may attempt to\nrevoke a message while the RBM platform is in the process of delivering it. If\nrevocation fails, check for a [`DELIVERED` event](/business-communications/rcs-business-messaging/guides/build/events#delivered)\nat your webhook. If the message hasn't been delivered, you can send a new\n[revocation request](/business-communications/rcs-business-messaging/guides/build/messages/revoke#example)\nand then route the message to an alternate channel like SMS for timely delivery.\n\nExample\n-------\n\nThe following code sends a revocation request. For formatting and value\ninformation, see\n[`phones.agentMessages.delete`](/business-communications/rcs-business-messaging/reference/rest/v1/phones.agentMessages/delete). \n\n### cURL\n\n```console\ncurl -X DELETE \"https://\u003cvar fieldvalues=\"asia,europe,us\" translate=\"no\"\u003eREGION\u003c/var\u003e-rcsbusinessmessaging.googleapis.com/v1/phones/\u003cvar translate=\"no\"\u003ePHONE_NUMBER\u003c/var\u003e/agentMessages/\u003cvar fieldlabel=\"Message ID\" translate=\"no\"\u003eMESSAGE_ID\u003c/var\u003e?agentId=\u003cvar translate=\"no\"\u003eAGENT_ID\u003c/var\u003e\" \\\n-H \"Content-Type: application/json\" \\\n-H \"User-Agent: curl/rcs-business-messaging\" \\\n-H \"`oauth2l header --json \u003cvar translate=\"no\"\u003ePATH_TO_SERVICE_ACCOUNT_KEY\u003c/var\u003e rcsbusinessmessaging`\"\n```\n\n### Node.js\n\n```javascript\n// Reference to RBM API helper\nconst rbmApiHelper = require('@google/rcsbusinessmessaging');\n\n// Stop the message associated with messageId from being delivered\nrbmApiHelper.revokeMessage('\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e', messageId, function(err, response) {\n console.log(response);\n});\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples).\n\n### Java\n\n```java\nimport com.google.rbm.RbmApiHelper;\n...\n\ntry {\n // Create an instance of the RBM API helper\n RbmApiHelper rbmApiHelper = new RbmApiHelper();\n\n // Stop the message associated with messageId from being delivered\n rbmApiHelper.revokeMessage(messageId, \"\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e\");\n} catch(Exception e) {\n e.printStackTrace();\n}\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples).\n\n### Python\n\n```python\n# Reference to RBM Python client helper and messaging object structure\nfrom rcs_business_messaging import rbm_service\n\n# Stop the message associated with message_id from being delivered\nrbm_service.revoke('\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e', message_id)\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples).\n\n### C#\n\n```c#\nusing RCSBusinessMessaging;\n...\n\n// Create an instance of the RBM API helper\nRbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,\n projectId);\n\n// Stop the message associated with messageId from being delivered\nrbmApiHelper.RevokeMessage(messageId, \"\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e\");\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples)."]]