メッセージを送信する

RBM エージェントは、メッセージを送受信してユーザーと通信します。エージェントは、ユーザーにメッセージを送信するために、RCS Business Messaging API にメッセージ リクエストを送信します。1 つのリクエストには、テキスト、リッチカード、画像、動画、返信候補、アクション候補を含めることができます。

デバイスが RCS に対応していない、または RCS が有効になっていない場合、RBM プラットフォームは 404 エラーを返します。この場合、インフラストラクチャで定義されたフォールバック メソッドを使用してユーザーに連絡を試みます。

エージェントがまだリリースされていないネットワークまたは RCS トラフィックが有効になっていないネットワークで RCS ユーザーにメッセージを送信すると、RBM プラットフォームは 403 エラーを返します。

ユーザーのデバイスでサポートされていない機能を含むメッセージを送信すると、RBM プラットフォームはエラーを返してメッセージを配信しません。

マルチチャネル メッセージ戦略の一環として、妥当な時間内に配信されなかったメッセージを取り消し、別のチャネルで送信することをおすすめします。事前定義された時刻にメッセージを自動的に取り消すには、メッセージの有効期限を設定します。

相手がオフラインになっています

受信者がオフラインの場合でも、RBM プラットフォームは配信用のメッセージを受け入れます。200 OK レスポンスが返され、RBM プラットフォームはメッセージを保持し、30 日間再配信を試みます。RBM にメッセージを再送信するよう依頼する必要はありません。

RBM では、送信されなかったメッセージは送信から 30 日後に削除されます。

エージェントのユースケースによっては、この 30 日間のタイムアウトの前に未配信のメッセージを取り消すことをおすすめします。取り消しを行うと、オフラインのユーザーがオンラインに戻ったときに古いメッセージを受信しないようにできます。メッセージを取り消す方法は複数あります。

メッセージの有効期限を設定する

エージェントのメッセージは時間に依存していますか?たとえば、OTP は短時間しか有効ではありません。期間限定特典は有効期限が切れます。予約日を過ぎると、予約リマインダーは関連性がなくなります。タイムリーで関連性の高いメッセージを送信できるように、メッセージの有効期限を設定します。これにより、オフラインのユーザーがオンラインに戻ったときに古いコンテンツを受信するのを防ぐことができます。有効期限は、フォールバック メッセージング戦略を呼び出して、ユーザーが必要な情報を時間どおりに受け取るための良いきっかけにもなります。

メッセージの有効期限を設定するには、エージェント メッセージに次のいずれかのフィールドを指定します。

  • expireTime: メッセージが期限切れになる正確な時刻(UTC)。
  • ttl(存続時間): メッセージが期限切れになるまでの時間。

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

メッセージの有効期限が切れると、RBM プラットフォームはメッセージの配信を停止し、メッセージは自動的に取り消されます。ただし、まれに失敗することがあります。たとえば、RBM プラットフォームがメッセージを配信している間に、API が取り消しをトリガーする可能性があります。期限切れのメッセージが正常に取り消されたかどうかを確認するため、RBM は Webhook に通知イベントを送信します。

ttlexpireTime の最大値は、メッセージの送信後 15 日です。

メッセージ サイズの上限

文字列化された AgentMessage 全体の最大サイズは 250 KB です。リッチカードなどのメディアはこのサイズ制限にカウントされます。メッセージのテキスト部分には 3,072 文字の上限があります。

RBM 経由で送信できるファイルの最大サイズは 100 MB です。1 つの RBM メッセージに添付できる PDF ファイルまたはメディア ファイルは 1 つのみです。詳しくは、メディアと PDF ファイルをご覧ください。

テキスト

最もシンプルなメッセージはテキストで構成されます。テキスト メッセージは、ビジュアル、複雑な操作、レスポンスなしで情報を伝達するのに最適です。

次のコードは、テキスト メッセージを送信します。形式と値のオプションについては、phones.agentMessages.create をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'text': 'Hello, world!'
  }
}"

Node.js

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

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
};

// Send a simple message to the device
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.rbm.RbmApiHelper;


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

   // Send simple text message to user
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444"
   );
} catch(Exception e) {
   e.printStackTrace();
}
このコードは、RBM サンプル エージェントからの抜粋です。

Python

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

# Create a simple RBM text message
message_text = messages.TextMessage('Hello, world!')

# Send text message to the device
messages.MessageCluster().append_message(message_text).send_to_msisdn('+12223334444')
このコードは、RBM サンプル エージェントからの抜粋です。

C#

using RCSBusinessMessaging;


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

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
);
このコードは、RBM サンプル エージェントからの抜粋です。

基本的なメッセージの内容 - SMS の転換

携帯通信会社は、SMS メッセージを RBM に移行するための課金モデルを導入しています。最大 160 個の UTF-8 文字を含む RBM メッセージは、基本メッセージと呼ばれます。

基本メッセージを送信するリクエストを作成する際は、文字は 1 バイト(UTF-8)としてカウントされることに注意してください。絵文字やマルチバイト文字セットなどの特殊文字を含むメッセージを送信する場合、各文字は 2 つの UTF-8 文字としてカウントされます。

ボックスにテキストを入力して、その長さをチェックします。

ユーザー確認用のワンタイム パスワード

RBM を使用して SMS Retriever API でユーザーの自動確認用のワンタイム パスワード(OTP)を送信できます。SMS Retriever と関連 API の詳細については、SMS Retriever のドキュメントをご覧ください。SMS Retriever API に登録されているアプリでの自動ユーザー確認の詳細については、こちらのフローチャートをご覧ください。

確認プロセス中、SMS Retriever API は RBM メッセージをリッスンします。このメッセージには、OTP とアプリを識別するハッシュを含める必要があります。ハッシュがアプリと一致すると、OTP が抽出され、ユーザーの自動確認のためにアプリに転送されます。

ユーザー確認用の RBM テキスト メッセージの例: コードは <OTP> <app hash> です。

例: Your code is 123456 M8tue43FGT.

メディア ファイルと PDF ファイル

画像、動画、音声、PDF ファイルを含むメッセージを送信する場合、エージェントはコンテンツの一般公開 URL を指定するか、ファイルを直接アップロードする必要があります。メディア ファイルの場合は、ユーザーがコンテンツをクリックする前にプレビューできるように、サムネイル画像を指定することもできます。音声ファイルの場合、デフォルトの音声ウィジェットがプレースホルダとして使用されます。

RBM プラットフォームはファイルを 60 日間キャッシュに保存します。API は、エージェントがユーザーへのメッセージに含めることができるファイル ID を返します。60 日が経過すると、RBM はキャッシュからファイルを削除します。

URL でファイルを指定する場合は、contentMessage.forceRefreshfalse に設定することをおすすめします。contentMessage.forceRefreshtrue に設定すると、URL コンテンツがキャッシュに保存されている場合でも、RBM は指定された URL から新しいコンテンツを強制的に取得します。これにより、ユーザーへのメッセージ配信時間が長くなります。

ファイルサイズの推奨事項と上限については、ベスト プラクティスをご覧ください。

ファイルの URL の例

次のコードは画像を送信します。書式設定と値のオプションについては、AgentContentMessage をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'contentInfo': {
      'fileUrl': 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif',
      'forceRefresh': 'false'
    }
  }
}"

Node.js

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

let params = {
   fileUrl: 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif',
   msisdn: '+12223334444',
};

// Send an image/video to a device
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.AgentContentMessage;
import com.google.api.services.rcsbusinessmessaging.v1.model.AgentMessage;
import com.google.rbm.RbmApiHelper;


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

   String fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif";

   // create media only message
   AgentContentMessage agentContentMessage = new AgentContentMessage();
   agentContentMessage.setContentInfo(new ContentInfo().setFileUrl(fileUrl));

   // attach content to message
   AgentMessage agentMessage = new AgentMessage();
   agentMessage.setContentMessage(agentContentMessage);

   rbmApiHelper.sendAgentMessage(agentMessage, "+12223334444");
} catch(Exception e) {
   e.printStackTrace();
}
このコードは、RBM サンプル エージェントからの抜粋です。

Python

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

# Create media file attachment
file_message = messages.FileMessage('http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif')

messages.MessageCluster().append_message(file_message).send_to_msisdn('+12223334444')
このコードは、RBM サンプル エージェントからの抜粋です。

C#

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;


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

string fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif";

// Create content info with the file url
ContentInfo contentInfo = new ContentInfo
{
    FileUrl = fileUrl
};

// Attach content info to a message
AgentContentMessage agentContentMessage = new AgentContentMessage
{
    ContentInfo = contentInfo,
};

// Attach content to message
AgentMessage agentMessage = new AgentMessage
{
    ContentMessage = agentContentMessage
};

rbmApiHelper.SendAgentMessage(agentMessage, "+12223334444");
このコードは、RBM サンプル エージェントからの抜粋です。

または、files.create を使用して、メッセージを送信する前にメディアをアップロードすることもできます。

ファイルのアップロード例

次のコードは、動画ファイルとサムネイル ファイルをアップロードし、両方のファイルをメッセージで送信します。書式設定と値のオプションについては、files.createAgentContentMessage をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/upload/v1/files?agentId=AGENT_ID" \
-H "Content-Type: video/mp4" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
--upload-file "FULL_PATH_TO_VIDEO_MEDIA_FILE"

# Capture server-specified video file name from response body JSON


curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/upload/v1/files?agentId=AGENT_ID" \
-H "Content-Type: image/jpeg" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
--upload-file "FULL_PATH_TO_THUMBNAIL_MEDIA_FILE"

# Capture server-specified image file name from response body JSON


curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'uploadedRbmFile': {
      'fileName': 'SERVER-SPECIFIED_VIDEO_FILE_NAME'
        'thumbnailName': 'SERVER-SPECIFIED_THUMBNAIL_FILE_NAME'
   }
  }
}"

サポートされているメディアタイプ

RBM は次のメディア タイプをサポートしています。

メディアタイプ ドキュメントの種類 広告表示オプション リッチカードに対応
application/ogg OGG オーディオ .ogx いいえ
application/pdf PDF .pdf いいえ
audio/aac AAC オーディオ .aac いいえ
audio/mp3 MP3 音声 .mp3 いいえ
audio/mpeg MPEG オーディオ .mpeg いいえ
audio/mpg MPG オーディオ .mp3 いいえ
audio/mp4 MP4 オーディオ .mp4 いいえ
audio/mp4-latm MP4-latm オーディオ .mp4 いいえ
audio/3gpp 3GPP 音声 .3gp いいえ
image/jpeg JPEG .jpeg、.jpg はい
image/gif GIF .gif はい
image/png PNG .png はい
video/h263 H263 動画 .h263 はい
video/m4v M4V 動画 .m4v はい
video/mp4 MP4 動画 .mp4 はい
video/mpeg4 MPEG-4 動画 .mp4、.m4p はい
video/mpeg MPEG 動画 .mpeg はい
動画/webm WEBM 動画 .webm はい

返信文の候補

返信の候補は、エージェントが対応方法を把握している返信を提示することで、ユーザーを会話に誘導します。エージェントは、候補ワード リストまたはリッチカードで返信候補を送信します。

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

返信候補の最大文字数は 25 文字です。

次のコードは、2 つの返信候補を含むテキストを送信します。書式設定と値のオプションについては、SuggestedReply をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'reply': {
          'text': 'Suggestion #1',
          'postbackData': 'suggestion_1'
        }
      },
      {
        'reply': {
          'text': 'Suggestion #2',
          'postbackData': 'suggestion_2'
        }
      }
    ]
  }
}"

Node.js

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

let suggestions = [
   {
      reply: {
         'text': 'Suggestion #1',
         'postbackData': 'suggestion_1',
      },
   },
   {
      reply: {
         'text': 'Suggestion #2',
         'postbackData': 'suggestion_2',
      },
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with suggestion chips to the device
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;
import com.google.rbm.SuggestionHelper;


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

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();
   suggestions.add(
      new SuggestionHelper("Suggestion #1", "suggestion_1").getSuggestedReply());

   suggestions.add(
      new SuggestionHelper("Suggestion #2", "suggestion_2").getSuggestedReply());

   // Send simple text message to user
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
このコードは、RBM サンプル エージェントからの抜粋です。

Python

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

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggested replies for the message to send to the user
cluster.append_suggestion_chip(messages.SuggestedReply('Suggestion #1', 'reply:suggestion_1'))
cluster.append_suggestion_chip(messages.SuggestedReply('Suggestion #2', 'reply:suggestion_2'))

# Send a simple message with suggestion chips to the device
cluster.send_to_msisdn('+12223334444')
このコードは、RBM サンプル エージェントからの抜粋です。

C#

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;


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

List<Suggestion> suggestions = new List<Suggestion>
{
   // Create suggestion chips
   new SuggestionHelper("Suggestion #1", "suggestion_1").SuggestedReply(),
   new SuggestionHelper("Suggestion #2", "suggestion_2").SuggestedReply()
};

// Send simple text message with suggestions to user
rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
   suggestions
);
このコードは、RBM サンプル エージェントからの抜粋です。

推奨される措置

おすすめのアクションは、デバイスの組み込み機能を活用して、会話を通じてユーザーをガイドします。エージェントは、ユーザーに電話番号のダイヤル、地図上の場所の開く、場所の共有、URL の開く、カレンダー イベントの作成を提案できます。エージェントは、候補チップリストまたはリッチカードでおすすめのアクションを送信します。

ユーザーが候補アクションをタップすると、アクションのポストバック データを含むイベントがエージェントに届きます。

候補となるアクションの最大文字数は 25 文字です。

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

電話番号をダイヤル

ダイヤル アクションは、エージェントが指定した電話番号にダイヤルするようユーザーに指示します。電話番号には、数字(0-9)、プラス記号(+)、アスタリスク(*)、番号記号(#)のみを含めることができます。E.164 国際形式(+14155555555 など)はサポートされていますが、必須ではありません。つまり、+141555555551011 の両方が有効なエントリです。

次のコードは、ダイヤル アクションを送信します。書式設定と値のオプションについては、DialAction をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Call',
          'postbackData': 'postback_data_1234',
          'fallbackUrl': 'https://www.google.com/contact/',
          'dialAction': {
            'phoneNumber': '+15556667777'
          }
        }
      }
    ]
  }
}"

Node.js

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

// Define a dial suggested action
let suggestions = [
   {
      action: {
         text: 'Call',
         postbackData: 'postback_data_1234',
         dialAction: {
            phoneNumber: '+15556667777'
         }
      }
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with a dial suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.DialAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;


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

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating a dial suggested action
   DialAction dialAction = new DialAction();
   dialAction.setPhoneNumber("+15556667777");

   // creating a suggested action based on a dial action
   SuggestedAction suggestedAction = new SuggestedAction();
   suggestedAction.setText("Call");
   suggestedAction.setPostbackData("postback_data_1234");
   suggestedAction.setDialAction(dialAction);

   // attaching action to a suggestion
   Suggestion suggestion = new Suggestion();
   suggestion.setAction(suggestedAction);

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
このコードは、RBM サンプル エージェントからの抜粋です。

Python

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

# Create a dial suggested action
suggestions = [
      messages.DialAction('Call', 'reply:postback_data_1234', '+15556667777')
]

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggestions for the message to send to the user
for suggestion in suggestions:
    cluster.append_suggestion_chip(suggestion)

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
このコードは、RBM サンプル エージェントからの抜粋です。

C#

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;


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

// Create a dial an agent suggested action
DialAction dialAction = new DialAction
{
    PhoneNumber = "+15556667777"
};

// Creating a suggested action based on a dial action
SuggestedAction suggestedAction = new SuggestedAction
{
    Text = "Call",
    PostbackData = "postback_data_1234",
    DialAction = dialAction
};

// Attach action to a suggestion
Suggestion suggestion = new Suggestion
{
    Action = suggestedAction
};

List<Suggestion> suggestions = new List<Suggestion>
{
    suggestion
};

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
このコードは、RBM サンプル エージェントからの抜粋です。

場所を表示する

位置情報の表示アクションは、ユーザーのデフォルトの地図アプリに位置情報を表示します。位置情報は、緯度と経度で指定することも、ユーザーの現在地に基づくクエリで指定することもできます。地図アプリに表示されるピンにカスタムラベルを設定することもできます。

次のコードは、位置情報の確認アクションを送信します。形式と値のオプションについては、ViewLocationAction をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'View map',
          'postbackData': 'postback_data_1234',
          'fallbackUrl': 'https://www.google.com/maps/@37.4220188,-122.0844786,15z',
          'viewLocationAction': {
            'latLong': {
              'latitude': "37.4220188',
              'longitude': "-122.0844786'
            },
            'label': 'Googleplex'
          }
        }
      }
    ]
  }
}"

Node.js

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

// Define a view location suggested action
let suggestions = [
   {
      action: {
         text: 'View map',
         postbackData: 'postback_data_1234',
         viewLocationAction: {
            latLong: {
               latitude: 37.4220188,
               longitude: -122.0844786
            },
            label: 'Googleplex'
         }
      }
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with a view location suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.ViewLocationAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;


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

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating a view location suggested action
   ViewLocationAction viewLocationAction = new ViewLocationAction();
   viewLocationAction.setQuery("Googleplex, Mountain View, CA");

   // creating a suggested action based on a view location action
   SuggestedAction suggestedAction = new SuggestedAction();
   suggestedAction.setText("View map");
   suggestedAction.setPostbackData("postback_data_1234");
   suggestedAction.setViewLocationAction(viewLocationAction);

   // attaching action to a suggestion
   Suggestion suggestion = new Suggestion();
   suggestion.setAction(suggestedAction);

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
このコードは、RBM サンプル エージェントからの抜粋です。

Python

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

# Create a view location suggested action
suggestions = [
      messages.ViewLocationAction('View map',
            'reply:postback_data_1234',
            query='Googleplex, Mountain View, CA')
]

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggestions for the message to send to the user
for suggestion in suggestions:
    cluster.append_suggestion_chip(suggestion)

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
このコードは、RBM サンプル エージェントからの抜粋です。

C#

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;


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

// create an view location action
ViewLocationAction viewLocationAction = new ViewLocationAction
{
    Query = "Googleplex Mountain View, CA"
};

// Attach the view location action to a suggested action
SuggestedAction suggestedAction = new SuggestedAction
{
    ViewLocationAction = viewLocationAction,
    Text = "View map",
    PostbackData = "postback_data_1234"
};

// Attach the action to a suggestion object
Suggestion suggestion = new Suggestion
{
    Action = suggestedAction
};

List<Suggestion> suggestions = new List<Suggestion>
{
    suggestion
};

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
このコードは、RBM サンプル エージェントからの抜粋です。

場所の共有

位置情報の共有アクションを使用すると、ユーザーはエージェントに位置情報を送信できます。ユーザーが指定した場所が、ユーザーの現在地であるとは限りません。

次のコードは、位置情報の共有アクションを送信します。形式と値のオプションについては、ShareLocationAction をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Share your location',
          'postbackData': 'postback_data_1234',
          'shareLocationAction': {}
        }
      }
    ]
  }
}"

Node.js

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

// Define a share location suggested action
let suggestions = [
   {
      action: {
         text: 'Share your location',
         postbackData: 'postback_data_1234',
         shareLocationAction: {
         }
      }
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with a share location suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.ShareLocationAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;


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

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating a share location suggested action
   ShareLocationAction shareLocationAction = new ShareLocationAction();

   // creating a suggested action based on a share location action
   SuggestedAction suggestedAction = new SuggestedAction();
   suggestedAction.setText("Share location");
   suggestedAction.setPostbackData("postback_data_1234");
   suggestedAction.setShareLocationAction(shareLocationAction);

   // attaching action to a suggestion
   Suggestion suggestion = new Suggestion();
   suggestion.setAction(suggestedAction);

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
このコードは、RBM サンプル エージェントからの抜粋です。

Python

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

# Create a share location suggested action
suggestions = [
      messages.ShareLocationAction('Share location',
            'reply:postback_data_1234')
]

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggestions for the message to send to the user
for suggestion in suggestions:
    cluster.append_suggestion_chip(suggestion)

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
このコードは、RBM サンプル エージェントからの抜粋です。

C#

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;


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

// Create a share location action
ShareLocationAction shareLocationAction = new ShareLocationAction();

// Attach the share location action to a suggested action
SuggestedAction suggestedAction = new SuggestedAction
{
    ShareLocationAction = shareLocationAction,
    Text = "Share location",
    PostbackData = "postback_data_1234"
};

// Attach the action to a suggestion object
Suggestion suggestion = new Suggestion
{
    Action = suggestedAction
};

List<Suggestion> suggestions = new List<Suggestion>
{
    suggestion
};

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
このコードは、RBM サンプル エージェントからの抜粋です。

URL を開く

URL を開くアクションを使用すると、エージェントが指定したウェブページにユーザーを誘導できます。デフォルトでは、ウェブページはユーザーのブラウザで開きます。ユーザーがウェブページにデフォルトのアプリを設定している場合は、そのアプリが代わりに開きます。その場合、候補のアクション ボタンのアイコンはアプリのアイコンになります。

URL を開くアクションは、統合されたウェブビューもサポートしています。ウェブビューで URL を開くをご覧ください。

次のコードは、URL を開くアクションを送信します。書式設定と値のオプションについては、OpenUrlAction をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Open Google',
          'postbackData': 'postback_data_1234',
          'openUrlAction': {
            'url': 'https://www.google.com'
          }
        }
      }
    ]
  }
}"

Node.js

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

// Define an open URL suggested action
let suggestions = [
   {
      action: {
         text: 'Open Google',
         postbackData: 'postback_data_1234',
         openUrlAction: {
            url: 'https://www.google.com'
         }
      }
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with an open URL suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.OpenUrlAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;


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

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating an open url suggested action
   OpenUrlAction openUrlAction = new OpenUrlAction();
   openUrlAction.setUrl("https://www.google.com");

   // creating a suggested action based on an open url action
   SuggestedAction suggestedAction = new SuggestedAction();
   suggestedAction.setText("Open Google");
   suggestedAction.setPostbackData("postback_data_1234");
   suggestedAction.setOpenUrlAction(openUrlAction);

   // attaching action to a suggestion
   Suggestion suggestion = new Suggestion();
   suggestion.setAction(suggestedAction);

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
このコードは、RBM サンプル エージェントからの抜粋です。

Python

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

# Create an open url suggested action
suggestions = [
      messages.OpenUrlAction('Open Google',
            'reply:postback_data_1234',
            'https://www.google.com')
]

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggestions for the message to send to the user
for suggestion in suggestions:
    cluster.append_suggestion_chip(suggestion)

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
このコードは、RBM サンプル エージェントからの抜粋です。

C#

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;


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

// Create an open url action
OpenUrlAction openUrlAction = new OpenUrlAction
{
    Url = "https://www.google.com"
};

// Attach the open url action to a suggested action
SuggestedAction suggestedAction = new SuggestedAction
{
    OpenUrlAction = openUrlAction,
    Text = "Open Google",
    PostbackData = "postback_data_1234"
};

// Attach the action to a suggestion object
Suggestion suggestion = new Suggestion
{
    Action = suggestedAction
};

List<Suggestion> suggestions = new List<Suggestion>
{
    suggestion
};

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
このコードは、RBM サンプル エージェントからの抜粋です。

WebView で URL を開く

ウェブビューで URL を開くアクションは、デフォルト ブラウザのレンダリング エンジンを使用して、指定されたウェブページをメッセージ アプリ内に読み込みます。これにより、ユーザーは RBM の会話から離れることなくウェブページを操作できます。ウェブビューを有効にするには、OpenURLApplication をご覧ください。

WebView には 3 つの表示モードがあります。書式設定オプションと値オプションについては、WebviewViewMode をご覧ください。

  • 全画面: ウェブページが画面全体に表示されます。
  • 半分: ウェブページが画面の半分を占有します。
  • 縦長: ウェブページが画面の 3/4 を占める

次のコードは、webview アクションで URL を開くアクションを送信します。書式設定と値のオプションについては、OpenURLAction をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 '{
 "contentMessage": {
   "text": "Hello, world!",
   "suggestions": [
     {
       "action": {
         "text": "Open Google",
         "postbackData": "postback_data_1234",
         "openUrlAction": {
           "url": "https://www.google.com",
           "application": "WEBVIEW",
           "webviewViewMode": "FULL",
           "description": "Accessibility description"
         }
       }
     }
   ]
 }
}'

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.OpenUrlAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;

  
try {
  
   String URL = "https://www.google.com";
  
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();
  
   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // Create suggestion to view webpage in full mode
   Suggestion viewInFullMode =  getUrlActionInWebview(URL, "FULL")
   suggestions.add(viewInFullMode);
  
   // create suggestion to view webpage in half mode
   Suggestion viewInHalfMode =  getUrlActionInWebview(URL, "HALF")
   suggestions.add(viewInHalfMode);
     
   // create suggestion to view webpage in tall mode
   Suggestion viewInTallMode =  getUrlActionInWebview(URL, "TALL")
   suggestions.add(viewInTallMode);
     
   // Send simple text message with the suggested action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}

  /**
    * Creates a suggested action to open URL in webview.
    *
    * @return a suggestion object for an open URL in webview action .
    */
    private Suggestion getUrlActionInWebview(String url,
                                             String viewMode) {
      // create an open url action
      OpenUrlAction openUrlAction = new OpenUrlAction();
      openUrlAction.setUrl(url);
      openUrlAction.setApplication("WEBVIEW");
      openUrlAction.setWebviewViewMode(viewMode);
      openUrlAction.setDescription("Accessibility description");
     
      // attach the open url action to a suggested action
      SuggestedAction suggestedAction = new SuggestedAction();
      suggestedAction.setOpenUrlAction(openUrlAction);
      suggestedAction.setText('display_text');
      suggestedAction.setPostbackData('postback_data_123');
     
      // attach the action to a suggestion object
      Suggestion suggestion = new Suggestion();
      suggestion.setAction(suggestedAction);
     
      return suggestion;
    }

カレンダーの予定を作成する

カレンダーの予定を作成アクションは、ユーザーのカレンダー アプリを開き、指定された情報を使用して新しい予定の作成を開始します。

次のコードは、カレンダー イベントの作成アクションを送信します。書式設定と値のオプションについては、CreateCalendarEventAction をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Save to calendar',
          'postbackData': 'postback_data_1234',
          'fallbackUrl': 'https://www.google.com/calendar',
          'createCalendarEventAction': {
            'startTime': '2020-06-30T19:00:00Z',
            'endTime': '2020-06-30T20:00:00Z',
            'title': 'My calendar event',
            'description': 'Description of the calendar event'
          }
        }
      }
    ]
  }
}"

Node.js

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

// Define a create calendar event suggested action
let suggestions = [
   {
      action: {
         text: 'Save to calendar',
         postbackData: 'postback_data_1234',
         createCalendarEventAction: {
            startTime: '2020-06-30T19:00:00Z',
            endTime: '2020-06-30T20:00:00Z',
            title: 'My calendar event',
            description: 'Description of the calendar event',
         },
      }
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with a create calendar event suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.CreateCalendarEventAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;


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

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating a create calendar event suggested action
   CreateCalendarEventAction createCalendarEventAction = new CreateCalendarEventAction();
   calendarEventAction.setTitle("My calendar event");
   calendarEventAction.setDescription("Description of the calendar event");
   calendarEventAction.setStartTime("2020-06-30T19:00:00Z");
   calendarEventAction.setEndTime("2020-06-30T20:00:00Z");

   // creating a suggested action based on a create calendar event action
   SuggestedAction suggestedAction = new SuggestedAction();
   suggestedAction.setText("Save to calendar");
   suggestedAction.setPostbackData("postback_data_1234");
   suggestedAction.setCreateCalendarEventAction(createCalendarEventAction);

   // attaching action to a suggestion
   Suggestion suggestion = new Suggestion();
   suggestion.setAction(suggestedAction);

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
このコードは、RBM サンプル エージェントからの抜粋です。

Python

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

# Create a calendar event suggested action
suggestions = [
      messages.CreateCalendarEventAction('Save to Calendar',
                             'reply:postback_data_1234',
                             '2020-06-30T19:00:00Z',
                             '2020-06-30T20:00:00Z',
                             'My calendar event',
                             'Description of the calendar event')

]

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggestions for the message to send to the user
for suggestion in suggestions:
    cluster.append_suggestion_chip(suggestion)

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
このコードは、RBM サンプル エージェントからの抜粋です。

C#

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;


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

// Create a calendar event action
CreateCalendarEventAction calendarEventAction = new CreateCalendarEventAction
{
    Title = "My calendar event",
    Description = "Description of the calendar event",
    StartTime = "2020-06-30T19:00:00Z",
    EndTime = "2020-06-30T20:00:00Z"
};

// Attach the calendar event action to a suggested action
SuggestedAction suggestedAction = new SuggestedAction
{
    CreateCalendarEventAction = calendarEventAction,
    Text = "Save to calendar",
    PostbackData = "postback_data_1234"
};

// Attach the action to a suggestion object
Suggestion suggestion = new Suggestion
{
    Action = suggestedAction
};

List<Suggestion> suggestions = new List<Suggestion>
{
    suggestion
};

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
このコードは、RBM サンプル エージェントからの抜粋です。

メールの作成

作成アクションにより、ユーザーのメッセージ アプリが開き、事前定義された電話番号(カスタマー サポート番号など)にメッセージを送信できます。

Compose アクションには次の 3 種類があります。視覚的な例については、テキスト、音声、動画のメッセージを作成するをご覧ください。

  • テキスト メッセージを作成する: メッセージ アプリが開き、ユーザーが送信するテキストが事前に入力されます。
  • 音声メッセージを作成する: メッセージ アプリが開き、マイクも起動するので、ユーザーは音声を録音できます。
  • 動画メッセージを作成する: メッセージ アプリが開き、カメラが起動してユーザーが動画を録画できるようになります。

次のコードは、Compose アクションを送信します。書式設定と値のオプションについては、ComposeAction をご覧ください。

cURL

  curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Compose a text message',
          'postbackData': 'postback_data_123',
          'composeAction': {
            'composeTextMessage': {
              'phoneNumber': '+15556667777'
              'text': 'Draft to go into the send message text field.'
            }
          }
        }
      },{
        'action': {
          'text': 'Compose an audio message',
          'postbackData': 'postback_data_456',
          'composeAction': {
            'composeRecordingMessage': {
              'phoneNumber': '+15556667777'
              'type': 'ACTION_TYPE_AUDIO'
            }
          }
        }
      },{
        'action': {
          'text': 'Compose a video message',
          'postbackData': 'postback_data_789',
          'composeAction': {
            'composeRecordingMessage': {
              'phoneNumber': '+15556667777'
              'type': 'ACTION_TYPE_VIDEO'
            }
          }
        }
      }
    ]
  }
}"

Node.js

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

// Define a compose suggested action
let suggestions = [
   {
      action: {
         text: 'Compose a text message',
         postbackData: 'postback_data_123',
         'composeAction': {
            'composeTextMessage': {
               'phoneNumber': '+15556667777'
               'text': 'Draft to go into the send message text field.'
            }
         }
      }
   },{
      action: {
         text: 'Compose an audio message',
         postbackData: 'postback_data_456',
         'composeAction': {
            'composeRecordingMessage': {
               'phoneNumber': '+15556667777'
               'type': 'ACTION_TYPE_AUDIO'
            }
         }
      }
   },{
      action: {
         text: 'Compose a video message',
         postbackData: 'postback_data_789',
         'composeAction': {
            'composeRecordingMessage': {
               'phoneNumber': '+15556667777'
               'type': 'ACTION_TYPE_VIDEO'
            }
         }
      }
   }
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with a dial suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.ComposeAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.ComposeRecordingMessage;
import com.google.api.services.rcsbusinessmessaging.v1.model.ComposeTextMessage;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;


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

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating compose text suggested action
   Suggestion composeTextSuggestion =  getComposeTextAction()
   suggestions.add(composeTextSuggestion);

   // creating compose audio suggested action
   Suggestion composeAudioSuggestion =  getComposeAudioAction()
   suggestions.add(composeAudioSuggestion);


   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}

 /**
   * Creates a compose text suggested action.
   * @return A suggestion object for a compose text action.
 */
 private Suggestion getComposeTextAction() {
        // creating a compose text suggested action
        ComposeTextMessage message = new ComposeTextMessage();
        message.setPhoneNumber("+12223334444");
        message.setText("Draft to go into the send message text field.");
        ComposeAction composeAction = new ComposeAction();
        composeAction.setComposeTextMessage(message);

        // creating a suggested action based on a compose text action
        SuggestedAction suggestedAction = new SuggestedAction();
        suggestedAction.setText("Send a text message");
        suggestedAction.setPostbackData("postback_data_123");
        suggestedAction.setComposeAction(composeAction);

        // attaching action to a suggestion
        Suggestion suggestion = new Suggestion();
        suggestion.setAction(suggestedAction);

        return suggestion;
    }

    /**
     * Creates a compose audio suggested action.
     * @return A suggestion object for a compose audio action.
    */
    private Suggestion getComposeAudioAction() {
        // creating a compose audio suggested action
        ComposeRecordingMessage message = new ComposeRecordingMessage();
        message.setPhoneNumber("+12223334444");
        message.setType("ACTION_TYPE_AUDIO");
        ComposeAction composeAction = new ComposeAction();
        composeAction.setComposeRecordingMessage(message);

        // creating a suggested action based on a compose text action
        SuggestedAction suggestedAction = new SuggestedAction();
        suggestedAction.setText("Send an audio message");
        suggestedAction.setPostbackData("postback_data_456");
        suggestedAction.setComposeAction(composeAction);

        // attaching action to a suggestion
        Suggestion suggestion = new Suggestion();
        suggestion.setAction(suggestedAction);

        return suggestion;
    }

Python

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

  # Create a dial suggested action
  suggestions = [
      messages.ComposeTextMessageAction(
          'Send a text message',
          'postback_data_123',
          '+15556667777',
          '')
      messages.ComposeRecordingMessageAction(
          'Send an audio message',
          'postback_data_456',
          '+15556667777',
          'ACTION_TYPE_AUDIO')
  
  ]

  # Create text message to send to user
  text_msg = messages.TextMessage('Hello, world!')
  cluster = messages.MessageCluster().append_message(text_msg)

  # Append suggestions for the message to send to the user
  for suggestion in suggestions:
      cluster.append_suggestion_chip(suggestion)

  # Send a simple message with suggested action to the device
  cluster.send_to_msisdn('+12223334444')

C#

  using Google.Apis.RCSBusinessMessaging.v1.Data;
  using RCSBusinessMessaging;
  

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

  // Create a compose text suggested action
  ComposeTextMessage composeTextMessage = new ComposeTextMessage{
      PhoneNumber = "+15556667777"
      Text = "Draft to go into the send message text field."
  };

  ComposeAction composeAction = new ComposeAction
  {
      ComposeTextMessage = composeTextMessage
  };

  // Creating a suggested action based on a compose action
  SuggestedAction suggestedAction = new SuggestedAction
  {
      Text = "Send a text message",
      PostbackData = "postback_data_123",
      ComposeAction = composeAction
  };

  // Attach action to a suggestion
  Suggestion suggestion = new Suggestion
  {
      Action = suggestedAction
  };

  List suggestions = new List
  {
      suggestion
  };

  rbmApiHelper.SendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
  );  

候補ワードのリスト

エージェントは、ユーザーの次のアクションを案内するメッセージとともに候補ワードのリストを送信します。チップリストは、関連するメッセージが会話の一番下にある場合にのみ表示されます。会話の後のメッセージ(ユーザーまたはエージェントからのメッセージ)は、チップリストを上書きします。

リスト内のチップは、返信候補アクション候補です。

チップリストには最大 11 個の候補チップを含めることができ、各チップラベルの最大文字数は 25 文字です。

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

リッチカード

関連情報、メディア、候補のまとまった情報を送信する必要がある場合は、リッチカードを送信する必要があります。リッチカードを使用すると、エージェントは 1 つのメッセージで複数の情報単位を送信できます。

リッチカードには次のアイテムを含めることができます。

  • 画像または動画
  • タイトルのテキスト
  • 説明テキスト
  • 返信の候補と操作の候補のリスト(最大 4 件)

リッチカードには、上記の項目をすべて含めることができますが、有効なカードにするには、少なくとも画像、動画、タイトルのいずれかを含める必要があります。リッチカードには、推奨されるアクションまたは推奨される返信を最大 4 つ含めることができます。1 つのカードに操作の候補と返信の候補を組み合わせて含めることはできません。

エージェントは、複数のリッチカードを リッチカード カルーセルでまとめて送信できます。

リッチカード ペイロードの最大サイズは 250 KB です。メディア ファイルサイズの推奨事項と上限については、ベスト プラクティスをご覧ください。

カードの高さ

カードはコンテンツに合わせて縦方向に拡大します。リッチカードの高さの最小値は 112 DP、最大値は 344 DP です。カードのコンテンツがカードの最小高さに合わせるのに十分でない場合は、カードが拡大され、余分な高さが空白で埋められます。

リッチカードのメディアは、次の 3 つの高さのいずれかに収まる必要があります。

  • 短いバージョン: 112 dp
  • 中: 168 dp
  • 大: 264 DP

選択した高さでメディアがカード内のサイズに収まらない場合、メディアをズームして切り抜くことで、メディア プレビューが選択されます。

次のコードは、画像と返信候補を含むリッチカードを送信します。書式設定と値のオプションについては、RichCard をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'richCard': {
      'standaloneCard': {
        'thumbnailImageAlignment': 'RIGHT',
        'cardOrientation': 'VERTICAL',
        'cardContent': {
          'title': 'Hello, world!',
          'description': 'RBM is awesome!',
          'media': {
            'height': 'TALL',
            'contentInfo':{
              'fileUrl': 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif',
              'forceRefresh': 'false'
            }
          },
          'suggestions': [
            {
              'reply': {
                'text': 'Suggestion #1',
                'postbackData': 'suggestion_1'
              }
            },
            {
              'reply': {
                'text': 'Suggestion #2',
                'postbackData': 'suggestion_2'
              }
            }
          ]
        }
      }
    }
  }
}"

Node.js

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

// Suggested replies to be used in the card
let suggestions = [
   {
      reply: {
         'text': 'Suggestion #1',
         'postbackData': 'suggestion_1',
      },
   },
   {
      reply: {
         'text': 'Suggestion #2',
         'postbackData': 'suggestion_2',
      },
   },
];

// Image to be displayed by the card
let imageUrl = 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif';

// Definition of the card parameters
let params = {
   messageText: 'Hello, world!',
   messageDescription: 'RBM is awesome!',
   msisdn: '+12223334444',
   suggestions: suggestions,
   imageUrl: imageUrl,
   height: 'TALL',
};

// Send rich card to device
rbmApiHelper.sendRichCard(params, function(response) {
   console.log(response);
});
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.StandaloneCard;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.cards.CardOrientation;
import com.google.rbm.cards.MediaHeight;
import com.google.rbm.RbmApiHelper;
import com.google.rbm.SuggestionHelper;


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

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();
   suggestions.add(
      new SuggestionHelper("Suggestion #1", "suggestion_1").getSuggestedReply());

   suggestions.add(
      new SuggestionHelper("Suggestion #2", "suggestion_2").getSuggestedReply());

   String imageUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif";

   // Create a standalone rich card to send to the user
   StandaloneCard standaloneCard = rbmApiHelper.createStandaloneCard(
       "Hello, world!",
       "RBM is awesome!",
       imageUrl,
       MediaHeight.MEDIUM,
       CardOrientation.VERTICAL,
       suggestions
   );

   rbmApiHelper.sendStandaloneCard(standaloneCard, "+12223334444");
} catch(Exception e) {
   e.printStackTrace();
}
このコードは、RBM サンプル エージェントからの抜粋です。

Python

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

# Suggested replies to be used in the card
suggestions = [
      messages.SuggestedReply('Suggestion #1', 'reply:suggestion_1'),
      messages.SuggestedReply('Suggestion #2', 'reply:suggestion_2')
]

# Image to be displayed by the card
image_url = 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif';

# Define rich card structure
rich_card = messages.StandaloneCard('VERTICAL',
                                    'Hello, world!',
                                    'RBM is awesome!',
                                    suggestions,
                                    image_url,
                                    None,
                                    None,
                                    'MEDIUM')

# Append rich card and send to the user
cluster = messages.MessageCluster().append_message(rich_card)
cluster.send_to_msisdn('+12223334444')
このコードは、RBM サンプル エージェントからの抜粋です。

C#

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
using RCSBusinessMessaging.Cards;


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

List<Suggestion> suggestions = new List<Suggestion>
{
   // Create suggestion chips
   new SuggestionHelper("Suggestion #1", "suggestion_1").SuggestedReply(),
   new SuggestionHelper("Suggestion #2", "suggestion_2").SuggestedReply()
};

string imageUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif";

// Create rich card with suggestions
StandaloneCard standaloneCard = rbmApiHelper.CreateStandaloneCard(
   "Hello, world!",
   "RBM is awesome",
   imageUrl,
   MediaHeight.TALL,
   CardOrientation.VERTICAL,
   suggestions
);

// Send rich card to user
rbmApiHelper.SendStandaloneCard(standaloneCard, "+12223334444");
このコードは、RBM サンプル エージェントからの抜粋です。

リッチカード カルーセル

ユーザーに複数のオプションから選択してもらう必要がある場合は、リッチカード カルーセルを使用します。カルーセルは複数のリッチカードを連結したもので、ユーザーはアイテムを比較して個別に対応できます。

カルーセルには、2 ~ 10 個のリッチカードを含めることができます。カルーセル内のリッチカードは、コンテンツと高さに関する一般的なリッチカードの要件を満たしている必要があります。

リッチカード カルーセルのペイロードの最大サイズは 250 KB です。メディア ファイルサイズの推奨事項と上限については、ベスト プラクティスをご覧ください。

リッチカードと同様に、画面の解像度、画素密度、ユーザー設定など、さまざまな要因がエンドユーザーに表示されるカードの外観に影響します。ただし、カルーセルでは、最初の数枚のカードの高さによってカルーセル内のすべてのカードの高さが決まり、カードの高さはタイトル、説明、候補の切り捨てに影響します。

ディスプレイの制約またはカードの高さにより、デバイスにカードのすべての要素を表示できない場合、RBM は次のロジックを使用して、デバイスに表示できるまでカードを切り捨てます。

  1. 説明を 1 行にまとめる。
  2. タイトルを 1 行に短縮します。
  3. カードに収まらない候補は、定義されたリストの最後から除外されます。
  4. 説明を省略します。
  5. タイトルを省略します。

タイトルと説明は、切り捨てを防ぐため、できるだけ短くしてください。縦長のメディアの場合は、タイトルと説明、または 1 つの候補を使用します。中程度のメディアの場合は、最大 2 つの候補を使用します。短いメディアの場合は、最大 3 つの候補を使用します。4 つの候補を表示するには、カードにメディアを含めないでください。

カードのコンテンツのサイズと長さはほぼ同じにします。必要に応じて、後続のカードが切り捨てられないように、カルーセルの最初に大きなカードを配置します。

次のコードは、リッチカードのカルーセルを送信します。書式設定と値のオプションについては、RichCard をご覧ください。

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_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 "{
  'contentMessage': {
    'richCard': {
      'carouselCard': {
        'cardWidth':'MEDIUM',
        'cardContents': [
          {
            'title':'Card #1',
            'description':'The description for card #1',
            'suggestions': [
              {
                'reply': {
                  'text':'Card #1',
                  'postbackData':'card_1'
                }
              }
            ],
            'media': {
              'height':'MEDIUM',
              'contentInfo': {
                'fileUrl':'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg',
                'forceRefresh':'false'
              }
            }
          },
          {
            'title':'Card #2',
            'description':'The description for card #2',
            'suggestions': [
              {
                'reply': {
                  'text':'Card #2',
                  'postbackData':'card_2'
                }
              }
            ],
            'media': {
              'height':'MEDIUM',
              'contentInfo': {
                'fileUrl':'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg',
                'forceRefresh': 'false'
              }
            }
          }
        ]
      }
    }
  }
}"

Node.js

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

// Images for the carousel cards
let card1Image = 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg';
let card2Image = 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg';

// Define the card contents for a carousel with two cards, each with one suggested reply
let cardContents = [
   {
      title: 'Card #1',
      description: 'The description for card #1',
      suggestions: [
         {
            reply: {
               text: 'Card #1',
               postbackData: 'card_1',
            }
         }
      ],
      media: {
         height: 'MEDIUM',
         contentInfo: {
            fileUrl: card1Image,
            forceRefresh: false,
         },
      },
   },
   {
      title: 'Card #2',
      description: 'The description for card #2',
      suggestions: [
         {
            reply: {
               text: 'Card #2',
               postbackData: 'card_2',
            }
         }
      ],
      media: {
         height: 'MEDIUM',
         contentInfo: {
            fileUrl: card2Image,
            forceRefresh: false,
         },
      },
   },
];

// Definition of carousel card
let params = {
   msisdn: '+12223334444',
   cardContents: cardContents,
};

// Send the device the carousel card defined above
rbmApiHelper.sendCarouselCard(params, function(response) {
   console.log(response);
});
このコードは、RBM サンプル エージェントからの抜粋です。

Java

import com.google.api.services.rcsbusinessmessaging.v1.model.CardContent;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.cards.CardOrientation;
import com.google.rbm.cards.CardWidth;
import com.google.rbm.cards.MediaHeight;
import com.google.rbm.RbmApiHelper;
import com.google.rbm.SuggestionHelper;


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

            List cardContents = new ArrayList();

            // Images for the carousel cards
            String card1Image = "https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg";

            // Create suggestions for first carousel card
            List card1Suggestions = new ArrayList();
            card1Suggestions.add(
                new SuggestionHelper("Card #1", "card_1"));

            cardContents.add(
                new StandaloneCardHelper(
                    "Card #1",
                    "The description for card #1",
                    card1Image,
                    card1Suggestions)
                    .getCardContent(MediaHeight.SHORT)
            );

            // Images for the carousel cards
            String card2Image = "https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg";

            // Create suggestions for second carousel card
            List card2Suggestions = new ArrayList();
            card2Suggestions.add(
                new SuggestionHelper("Card #2", "card_2"));

            cardContents.add(
                new StandaloneCardHelper(
                    "Card #2",
                    "The description for card #2",
                    card2Image,
                    card2Suggestions)
                    .getCardContent(MediaHeight.SHORT)
            );

            // Send the carousel to the user
            rbmApiHelper.sendCarouselCards(cardContents, CardWidth.MEDIUM, "+12223334444");
        } catch(Exception e) {
            e.printStackTrace();
        }
このコードは、RBM サンプル エージェントからの抜粋です。

Python

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

# Images for the carousel cards
card_image_1 = 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg';
card_image_2 = 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg';

# Suggested replies to be used in the cards
suggestions1 = [
      messages.SuggestedReply('Card #1', 'reply:card_1')
]

suggestions2 = [
      messages.SuggestedReply('Card #2', 'reply:card_2')
]

# Define the card contents for a carousel with two cards,
# each with one suggested reply
card_contents = []
card_contents.append(messages.CardContent('Card #1',
                                          'The description for card #1',
                                          card_image_1,
                                          'MEDIUM',
                                          suggestions1))

card_contents.append(messages.CardContent('Card #2',
                                          'The description for card #2',
                                          card_image_2,
                                          'MEDIUM',
                                          suggestions2))

# Send the device the carousel card defined above
carousel_card = messages.CarouselCard('MEDIUM', card_contents)
cluster = messages.MessageCluster().append_message(carousel_card)
cluster.send_to_msisdn('+12223334444')
このコードは、RBM サンプル エージェントからの抜粋です。

C#

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
using RCSBusinessMessaging.Cards;


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

// Image references to be used in the carousel cards
string card1Image = "https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg";
string card2Image = "https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg";

// Suggestion chip lists to be used in carousel cards
List<Suggestion> suggestions1 = new List<Suggestion>
{
   new SuggestionHelper("Card #1", "card_1").SuggestedReply()
};

List<Suggestion> suggestions2 = new List<Suggestion>
{
   new SuggestionHelper("Card #2", "card_2").SuggestedReply()
};

// Create the card content for the carousel
List<CardContent> cardContents = new List<CardContent>
{
   // Add items as card content
   new StandaloneCardHelper(
                    "Card #1",
                    "The description for card #1",
                    card1Image,
                    suggestions1).GetCardContent(),
   new StandaloneCardHelper(
                    "Card #2",
                    "The description for card #2",
                    card2Image,
                    suggestions2).GetCardContent()
};

// Send the carousel to the user
rbmApiHelper.SendCarouselCards(cardContents, CardWidth.MEDIUM, msisdn);
このコードは、RBM サンプル エージェントからの抜粋です。