事件

在以下範例中,rbm_api_helper.js (不供 Python 使用) 會假設您正在使用的檔案位於主應用程式資料夾下方一個目錄。視專案設定而定,您可能需要調整位置。

讀取事件

讀取事件可讓使用者知道代理程式已收到訊息,並讓他們放心,RBM 平台已傳送訊息。以下程式碼會將讀取事件傳送至裝置,並使用用戶端程式庫。

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 範例服務專員