撤銷訊息

您的服務專員可以撤銷已傳送但尚未送達的訊息。建議您在未送達的郵件過期前撤銷。時間點取決於您的服務機器人用途。舉例來說,您可以選擇在十分鐘後撤銷 OTP 訊息,但在特定到期日撤銷宣傳訊息。為確保訊息能及時傳送,請務必及時撤銷訊息,以便透過簡訊等其他管道傳送。

撤銷訊息的方法有兩種:

  • 傳送撤銷要求,即可觸發撤銷程序。當 RBM 平台收到撤銷要求時,平台會傳回 200 OK。200 OK 回應不會確認訊息是否已撤銷。如果撤銷成功,RBM 平台就會停止嘗試傳送訊息,並從使用者的佇列中刪除該訊息。

  • 設定訊息到期日,即可在適當時間自動撤銷訊息。當訊息到期時,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);
});
以下程式碼節錄自 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 範例服務專員