イベント

イベントは、エージェントが送受信できる通知です。イベントには次の 3 種類があります。

サーバーで生成されたイベント

RBM プラットフォームは、メッセージの有効期限などのサーバーレベルの更新をエージェントに通知するイベントを送信します。

書式設定と値のオプションについては、ServerEvent をご覧ください。

メッセージの有効期限が切れており、取り消しに成功しました

メッセージは有効期限が切れており、正常に取り消されました。このイベントは、フォールバック メッセージ戦略のトリガーとして適しています。

{
  "phoneNumber": [phone number of recipient that the original message was intended for] ,
  "messageId": [RCS message ID of the message],
  "agentId": [bot ID],
  "eventType": "TTL_EXPIRATION_REVOKED",
  "eventId": [unique ID generated by the RBM platform],
  "sendTime": [time at which the server sent this event]
}

メッセージの有効期限が切れているため、取り消しに失敗しました

メッセージは期限切れになりましたが、取り消されていません。

{
  "phoneNumber": [phone number of recipient that the original message was intended for] ,
  "messageId": [RCS message ID of the message],
  "agentId": [bot ID],
  "eventType": "TTL_EXPIRATION_REVOKE_FAILED",
  "eventId": [unique ID generated by the RBM platform],
  "sendTime": [time at which the server sent this event]
}

メッセージの配信は保証されません。

  • メッセージが配信されている場合は、Webhook で DELIVERED イベントを受け取ります。
  • メッセージが配信されなかった場合は、取り消し API を使用して取り消しリクエストを送信します。

OTP や不正行為のアラートなど、時間的制約のあるメッセージの場合は、ユーザーにメッセージが重複する場合でも、SMS などの代替チャネルを使用してメッセージを送信することをおすすめします。

ユーザー生成イベント

ユーザー メッセージや機能チェックと同様に、エージェントはユーザー イベントを JSON として受信します。

書式設定と値のオプションについては、UserEvent をご覧ください。

ユーザーがエージェントのメッセージを受信する

このイベントは、メッセージが配信されたことを示します。

{
  "senderPhoneNumber": "PHONE_NUMBER",
  "eventType": "DELIVERED",
  "eventId": "EVENT_ID",
  "messageId": "MESSAGE_ID",
  "agentId": "AGENT_ID"
}

ユーザーがエージェント メッセージを読む

このイベントは、メッセージが開封または確認されたことを示します。

{
  "senderPhoneNumber": "PHONE_NUMBER",
  "eventType": "READ",
  "eventId": "EVENT_ID",
  "messageId": "MESSAGE_ID",
  "agentId": "AGENT_ID"
}

ユーザーが入力を開始する

このイベントは、ユーザーが入力中であることを示します。

{
  "senderPhoneNumber": "PHONE_NUMBER",
  "eventType": "IS_TYPING",
  "eventId": "EVENT_ID",,
  "agentId": "AGENT_ID"
}

ユーザーがテキスト メッセージを送信する

{
  "senderPhoneNumber": "PHONE_NUMBER",
  "text": "Hi",
  "eventId": "EVENT_ID",
  "agentId": "AGENT_ID"
}

ユーザーがファイルを送信

{
  "senderPhoneNumber": "PHONE_NUMBER",
  "userFile": {
    "payload": {
      "mimeType": "image/gif",
      "fileSizeBytes": 127806,
      "fileUri": "https://storage.googleapis.com/copper_test/77ddb795-24ad-4607-96ae-b08b4d86406a/d2dcc67ab888d34ee272899c020b13402856f81597228322079eb007e8c9",
      "fileName": "4_animated.gif"
    }
  },
  "eventId": "EVENT_ID",,
  "agentId": "AGENT_ID"
}

ユーザーが返信の候補をタップする

ユーザーが返信の候補をタップすると、エージェントは返信のポストバック データとテキストを含むイベントを受け取ります。

{
  "senderPhoneNumber": "PHONE_NUMBER",
  "eventId": "EVENT_ID",
  "agentId": "AGENT_ID",
  "suggestionResponse": {
    "postbackData": "postback_1234",
    "text": "Hello there!"
  }
}

ユーザーが候補となるアクションをタップ

ユーザーが提案されたアクションをタップすると、エージェントはアクションのポストバック データを含むイベントを受け取ります。

{
  "senderPhoneNumber": "PHONE_NUMBER",
  "eventId": "EVENT_ID",
  "agentId": "AGENT_ID",
  "suggestionResponse": {
    "postbackData": "postback_1234"
  }
}

エージェントによって生成されたイベント

エージェントはイベントを送信して人間の操作をシミュレートし、エージェントがメッセージに対応していることをユーザーに伝えます。ユーザーに対しては、イベントが会話内に通知として表示されます。

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

エージェントが READ イベントを送信します。

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

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

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentEvents?eventId=EVENT_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('../libs/rbm_api_helper');

// Send the device an event to indicate that messageId has been read
rbmApiHelper.sendReadMessage('+12223334444', messageId);
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.rbm.samples.lib.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" \
-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('../libs/rbm_api_helper');

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