事件

在下列範例中,rbm_api_helper.js (不適用於 Python) 假設您正在處理的檔案位於主要應用程式資料夾下方的一個目錄。您可能需要根據專案設定調整位置。

讀取事件

讀取事件可讓使用者瞭解代理程式已收到訊息,並確信 RCS Business 平台已傳送訊息。下列程式碼會使用用戶端程式庫,將讀取事件傳送至裝置。

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Send the device an event to indicate that messageId has been read
rbmApiHelper.sendReadMessage('+12223334444', messageId);
這段程式碼摘錄自 RBM 範例服務專員

Java

import com.google.rbm.RbmApiHelper;


// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper();

// Send the device an event to indicate that messageId has been read
rbmApiHelper.sendReadMessage(messageId, "+12223334444");
這段程式碼摘錄自 RBM 範例服務專員

Python

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service

# Send the device an event to indicate that message_id was read
rbm_service.send_read_event('+12223334444', message_id)
這段程式碼摘錄自 RBM 範例服務專員

C#

using RCSBusinessMessaging;


// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

// Send the device an event to indicate that messageId has been read
rbmApiHelper.SendReadMessage(messageId, "+12223334444");
這段程式碼摘錄自 RBM 範例服務專員

輸入事件

輸入事件 可讓使用者知道服務專員正在撰寫訊息。下列程式碼會使用用戶端程式庫,將輸入事件傳送至裝置。

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Send the device an event to indicate that the agent is typing
rbmApiHelper.sendIsTypingMessage('+12223334444', function() {
    console.log('Typing event sent!');
});
這段程式碼摘錄自 RBM 範例服務專員

Java

import com.google.rbm.RbmApiHelper;


// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper();

// Send the device an event to indicate that the agent is typing
rbmApiHelper.sendIsTypingMessage("+12223334444");
這段程式碼摘錄自 RBM 範例服務專員

Python

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service

# Send the device an event to indicate that the agent is typing
rbm_service.send_is_typing_event('+12223334444')
這段程式碼摘錄自 RBM 範例服務專員

C#

using RCSBusinessMessaging;


// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

// Send the device an event to indicate that the agent is typing
rbmApiHelper.SendIsTypingMessage(messageId, "+12223334444");
這段程式碼摘錄自 RBM 範例服務專員