RBM 代理通过发送和接收消息与用户进行通信。如需向用户发送消息,您的客服人员会向 RCS Business Messaging API 发送消息请求。单个请求可以包含文本、富媒体卡片、图片或视频,以及建议的回复和建议的操作。
如果您向用户发送消息,而用户的设备不支持 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 发送一条通知事件。
ttl
和 expireTime
的最大值为提交消息后的 15 天。
消息大小限制
整个字符串化的 AgentMessage 的大小上限为 250 KB。富媒体卡片和其他媒体内容会计入此大小限制。邮件正文的字符数上限为 3072 个字符。
通过 RBM 发送的文件大小上限为 100 MB。单个 RBM 消息只能附加一个 PDF 或媒体文件。如需了解详情,请参阅媒体文件和 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); });
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(); }
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')
C#
using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", );
基本消息内容 - 短信转换
运营商已推出结算模式,以支持将短信迁移到 RBM。包含最多 160 个 UTF-8 字符的 RBM 消息称为基本消息。
构建用于发送基本消息的请求时,请注意字符计为 1 个字节 (UTF-8)。如果您发送的消息包含表情符号或多字节字符集等特殊字符,则每个字符都将计为 2 个 UTF-8 字符。
在框中输入一些文字,检查其长度:
用于用户验证的动态密码
您可以使用 RBM 发送一次性密码 (OTP),以便通过 SMS Retriever API 自动验证用户。如需详细了解短信 Retriever 和相关 API,请参阅 短信 Retriever 文档。如需详细了解已注册 SMS Retriever API 的应用中的自动用户验证,请参阅此流程图。
在验证过程中,SMS Retriever API 会监听 RBM 消息。此消息必须包含用于标识应用的 OTP 和哈希。哈希与应用匹配后,系统会提取 OTP 并将其转发给应用以进行自动用户验证。
以下是用于用户验证的 RBM 短信示例:您的代码是 <OTP> <app hash>。
例如 Your code is 123456 M8tue43FGT.
。
媒体文件和 PDF 文件
当您发送包含图片、视频、音频或 PDF 文件的消息时,您的客服人员必须提供相应内容的可公开访问网址,或者直接上传文件。对于媒体文件,您还可以指定缩略图,以便用户在点击内容之前预览内容。对于音频文件,系统会使用默认的音频 widget 作为占位符。
RBM 平台会将文件缓存 60 天,并且 API 会返回一个文件 ID,您的代理可以将该 ID 添加到发送给用户的消息中。60 天后,RBM 会从缓存中移除文件。
按网址指定文件时,最佳做法是将 contentMessage.forceRefresh
设置为 false
。将 contentMessage.forceRefresh
设为 true
会强制 RBM 从指定网址提取新内容,即使网址内容已缓存也会如此,这会延长向用户传送消息的时间。
如需了解文件大小建议和限制,请参阅最佳实践。
文件网址示例
以下代码会发送图片。如需了解格式设置和值选项,请参阅 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); });
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(); }
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')
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");
或者,您也可以先上传媒体,然后再使用 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 | 否 | ||
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 | 是 |
video/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); });
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(); }
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')
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 );
建议操作
建议的操作可利用设备的内置功能引导用户完成对话。您的客服人员可以建议用户拨打电话号码、在地图上打开某个位置、分享位置、打开网址或创建日历活动。您的客服人员会以建议条状标签列表或富媒体卡片的形式发送建议操作。
当用户点按建议的操作时,您的客服人员会收到包含操作的回传数据的事件。
建议操作的长度不得超过 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); });
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(); }
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')
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 );
查看某个地点
“查看位置”操作会在用户的默认地图应用中显示位置。您可以通过经纬度指定位置,也可以根据用户的当前位置进行查询来指定位置。您还可以为地图应用中显示的图钉设置自定义标签。
示例
以下代码会发送查看位置信息操作。如需了解格式设置和值选项,请参阅 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); });
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(); }
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')
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 );
分享位置信息
借助“分享位置”操作,用户可以向您的客服人员发送位置信息。用户指定的位置不一定是用户所在的位置。
示例
以下代码会发送分享位置信息操作。如需了解格式设置和值选项,请参阅 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); });
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(); }
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')
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 );
打开网址
借助“打开网址”操作,您可以引导用户前往客服人员指定的网页。默认情况下,网页会在用户的浏览器中打开。如果用户为网页配置了默认应用,系统会改为打开该应用。在这种情况下,建议操作按钮上的图标将是应用的图标。
“打开网址”操作还支持集成的 WebView;请参阅使用 WebView 打开网址。
示例
以下代码会发送打开网址操作。如需了解格式设置和值选项,请参阅 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); });
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(); }
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')
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 );
使用 WebView 打开网址
“使用 WebView 打开网址”操作会使用默认浏览器的渲染引擎在即时通讯应用中加载指定网页。这样,用户无需离开 RBM 对话即可与网页互动。如需启用 WebView,请参阅 OpenURLApplication
。
WebView 有三种显示模式。如需了解格式设置和值选项,请参阅 WebviewViewMode
。
- 全屏:网页占据整个屏幕
- 半屏:网页占据一半屏幕
- 高:网页占据三分之二的屏幕
示例
以下代码会发送“使用 WebView 打开网址”操作。如需了解格式设置和值选项,请参阅 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); });
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(); }
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')
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 );
撰写邮件
“撰写”操作会打开用户的即时通讯应用,以便用户向预定义的电话号码(例如客户服务电话号码)发送消息。
Compose 操作分为三种类型。如需查看直观示例,请参阅撰写文本、语音或视频消息。
- 撰写短信:打开包含预填充文本的即时通讯应用,供用户发送。
- 撰写语音信息:打开即时通讯应用并启动麦克风,以便用户录制音频。
- 撰写视频消息:打开即时通讯应用并启动相机,以便用户录制视频。
示例
以下代码会发送 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 }; Listsuggestions = new List { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
建议内容信息条列表
您的客服人员会发送包含消息的建议内容信息卡列表,以引导用户执行后续操作。只有当关联的消息位于对话底部时,系统才会显示条状标签列表。对话中的任何后续消息(来自用户或您的客服人员)都会覆盖条状标签列表。
条状标签列表最多包含 11 个建议条状标签,每个条状标签标签最多可包含 25 个字符。
如需了解格式设置和值选项,请参阅 AgentContentMessage
。
复合信息卡
当您需要发送大量相关信息、媒体内容或建议时,应发送复合信息卡。借助富媒体卡片,您的客服人员可以在一条消息中发送多个信息单元。
富媒体卡片可以包含以下内容:
- 图片或视频
- 标题文本
- 描述文字
- 建议的回复和建议的操作的列表(最多 4 条)
复合信息卡可以包含所有列出的项,但必须至少包含图片、视频或标题,才有效。一个富媒体卡片最多可以包含四项建议操作或建议回复。单个卡片上不能同时包含建议的操作和建议的回复。
您的客服人员可以通过复合信息卡轮播界面一起发送多张复合信息卡。
富媒体卡载荷的大小上限为 250 KB。如需了解媒体文件大小建议和限制,请参阅最佳实践。
卡片高度
卡片会垂直展开即可适应内容。富媒体卡片的最小高度为 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); });
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(); }
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')
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");
复合信息卡轮播界面
如果您需要向用户显示多个选项供其选择,请使用富媒体卡片轮播界面。轮播界面会将多个丰富卡片串联在一起,让用户能够比较商品并对每个商品做出回应。
轮播界面中可以包含至少 2 张,最多 10 张复合信息卡。轮播界面中的复合信息卡必须符合内容和高度方面的一般复合信息卡要求。
富媒体卡片轮播界面载荷的大小上限为 250 KB。如需了解媒体文件大小建议和限制,请参阅最佳实践。
截断
与富媒体卡片一样,许多因素(例如屏幕分辨率、像素密度和用户偏好设置)都会影响卡片在最终用户中的显示方式。不过,在轮播界面中,前几个卡片的高度决定了轮播界面中所有卡片的高度,而卡片高度会影响标题、说明和建议的截断。
如果设备因显示限制或卡片高度而无法显示卡片的所有元素,RBM 会使用以下逻辑截断卡片,直到其能够在设备上显示:
- 将说明缩减为一行。
- 将标题缩减为一行。
- 从定义的列表末尾开始,忽略不适合显示在卡片中的建议。
- 省略说明。
- 省略标题。
为避免截断,请尽可能缩短标题和说明的长度。对于长视频,请使用标题和说明,或使用一条建议。对于中等媒体,最多可使用两个建议。对于短视频,最多可使用 3 条建议。如需显示四条建议,请勿在卡片中添加媒体内容。
让卡片的内容大小和长度大致相当,并根据需要在轮播界面中放置较大的卡片,以免后续卡片被截断。
示例
以下代码会发送复合信息卡轮播界面。如需了解格式设置和值选项,请参阅 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); });
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(); }
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')
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);