イベントを送信する

エージェントは、ユーザーのデバイスにステータス イベントを送信して、人間の操作をシミュレートします。ユーザーには、これらのイベントは開封確認または入力中のインジケーターとして表示され、メッセージが処理されていることを確認できます。

書式設定と値のオプションについては、phones.agentEvents リファレンスをご覧ください。

エージェントが RBM プラットフォームから受信する Webhook イベントの詳細については、イベントを受信するをご覧ください。

エージェントが READ イベントを送信する

ユーザーには、このイベントは特定のメッセージの既読確認として表示されます。RBM プラットフォームがメッセージを配信し、エージェントがメッセージを処理していることをユーザーに知らせます。

次のコードは、一致する messageId を含むメッセージの READ イベントを送信します。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentEvents?eventId=EVENT_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`" \
-d "{
  'eventType': 'READ',
  'messageId': 'MESSAGE_ID'
}"

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 サンプル エージェントからの抜粋です。

エージェントが IS_TYPING イベントを送信する

ユーザーには、このイベントは入力インジケーターとして表示され、エージェントがメッセージを作成していることを知らせます。入力インジケーターは、しばらくすると(約 20 秒後)、またはユーザーのデバイスがエージェントから新しいメッセージを受信すると、期限切れになります。エージェントは、複数の IS_TYPING イベントを送信して、入力インジケーターの有効期限タイマーをリセットできます。

次のコードは IS_TYPING イベントを送信します。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentEvents?eventId=EVENT_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`" \
-d "{
  'eventType': 'IS_TYPING',
}"

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 サンプル エージェントからの抜粋です。