撤銷訊息

您的服務專員可撤銷已傳送但尚未傳送的訊息。建議您在過時前撤銷未傳送的訊息。時間取決於代理程式的用途。例如,您可以在十分鐘後撤銷動態密碼訊息,但在指定到期日撤銷宣傳訊息。為了即時傳送訊息,請務必及時撤銷訊息,以便透過其他替代方式 (例如簡訊) 傳送訊息。

撤銷訊息的方式有兩種:

  • 傳送撤銷要求以觸發撤銷要求。當 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" \
-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('../libs/rbm_api_helper');

// 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.samples.lib.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 範例代理程式摘錄的內容。