如果訊息已傳送但尚未送達,服務專員可以撤銷訊息。最好在未送達的訊息過期前撤銷。時間取決於代理程式的用途。舉例來說,您可能會在十分鐘後撤銷一次性密碼訊息,但會在特定到期日撤銷宣傳訊息。為確保訊息能及時送達,請務必及時撤銷訊息,以便透過簡訊等替代管道傳送訊息。
撤銷訊息的方法有兩種:
傳送撤銷要求,觸發撤銷程序。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");