RBM 代理通过发送和接收消息与用户通信。 如需向用户发送信息,您的代理会向 RCS Business 发送信息请求 Messaging API。单个请求可包含文字、复合信息卡、图片或 以及建议的回复和建议的操作。
如果您向不支持 RCS 或未安装 RCS 的用户发送消息 RCS 处于启用状态时,RBM 平台会返回 404 错误。在这种情况下,您可以尝试 通过基础架构中定义的后备方法覆盖用户
您向 RCS 用户发送消息时所使用的网络并非代理 RBM 平台或尚未启用 RCS 流量的网络上 会返回 403 错误。
如果您发送的消息中包含用户设备不支持的功能, RBM 平台会返回错误,并且无法递送您的消息。
字符串化的整个字符串的大小上限 AgentMessage 为 250 KB。复合搜索卡和其他媒体会计入此大小限制。通过 消息的文本部分也不得超过 3072 个字符。
收件人已离线
如果收件人 离线使用。您收到 200 OK 响应,并且 RBM 平台保留了该消息 并在 30 天内尝试重新提交。因此无需要求 RBM 将 消息。
RBM 会在所有未送达的消息提交 30 天后将其删除。
根据代理的使用场景,您可能需要 撤消未递送的邮件 则会在 30 天超时期限内失效撤消后,离线用户可能无法再 他们重新上线时收到过期的消息。有多个 撤消消息的方法:
设置消息有效期
代理的消息具有时效性吗?例如,动态密码仅适用于 一小段时间。限时优惠将过期。预约提醒也不会显示 与会面相关。为了帮助确保及时 messages,设置消息有效期。这可能会阻止离线用户 重新上线时收到过时内容设置到期时间也是一个好办法 提示调用您的后备消息策略,以便用户获得所需信息 。
如需设置消息到期时间,请在代理中指定以下字段之一 消息:
expireTime
:消息到期的确切时间(采用世界协调时间)。ttl
(存留时间):消息的有效期。
如需了解格式设置和值选项,请参阅 AgentMessage
。
消息过期后,RBM 平台将停止尝试传送消息, 它会自动撤消不过,在极少数情况下,此操作可能会失败 。例如,当 RBM 运行时,API 可能会触发撤消 平台正在传递消息。为了确认是否 已过期的消息被成功撤消,RBM 将会发送通知 事件 添加到网络钩子。
ttl
和 expireTime
的最大值为消息后的 15 天
提交内容。
文本
最简单的消息是由文本组成的。短信最适合 来传递信息,而无需视觉、复杂互动或 响应。
示例
以下代码会发送一条纯文本消息。关于格式和值
选项,请参阅
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 示例代理。
基本消息内容 - 短信转换
运营商推出了计费模式 ,以便将短信迁移到 RBM。RBM 消息最多包含 160 个字符, UTF-8 字符称为基本消息。
构建发送基本消息的请求时,请记住 计为 1 个字节 (UTF-8)。如果您发送包含特殊标记的邮件, 个字符(例如表情符号或多字节字符集),每个字符都会计算 为 2 个 UTF-8 字符。
在框中输入一些文本,以检查文本长度:
用于用户验证的一次性密码
您可以使用 RBM 为自动用户发送动态密码 (OTP) 使用 SMS Retriever API 进行验证。有关 SMS Retriever 的详细信息 和相关 API,请参阅短信检索器文档。 如需详细了解已在 Google Play 中注册 请参阅此 流程图。
在验证过程中,SMS Retriever API 会监听 RBM 消息。此消息必须包含动态密码和用于识别应用的哈希。 在哈希与应用匹配后,系统会提取动态密码并转发给 应用以进行自动用户验证。
以下是用于用户验证的 RBM 短信示例:您的验证码是 <OTP> <app hash>。
例如 Your code is 123456 M8tue43FGT.
。
媒体和 PDF 文件
当您发送包含图片、视频、音频或 PDF 文件的消息时,您的代理 必须为内容提供可公开访问的网址,或直接将 文件。对于媒体文件,您还可以指定缩略图图片 可以先预览内容,然后再点击对于音频文件,默认的音频 widget 用作占位符。
RBM 平台会将文件缓存 60 天,而 API 会返回 您的代理可以包含在发送给用户的消息中。RBM 会在 60 天后移除文件 从缓存中移除
请参阅最佳做法 了解文件大小建议和限制。
文件网址示例
以下代码会发送一张图片。如需了解格式设置和值选项,请参阅 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.create
和 AgentContentMessage
。
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 | 否 | ||
音频/aac | AAC 音频 | .aac | 否 |
音频/mp3 | MP3 音频 | .mp3 | 否 |
audio/mpeg | MPEG 音频 | .mpeg | 否 |
音频/mpg | MPG 音频 | .mp3 | 否 |
audio/mp4 | MP4 音频 | .mp4 | 否 |
音频/mp4-latm | MP4-latm 音频 | .mp4 | 否 |
音频/3gpp | 3GPP 音频 | 0.3gp | 否 |
image/jpeg | JPEG | .jpeg、.jpg | 是 |
image/gif | GIF | .gif | 是 |
image/png | PNG | .png | 是 |
视频/h263 | H263 视频 | .h263 | 是 |
视频/m4v | M4V 视频 | .m4v | 是 |
video/mp4 | MP4 视频 | .mp4 | 是 |
视频/mpeg4 | MPEG-4 视频 | .mp4、.m4p | 是 |
video/mpeg | MPEG 视频 | .mpeg | 是 |
视频/webm | WEBM 视频 | .webm | 是 |
建议的回复
“建议回复”可通过提供符合以下特征的回复来引导用户完成对话: 让客服人员知道如何应对。您的代理在以下时间后发送建议的回复: 建议条状标签列表或复合信息卡。
当用户点按建议的回复时,代理会收到 事件 包含回复的文本和回传数据。
建议的回复最多包含 25 个字符。
示例
以下代码会发送包含两条建议回复的文本。对于格式设置和
值选项,请参阅
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 示例代理。
建议操作
“建议操作”功能通过停用内置功能,引导用户完成对话。 自己设备的功能您的代理可以建议用户 号码、打开地图上的位置、分享位置、打开网址或创建 日历活动。你的客服人员将在以下时间后发送建议的操作: 建议条状标签列表或复合信息卡。
当用户点按建议的操作时,代理会收到一个 事件 包含操作的回传数据的对象。
建议的操作不得超过 25 个字符。
如需了解格式设置和值选项,请参阅 SuggestedAction
。
拨号
“拨号”操作会引导用户拨打您的代理指定的电话号码。
电话号码只能包含数字 (0-9
)、加号 (+
)、星号 (*
),
和数字符号 (#
)。E.164 国际格式(例如,
+14155555555
),但并非必需。也就是说,+14155555555
和
“1011
”为有效条目。
示例
以下代码会发送拨号操作。如需了解格式设置和值选项,请参阅 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 示例代理。
打开网址
“打开网址”操作会打开用户的网络浏览器并转到指定的网址。如果 将应用注册为网址的默认处理程序,系统会改为打开该应用,并且 该操作的图标是应用的图标。
示例
以下代码会发送一个打开网址的操作。有关格式设置和值选项
请参阅
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 示例代理。
创建日历活动
“创建日历活动”操作会打开用户的日历应用,并开始 使用指定信息创建新事件。
示例
以下代码会发送“创建日历活动”操作。对于格式设置和
值选项,请参阅
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 示例代理。
建议条状标签列表
您的代理会发送建议内容信息卡列表及消息来引导用户随后 操作。条状标签列表仅在相关消息位于 对话底部。会话中的所有后续邮件(来自 用户或代理)会覆盖条状标签列表。
条状标签列表最多包含 11 个建议内容信息卡,每个条状标签标签可以 不能超过 25 个字符。
如需了解格式设置和值选项,请参阅 AgentContentMessage
。
复合信息卡
当您需要将大量相关信息、媒体或信息 您应该发送复合信息卡。复合搜索卡允许代理 在一条消息中包含多个单位的信息。
复合信息卡可包含以下项目:
- 图片或视频
- 标题文本
- 描述文字
- 建议的回复和建议操作的列表(最多 4 个)
复合信息卡可以包含列出的全部项目,但复合信息卡必须包含 至少需要一个图片、视频或标题才有效。复合信息卡可以包含 最多四条建议的操作或建议的回复。 它不能包含对 。
您的代理可以在一个时间段内同时发送多张复合搜索卡 复合信息卡轮播界面。
卡片高度
卡片会垂直展开即可适应其中的内容。复合信息卡有最小高度 112 DP,最大高度为 344 DP。如果卡片的内容 卡片不够大,无法填满卡片的最小高度,则卡片会展开并填满 添加额外的高度和空格
复合信息卡中的媒体必须符合以下三种高度之一:
- 短: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 张复合信息卡。富 轮播界面中的卡片必须符合 内容和高度
截断
就像复合搜索卡一样,需要考虑很多因素(例如屏幕分辨率、 像素密度和用户偏好设置)会影响卡片对最终用户的外观。在 不过,前几张卡片的高度决定了 和卡片高度会影响标题、说明和 建议截断。
如果设备因显示限制而无法显示卡片的所有元素 或卡片高度,则 RBM 会使用 以下逻辑:
- 将广告内容描述缩减为一行。
- 将标题缩减到一行。
- 从卡片末尾开始忽略不适合卡片的建议 定义的列表。
- 省略说明。
- 省略标题。
为避免内容被截断,请使用尽可能短的标题和说明。高 请使用标题和说明或一条建议。中型 最多使用两条建议。对于短视频,最多可以提供 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 示例代理。
邮件大小上限
RBM 消息中可发送的文字大小上限为 256kb。这个 包含构成 JSON 载荷的文本, 消息。
可通过 RBM 发送的文件大小上限为 200MB。
一条 RBM 消息只能附加一个媒体文件。