傳送訊息

RBM 代理程式會透過傳送和接收訊息與使用者溝通。如要傳送訊息給使用者,您的代理程式會將訊息要求傳送至 RCS Business Messaging API。單一要求可包含文字、互動式資訊卡、圖片或影片,以及建議回覆和建議動作。

如果您傳送訊息給使用者,但對方的裝置不支援 RCS 或未啟用 RCS,RBM 平台會傳回 404 錯誤。在這種情況下,您可以嘗試透過基礎架構中定義的備用方法聯絡使用者。

如果您在尚未推出代理程式的網路,或尚未啟用 RCS 流量的網路上,傳送訊息給 RCS 使用者,RBM 平台會傳回 403 錯誤。

如果您傳送的訊息含有使用者裝置不支援的功能,RBM 平台會傳回錯誤,並且不會傳送您的訊息。

在多管道訊息策略中,建議您在合理時間後撤銷未送達的訊息,並透過其他管道傳送。如要在預先設定的時間自動撤銷訊息,請設定訊息到期時間

接收者目前不在線上

如果收件者處於離線狀態,RBM 平台仍會接受訊息傳送作業。您會收到 200 OK 回應,且 RBM 平台會保留訊息並嘗試重新傳送 30 天。您不必要求 RBM 再次傳送訊息。

RBM 會在提交後 30 天後刪除所有未送達的訊息。

視服務機器人的用途而定,您可能會在 30 天逾時前撤銷未送達的訊息。撤銷功能可避免離線使用者在重新連上網路時收到過時的訊息。您可以透過多種方式撤銷訊息:

設定訊息到期日

你的服務專員是否傳送了具有時效性的訊息?舉例來說,一次性密碼的有效期間很短。限時優惠到期。而且,預約日期過後,預約提醒就不再適用。為確保及時且相關的訊息,請設定郵件到期日。這麼做可避免離線使用者在重新上線時收到過時的內容。到期日也是觸發備用訊息策略的好方法,可讓使用者及時取得所需資訊。

如要設定訊息到期日,請在代理程式訊息中指定下列其中一個欄位:

  • expireTime:訊息到期時間 (以世界標準時間為準)。
  • ttl(存留時間):訊息到期前剩餘的時間。

如需格式和值選項,請參閱 AgentMessage

訊息到期後,RBM 平台就會停止嘗試傳送訊息,並自動撤銷訊息。不過,在少數情況下,這可能會失敗。舉例來說,API 可能會在 RBM 平台傳送訊息的過程中觸發撤銷作業。為確認是否已成功撤銷過期訊息,RBM 會將通知事件傳送至您的 webhook。

ttlexpireTime 的最大值為提交訊息後的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);
});
以下程式碼節錄自 RBM 範例服務專員

Java

import com.google.rbm.RbmApiHelper;


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

   // Send simple text message to user
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444"
   );
} catch(Exception e) {
   e.printStackTrace();
}
以下程式碼節錄自 RBM 範例服務專員

Python

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

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

# Send text message to the device
messages.MessageCluster().append_message(message_text).send_to_msisdn('+12223334444')
以下程式碼節錄自 RBM 範例服務專員

C#

using RCSBusinessMessaging;


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

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
);
以下程式碼節錄自 RBM 範例服務專員

基本訊息內容 - 簡訊轉換

電信業者已推出收費模式,可支援將簡訊遷移至 RBM。含有最多 160 個 UTF-8 字元的 RBM 訊息稱為基本訊息。

建構要求以傳送基本訊息時,請記住字元會計為 1 個位元組 (UTF-8)。如果您傳送的訊息含有表情符號或多位元字元集等特殊字元,每個字元都會計為 2 個 UTF-8 字元。

在方塊中輸入文字,確認其長度:

用於使用者驗證的一次性密碼

您可以使用 RBM 傳送一次性密碼 (OTP),透過 SMS Retriever API 自動驗證使用者。如要進一步瞭解 SMS Retriever 和相關 API,請參閱 SMS Retriever 說明文件。如要進一步瞭解已註冊 SMS Retriever API 的應用程式如何自動驗證使用者,請參閱這份流程圖

在驗證程序期間,SMS Retriever API 會監聽 RBM 訊息。這則訊息必須包含 OTP 和可識別應用程式的雜湊。雜湊與應用程式比對後,系統會擷取 OTP 並轉送至應用程式,以便自動驗證使用者。

以下是用於使用者驗證的 RBM 簡訊範例:您的驗證碼為 <OTP> <app hash>。

例如:Your code is 123456 M8tue43FGT.

媒體和 PDF 檔案

當您傳送含有圖片、影片、音訊或 PDF 檔案的訊息時,您的服務專員必須提供可供公眾存取的內容網址,或直接上傳檔案。對於媒體檔案,您也可以指定縮圖圖片,讓使用者在點選內容前先行預覽。對於音訊檔案,系統會使用預設的音訊小工具做為預留位置。

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);
});
以下程式碼節錄自 RBM 範例服務專員

Java

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


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

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

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

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

   rbmApiHelper.sendAgentMessage(agentMessage, "+12223334444");
} catch(Exception e) {
   e.printStackTrace();
}
以下程式碼節錄自 RBM 範例服務專員

Python

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

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

messages.MessageCluster().append_message(file_message).send_to_msisdn('+12223334444')
以下程式碼節錄自 RBM 範例服務專員

C#

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


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

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

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

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

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

rbmApiHelper.SendAgentMessage(agentMessage, "+12223334444");
以下程式碼節錄自 RBM 範例服務專員

或者,您也可以先上傳媒體,然後再使用 files.create 將媒體傳送至訊息。

檔案上傳範例

以下程式碼會上傳影片檔案和縮圖檔案,然後在訊息中傳送這兩個檔案。如需格式和值選項,請參閱 files.createAgentContentMessage

cURL

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

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


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

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


curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'uploadedRbmFile': {
      'fileName': 'SERVER-SPECIFIED_VIDEO_FILE_NAME'
        'thumbnailName': 'SERVER-SPECIFIED_THUMBNAIL_FILE_NAME'
   }
  }
}"

支援的媒體類型

RBM 支援下列媒體類型:

媒體類型 文件類型 擴充功能 支援複合式資訊卡
application/ogg OGG 音訊 .ogx
應用程式/pdf PDF .pdf
audio/aac AAC 音訊 .aac
audio/mp3 MP3 audio .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

建議的回覆

建議回覆會提供代理程式可回應的回覆,引導使用者進行對話。服務機器人會在建議方塊清單互動式資訊卡中傳送建議回覆。

當使用者輕觸建議回覆時,您的服務機器人會收到含有回覆文字和回傳資料的事件

建議回覆的長度上限為 25 個半形字元。

範例

以下程式碼會傳送含有兩個建議回覆的文字。如需格式和值選項,請參閱 SuggestedReply

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'reply': {
          'text': 'Suggestion #1',
          'postbackData': 'suggestion_1'
        }
      },
      {
        'reply': {
          'text': 'Suggestion #2',
          'postbackData': 'suggestion_2'
        }
      }
    ]
  }
}"

Node.js

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

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

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

// Send a simple message with suggestion chips to the device
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
以下程式碼節錄自 RBM 範例服務專員

Java

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


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

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

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

   // Send simple text message to user
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
以下程式碼節錄自 RBM 範例服務專員

Python

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

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

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

# Send a simple message with suggestion chips to the device
cluster.send_to_msisdn('+12223334444')
這段程式碼是 RBM 範例服務專員的摘錄。

C#

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


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

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

// Send simple text message with suggestions to user
rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
   suggestions
);
以下程式碼節錄自 RBM 範例服務專員

建議採取的動作

建議動作會利用裝置內建的功能,引導使用者進行對話。您的服務專員可以建議使用者撥打電話號碼、在地圖上開啟地點、分享地點、開啟網址或建立日曆活動。您的服務機器人會在建議方塊清單資訊卡中傳送建議動作。

當使用者輕觸建議的動作時,您的代理程式會收到含有動作回傳資料的事件

建議動作的長度上限為 25 個半形字元。

如需格式和值選項,請參閱 SuggestedAction

撥號

撥號動作會引導使用者撥打代理程式指定的電話號碼。電話號碼只能包含數字 (0-9)、加號 (+)、星號 (*) 和數字符號 (#)。系統支援 E.164 國際格式 (例如 +14155555555),但不強制要求使用。也就是說,+141555555551011 都是有效的項目。

範例

以下程式碼會傳送撥號動作。如需格式和值選項,請參閱 DialAction

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Call',
          'postbackData': 'postback_data_1234',
          'fallbackUrl': 'https://www.google.com/contact/',
          'dialAction': {
            'phoneNumber': '+15556667777'
          }
        }
      }
    ]
  }
}"

Node.js

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

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

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

// Send a simple message with a dial suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
以下程式碼節錄自 RBM 範例服務專員

Java

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


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

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

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

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

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

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
以下程式碼節錄自 RBM 範例服務專員

Python

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

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

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

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

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
以下程式碼節錄自 RBM 範例服務專員

C#

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


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

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

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

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

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

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
以下程式碼節錄自 RBM 範例服務專員

查看地點

「查看位置」動作會在使用者的預設地圖應用程式中顯示位置。您可以透過經緯度或使用者目前位置的查詢,指定位置。您也可以為地圖應用程式中顯示的圖釘設定自訂標籤。

範例

以下程式碼會傳送查看位置動作。如需格式和值選項,請參閱 ViewLocationAction

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'View map',
          'postbackData': 'postback_data_1234',
          'fallbackUrl': 'https://www.google.com/maps/@37.4220188,-122.0844786,15z',
          'viewLocationAction': {
            'latLong': {
              'latitude': "37.4220188',
              'longitude': "-122.0844786'
            },
            'label': 'Googleplex'
          }
        }
      }
    ]
  }
}"

Node.js

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

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

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

// Send a simple message with a view location suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
以下程式碼節錄自 RBM 範例服務專員

Java

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


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

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

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

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

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

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
以下程式碼節錄自 RBM 範例服務專員

Python

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

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

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

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

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
這段程式碼是 RBM 範例服務專員的摘錄。

C#

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


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

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

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

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

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

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
以下程式碼節錄自 RBM 範例服務專員

分享位置資訊

分享位置動作可讓使用者將位置資訊傳送給你的服務專員。使用者指定的位置不一定是使用者的位置。

範例

以下程式碼會傳送分享位置資訊動作。如需格式和值選項,請參閱 ShareLocationAction

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Share your location',
          'postbackData': 'postback_data_1234',
          'shareLocationAction': {}
        }
      }
    ]
  }
}"

Node.js

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

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

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

// Send a simple message with a share location suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
以下程式碼節錄自 RBM 範例服務專員

Java

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


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

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

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

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

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

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
以下程式碼節錄自 RBM 範例服務專員

Python

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

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

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

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

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
以下程式碼節錄自 RBM 範例服務專員

C#

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


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

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

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

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

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

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
以下程式碼節錄自 RBM 範例服務專員

開啟網址

開啟網址動作可讓您將使用者導向代理程式指定的網頁。根據預設,網頁會在使用者的瀏覽器中開啟。如果使用者已為網頁設定預設應用程式,系統會改為開啟該應用程式。在這種情況下,建議動作按鈕上的圖示會是應用程式的圖示。

「開啟網址」動作也支援整合的 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);
});
以下程式碼節錄自 RBM 範例服務專員

Java

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


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

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

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

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

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

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
以下程式碼節錄自 RBM 範例服務專員

Python

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

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

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

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

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
以下程式碼節錄自 RBM 範例服務專員

C#

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


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

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

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

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

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

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
這段程式碼是 RBM 範例服務專員的摘錄。

使用 WebView 開啟網址

使用「Open URL with WebView」動作,可透過預設瀏覽器的轉譯引擎,在訊息應用程式中載入指定網頁。這樣一來,使用者就能在 RBM 對話中與網頁互動,不必離開對話。如要啟用網頁檢視畫面,請參閱 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;
    }

建立日曆活動

「建立日曆活動」動作會開啟使用者的日曆應用程式,並開始使用指定資訊建立新活動。

範例

以下程式碼會傳送建立日曆事件的動作。如需格式和值選項,請參閱 CreateCalendarEventAction

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Save to calendar',
          'postbackData': 'postback_data_1234',
          'fallbackUrl': 'https://www.google.com/calendar',
          'createCalendarEventAction': {
            'startTime': '2020-06-30T19:00:00Z',
            'endTime': '2020-06-30T20:00:00Z',
            'title': 'My calendar event',
            'description': 'Description of the calendar event'
          }
        }
      }
    ]
  }
}"

Node.js

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

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

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

// Send a simple message with a create calendar event suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
以下程式碼節錄自 RBM 範例服務專員

Java

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


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

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

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

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

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

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
以下程式碼節錄自 RBM 範例服務專員

Python

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

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

]

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

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

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
以下程式碼節錄自 RBM 範例服務專員

C#

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


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

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

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

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

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

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
以下程式碼節錄自 RBM 範例服務專員

撰寫郵件

Compose 動作會開啟使用者的訊息應用程式,方便他們傳送訊息給預先定義的電話號碼,例如客服專線。

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
  };

  List suggestions = 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);
});
以下程式碼節錄自 RBM 範例服務專員

Java

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


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

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

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

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

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

   rbmApiHelper.sendStandaloneCard(standaloneCard, "+12223334444");
} catch(Exception e) {
   e.printStackTrace();
}
以下程式碼節錄自 RBM 範例服務專員

Python

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

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

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

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

# Append rich card and send to the user
cluster = messages.MessageCluster().append_message(rich_card)
cluster.send_to_msisdn('+12223334444')
以下程式碼節錄自 RBM 範例服務專員

C#

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


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

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

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

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

// Send rich card to user
rbmApiHelper.SendStandaloneCard(standaloneCard, "+12223334444");
以下程式碼節錄自 RBM 範例服務專員

複合式資訊卡輪轉介面

如要向使用者提供多個選項供選擇,請使用複合式資訊卡輪轉介面。輪轉介面會將多個豐富資訊卡串連在一起,讓使用者比較各項商品,並對每項商品做出反應。

輪轉介面最多可包含十張互動式資訊卡,輪轉介面中的複合式資訊卡必須符合一般複合式資訊卡的內容和高度規定。

互動式資訊卡輪轉介面酬載的大小上限為 250 KB。請參閱最佳做法,瞭解媒體檔案大小的建議和限制。

豐富資訊卡類似,許多因素 (例如螢幕解析度、像素密度和使用者偏好設定) 都會影響資訊卡在使用者端顯示的方式。不過,在輪轉介面中,前幾張資訊卡的高度會決定輪轉介面中所有資訊卡的高度,而資訊卡高度會影響標題、說明和建議的截斷方式。

如果裝置因顯示限制或資訊卡高度而無法顯示資訊卡的所有元素,RBM 會根據以下邏輯截斷資訊卡,直到資訊卡可在裝置上顯示為止:

  1. 將說明縮減為一行。
  2. 將標題縮減為一行。
  3. 從定義清單的結尾開始,省略不符合資訊卡內容的建議。
  4. 省略說明。
  5. 省略標題。

為避免標題和說明遭到截斷,請盡量簡短。對於高型媒體,請使用標題和說明,或使用一個建議。對於中等媒體,最多可使用兩個建議。對於短篇媒體,最多可使用三個建議。為了讓四個建議顯示在資訊卡中,請不要加入媒體。

請讓資訊卡的內容大小和長度大致相同,並視需要在輪轉介面中先載入較大的資訊卡,避免後續資訊卡遭到截斷。

範例

以下程式碼會傳送複合式資訊卡輪轉介面。如需格式和值選項,請參閱 RichCard

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'richCard': {
      'carouselCard': {
        'cardWidth':'MEDIUM',
        'cardContents': [
          {
            'title':'Card #1',
            'description':'The description for card #1',
            'suggestions': [
              {
                'reply': {
                  'text':'Card #1',
                  'postbackData':'card_1'
                }
              }
            ],
            'media': {
              'height':'MEDIUM',
              'contentInfo': {
                'fileUrl':'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg',
                'forceRefresh':'false'
              }
            }
          },
          {
            'title':'Card #2',
            'description':'The description for card #2',
            'suggestions': [
              {
                'reply': {
                  'text':'Card #2',
                  'postbackData':'card_2'
                }
              }
            ],
            'media': {
              'height':'MEDIUM',
              'contentInfo': {
                'fileUrl':'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg',
                'forceRefresh': 'false'
              }
            }
          }
        ]
      }
    }
  }
}"

Node.js

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

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

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

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

// Send the device the carousel card defined above
rbmApiHelper.sendCarouselCard(params, function(response) {
   console.log(response);
});
以下程式碼節錄自 RBM 範例服務專員

Java

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


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

            List cardContents = new ArrayList();

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

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

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

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

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

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

            // Send the carousel to the user
            rbmApiHelper.sendCarouselCards(cardContents, CardWidth.MEDIUM, "+12223334444");
        } catch(Exception e) {
            e.printStackTrace();
        }
以下程式碼節錄自 RBM 範例服務專員

Python

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

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

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

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

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

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

# Send the device the carousel card defined above
carousel_card = messages.CarouselCard('MEDIUM', card_contents)
cluster = messages.MessageCluster().append_message(carousel_card)
cluster.send_to_msisdn('+12223334444')
以下程式碼節錄自 RBM 範例服務專員

C#

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


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

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

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

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

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

// Send the carousel to the user
rbmApiHelper.SendCarouselCards(cardContents, CardWidth.MEDIUM, msisdn);
以下程式碼節錄自 RBM 範例服務專員