イベント

次の例では、rbm_api_helper.js(Python では使用されません)は、作業中のファイルがメインアプリ フォルダの 1 つ下のディレクトリにあることを前提としています。プロジェクトの構成によっては、ロケーションの調整が必要になることがあります。

イベントを読み取る

既読イベントは、エージェントがメッセージを受信したことをユーザーに知らせ、RCS for 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 サンプル エージェントからの抜粋です。