RBM 代理程式會透過傳送和接收訊息與使用者溝通。如要傳送訊息給使用者,您的代理程式會將訊息要求傳送至 RCS Business Messaging API。單一要求可包含文字、互動式資訊卡、多媒體和 PDF 檔案,以及建議回覆和建議動作。
在某些情況下,RBM 平台會傳回錯誤訊息,協助您管理訊息傳送作業:
- 如果您傳送訊息給使用者,但對方的裝置不支援 RCS 或未啟用 RCS,RBM 平台會傳回 404 NOT_FOUND 錯誤。在這種情況下,您可以嘗試透過基礎架構中定義的備用方法聯絡使用者。
- 如果您在尚未推出服務專員的網路,或尚未啟用 RCS 流量的網路上,傳送訊息給 RCS 使用者,RBM 平台會傳回 404 NOT_FOUND 錯誤。
- 如果您傳送的訊息含有使用者裝置不支援的功能,RBM 平台會傳回 400 INVALID_ARGUMENT 錯誤,並且不會傳送您的訊息。
在多管道訊息策略中,建議您在合理時間後撤銷未送達的訊息,並透過其他管道傳送。如要在預先設定的時間自動撤銷訊息,請設定訊息到期時間。
接收者目前不在線上
如果收件者處於離線狀態,RBM 平台仍會接受訊息傳送作業。您會收到 200 OK 回應,且 RBM 平台會保留訊息並嘗試重新傳送 30 天。您不需要要求 RBM 再次傳送訊息。
RBM 會在提交後 30 天後刪除所有未送達的訊息。
視服務機器人的用途而定,您可能會在 30 天的逾時期限前撤銷未送達的訊息。撤銷作業可避免離線使用者在重新上線時收到過時的訊息。您可以透過多種方式撤銷訊息:
設定訊息到期日
你的服務專員是否傳送了具有時效性的訊息?舉例來說,一次性密碼的有效期間很短。限時優惠到期。而且,預約日期過後,預約提醒就不再相關。為確保訊息能及時且符合需求,請設定訊息到期日。這麼做可避免離線使用者在重新上線時收到過時的內容。到期日也是觸發備用訊息策略的好方法,可讓使用者及時取得所需資訊。
如要設定訊息到期日,請在代理程式訊息中指定下列其中一個欄位:
expireTime
:訊息到期時間 (以世界標準時間為準)。ttl
(存留時間):訊息到期前剩餘的時間。
如需格式設定和值選項,請參閱 AgentMessage
。
訊息到期後,RBM 平台就會停止嘗試傳送訊息,並自動撤銷訊息。不過,在少數情況下,這可能會失敗。舉例來說,API 可能會在 RBM 平台傳送訊息的過程中觸發撤銷作業。為確認已過期訊息是否已成功撤銷,RBM 會將通知事件傳送至您的 webhook。
ttl
和 expireTime
的最大值為提交訊息後的 15 天。
設定訊息流量類型
RBM API 包含 messageTrafficType
欄位,可用於將訊息分類。雖然服務專員用途仍會定義服務專員行為和適用的業務規則,但messageTrafficType
可讓您更詳細地分類訊息內容。最終,單一代理程式就能處理多種用途。目前不會影響現有的代理程式用途或商務規則。
目前這個欄位為選用欄位,但建議您現在就設定,以免在欄位變成必填時收到錯誤。
如要設定郵件流量類型,請根據郵件內容為每封郵件指派適當的 messageTrafficType
。RBM 支援下列流量類型。
流量類型 | 訊息內容 | 服務專員用途 |
---|---|---|
AUTHENTICATION |
驗證郵件。 | 動態密碼 |
TRANSACTION |
針對使用者現有服務或產品的訊息。例如:確認訊息、付款收據或訂房詳細資料。 | 交易或多用途 |
PROMOTION |
用於宣傳訊息,例如優惠、折扣、公告或其他宣傳內容。 | 促銷或多用途 |
SERVICEREQUEST |
針對使用者明確要求的服務傳送訊息。 | 動態密碼、交易、宣傳或多用途 |
ACKNOWLEDGEMENT |
用於確認使用者動作的訊息,特別是取消訂閱要求。這表示我們已收到使用者的申請,並正在處理中。 | 動態密碼、交易、宣傳或多用途 |
如果未設定流量類型,系統會為代理程式用途指派預設類型。
服務專員用途 | 預設流量類型 |
---|---|
OTP | AUTHENTICATION |
交易 | TRANSACTION |
宣傳 | PROMOTION |
多用途 | MESSAGE_TRAFFIC_TYPE_UNSPECIFIED |
多用途代理程式沒有預設流量類型。您必須根據每則訊息的內容,明確設定流量類型。如果您未替換 MESSAGE_TRAFFIC_TYPE_UNSPECIFIED
值,系統會產生錯誤。
訊息大小限制
整個字串化的 AgentMessage 大小上限為 250 KB。訊息的文字部分長度上限為 3072 個半形字元。
透過 RBM 傳送的檔案大小上限為 100 MB。詳情請參閱「媒體和 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!" }, "messageTrafficType": "PROMOTION" }'
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 訊息稱為基本訊息。
基本訊息內容和連結預覽畫面
RCS 用戶端可以實作連結預覽功能。如果純文字 RBM 訊息包含含有 openGraph 標記的網站網址,系統可能會顯示預覽圖片,讓使用者感受到更豐富的內容。
請注意,RCS 用戶端可能會允許使用者停用連結預覽功能。
用於使用者驗證的一次性密碼
您可以使用 RBM 傳送一次性密碼 (OTP),透過 SMS Retriever API 自動驗證使用者。目前沒有專用 API 可讀取透過 RBM 傳送的 OTP。
Android 的運作方式
如果 Android 應用程式已註冊 SMS Retriever API,則 API 會監聽格式正確的 RBM 訊息。這則訊息必須同時包含 OTP 和可識別應用程式的專屬雜湊。
收到格式正確的 RBM 訊息後,SMS Retriever API 會像處理 SMS OTP 一樣處理這類訊息。雜湊值與應用程式相符後,系統會擷取 OTP 並轉送至應用程式,以便自動驗證使用者。
- 使用者驗證的 RBM 簡訊範例:
Your code is <OTP> <app hash>.
- 範例:
Your code is 123456 M8tue43FGT.
如要進一步瞭解 SMS Retriever 和相關 API,請參閱 SMS Retriever 說明文件。如要進一步瞭解已註冊 SMS Retriever API 的應用程式如何自動驗證使用者,請參閱這張流程圖。
iOS 版運作方式
對於 iOS,系統內建的 OTP 處理機制會自動偵測並建議 RBM OTP 供自動填入,就像 SMS OTP 一樣。iOS 應用程式無須整合特定 API 即可讀取 OTP。
媒體和 PDF 檔案
當您傳送含有圖片、影片、音訊或 PDF 檔案的訊息時,您的服務專員必須提供可供公眾存取的內容網址,或直接上傳檔案。對於媒體檔案,您也可以指定縮圖圖片,讓使用者在點選內容前先行預覽。對於音訊檔案,系統會使用預設的音訊小工具做為預留位置。
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 支援下列媒體類型。縮圖僅支援 image/jpeg、image/jpg、image/gif 和 image/png。
媒體類型 | 文件類型 | 擴充功能 | 支援複合式資訊卡 |
---|---|---|---|
application/ogg | OGG 音訊 | .ogx | 否 |
應用程式/pdf | 否 | ||
audio/aac | AAC 音訊 | .aac | 否 |
audio/mp3 | MP3 音訊 | .mp3 | 否 |
音訊/mpeg | MPEG 音訊 | .mpeg | 否 |
音訊/mpg | MPG 音訊 | .mp3 | 否 |
音訊/mp4 | MP4 音訊 | .mp4 | 否 |
audio/mp4-latm | MP4-latm 音訊 | .mp4 | 否 |
audio/3gpp | 3GPP 音訊 | .3gp | 否 |
圖片/jpeg | JPEG | .jpeg、.jpg | 是 |
圖片/gif | GIF | .gif | 是 |
圖片/png | PNG | .png | 是 |
video/h263 | H263 影片 | .h263 | 是 |
video/m4v | M4V 影片 | .m4v | 是 |
video/mp4 | MP4 影片 | .mp4 | 是 |
影片/mpeg4 | MPEG-4 影片 | .mp4、.m4p | 是 |
影片/mpeg | MPEG 影片 | .mpeg | 是 |
video/webm | WEBM 影片 | .webm | 是 |
建議
您的對話方提供的建議 (建議回覆和建議動作) 會顯示在建議方塊清單 (最多 11 個建議) 或資訊卡 (最多 4 個建議) 中。
每個建議的長度上限為 25 個半形字元。
建議的回覆
建議回覆會提供代理程式可回應的回覆,引導使用者進行對話。
當使用者輕觸建議回覆時,您的服務機器人會收到包含回覆文字和回傳資料的事件。酬載的長度上限為 2048 個半形字元。
範例
以下程式碼會傳送含有兩個建議回覆的文字。如需格式和值選項,請參閱 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 );
建議採取的動作
建議動作會利用裝置內建的功能,引導使用者進行對話。您的服務專員可以建議使用者撥打電話號碼、在地圖上開啟地點、分享地點、開啟網址或建立日曆活動。
針對每個建議動作,您可以選擇提供備用網址 (最多 2048 個半形字元)。如果使用者的裝置不支援建議動作,系統會在新瀏覽器視窗中開啟這個網址。
當使用者輕觸建議的動作時,您的代理程式會收到含有動作回傳資料的事件。
如需格式和值選項,請參閱 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 );
分享位置資訊
「分享位置資訊」動作可讓使用者與服務專員分享位置資訊。使用者可以分享目前位置,或是透過 Google 地圖應用程式手動選取位置。
範例
以下程式碼會傳送分享位置資訊動作。如需格式和值選項,請參閱 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 開啟網址
使用「Open URL with WebView」動作,即可透過預設瀏覽器的轉譯引擎,在訊息應用程式中載入指定網頁。這樣一來,使用者就能在 RBM 對話中與網頁互動,不必離開對話。如果使用者的裝置不支援 WebView,系統會改為在使用者的瀏覽器中開啟網頁。如要啟用網頁檢視畫面,請參閱 OpenURLApplication
。
Webview 有三種顯示模式。如需格式和值選項,請參閱 WebviewViewMode
。
- 全螢幕:網頁會占滿整個螢幕
- Half:網頁占據螢幕一半的空間
- 高:網頁占據螢幕的四分之三
範例
以下程式碼會傳送「開啟網址」與 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; }
建立日曆活動
「建立日曆活動」動作會開啟使用者的日曆應用程式,並開始使用指定資訊建立新活動。
必須提供日曆活動名稱。長度上限為 100 個半形字元。日曆事件說明為選填項目,長度上限為 500 個半形字元。
範例
以下程式碼會傳送建立日曆事件動作。如需格式和值選項,請參閱 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 動作分為三種類型。如需視覺範例,請參閱撰寫文字、語音或影片訊息。
- 撰寫簡訊:開啟訊息應用程式,並為使用者預先填入要傳送的文字。
- 撰寫語音訊息:開啟訊息應用程式並啟動麥克風,讓使用者錄製語音。
- 撰寫影像訊息:開啟訊息應用程式並啟動相機,讓使用者錄製影片。
範例
以下程式碼會傳送 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");
複合式資訊卡輪轉介面
如要向使用者提供多個選項供選擇,請使用複合式資訊卡輪轉介面。輪轉介面會將多個豐富資訊卡串連在一起,讓使用者比較各項商品,並對每項商品做出反應。
輪轉介面最多可包含十張互動式資訊卡,輪轉介面中的複合式資訊卡必須符合一般複合式資訊卡的內容和高度規定。您可以在互動資訊卡中找到輪轉介面規格。
互動式資訊卡輪轉介面酬載的大小上限為 250 KB。請參閱最佳做法,瞭解媒體檔案大小的建議和限制。
截斷
與豐富資訊卡類似,許多因素 (例如螢幕解析度、像素密度和使用者偏好設定) 都會影響資訊卡在使用者端顯示的方式。不過,在輪轉介面中,前幾張資訊卡的高度會決定輪轉介面中所有資訊卡的高度,而資訊卡高度會影響標題、說明和建議的截斷方式。
如果裝置因顯示限制或資訊卡高度而無法顯示資訊卡的所有元素,RBM 會根據下列邏輯截斷資訊卡,直到資訊卡可在裝置上顯示為止:
- 將說明縮減為一行。
- 將標題縮減為一行。
- 從定義清單的結尾開始,省略不符合資訊卡內容的建議。
- 省略說明。
- 省略標題。
為避免標題和說明遭到截斷,請盡可能縮短字數。對於高寬比媒體,請使用標題和說明,或使用一個建議。對於中等媒體,最多使用兩個建議。對於短篇媒體,最多可使用三個建議。如要顯示四個建議,請勿在資訊卡中加入媒體。
請讓資訊卡的內容大小和長度大致相同,並視需要在輪轉介面前端放入較大的資訊卡,避免後續資訊卡遭到截斷。
範例
以下程式碼會傳送複合式資訊卡輪轉介面。如需格式和值選項,請參閱 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);