Gửi tin nhắn

Nhân viên hỗ trợ RBM giao tiếp với người dùng bằng cách gửi và nhận tin nhắn. Để gửi tin nhắn cho người dùng, nhân viên hỗ trợ của bạn gửi yêu cầu tin nhắn đến RCS Business Messaging API. Một yêu cầu có thể bao gồm văn bản, thẻ thông tin, hình ảnh hoặc video, cũng như các câu trả lời đề xuất và hành động được đề xuất.

Nếu bạn gửi tin nhắn cho người dùng có thiết bị không hỗ trợ RCS hoặc không bật RCS, thì nền tảng RBM sẽ trả về lỗi 404. Trong trường hợp này, bạn có thể cố gắng liên hệ với người dùng thông qua các phương thức dự phòng được xác định trong cơ sở hạ tầng của mình.

Nếu bạn gửi tin nhắn cho người dùng RCS trên một mạng mà nhân viên hỗ trợ của bạn chưa ra mắt hoặc trên một mạng chưa bật lưu lượng truy cập RCS, thì nền tảng RBM sẽ trả về lỗi 403.

Nếu bạn gửi tin nhắn có các tính năng mà thiết bị của người dùng không hỗ trợ, thì nền tảng RBM sẽ trả về lỗi và không gửi thông báo của bạn.

Kích thước tối đa của toàn bộ AgentMessage đã chuỗi là 250 KB.

Gửi cho người dùng ngoại tuyến

Nền tảng RBM vẫn chấp nhận tin nhắn để gửi nếu người nhận không có kết nối mạng. Bạn sẽ nhận được phản hồi 200 OK và nền tảng RBM sẽ lưu giữ tin nhắn và cố gắng gửi lại trong vòng 30 ngày. Bạn không cần yêu cầu RBM gửi lại tin nhắn.

RBM sẽ xoá mọi tin nhắn chưa được gửi sau 30 ngày kể từ ngày gửi.

Tuỳ thuộc vào trường hợp sử dụng của nhân viên hỗ trợ, bạn nên thu hồi một tin nhắn chưa được gửi trước thời gian chờ 30 ngày này. Việc thu hồi có thể ngăn người dùng ngoại tuyến nhận được thông báo lỗi thời khi họ kết nối mạng trở lại. Có nhiều cách để thu hồi thông báo:

Đặt thời hạn cho thư

Thời gian nhắn tin của nhân viên hỗ trợ có nhạy cảm không? Ví dụ: OTP chỉ có hiệu lực trong một khoảng thời gian ngắn. Ưu đãi trong thời gian có hạn. Và lời nhắc cuộc hẹn không phù hợp sau ngày hẹn. Để giúp đảm bảo các thông báo kịp thời và phù hợp, hãy đặt ngày hết hạn của thông báo. Điều này có thể ngăn người dùng ngoại tuyến nhận được nội dung cũ khi họ trực tuyến trở lại. Thời hạn cũng là một gợi ý phù hợp để gọi chiến lược thông báo dự phòng, giúp người dùng nhận được thông tin họ cần đúng lúc.

Để đặt thời hạn cho tin nhắn, hãy chỉ định một trong các trường sau trong thông báo của nhân viên hỗ trợ:

  • expireTime: thời gian chính xác theo giờ UTC khi thông báo hết hạn.
  • ttl(thời gian tồn tại): khoảng thời gian trước khi thông báo hết hạn.

Để biết các tuỳ chọn định dạng và giá trị, hãy xem AgentMessage.

Sau khi thông báo hết hạn, nền tảng RBM sẽ ngừng tìm cách gửi thông báo và thông báo đó sẽ tự động bị thu hồi. Tuy nhiên, quá trình này có thể không thành công trong một số ít trường hợp. Ví dụ: API có thể kích hoạt việc thu hồi trong khi nền tảng RBM đang trong quá trình gửi thông báo. Để xác nhận xem thông báo hết hạn có được thu hồi thành công hay không, RBM sẽ gửi một sự kiện thông báo đến webhook của bạn.

Văn bản

Những thông điệp đơn giản nhất đều được tạo thành từ văn bản. Tin nhắn văn bản phù hợp nhất để giao tiếp thông tin mà không cần hình ảnh, hoạt động tương tác phức tạp hay phản hồi.

Ví dụ:

Mã sau đây sẽ gửi một tin nhắn văn bản đơn giản. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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);
});
Mã này là phần trích dẫn từ tác nhân mẫu 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();
}
Mã này là phần trích dẫn từ tác nhân mẫu 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')
Mã này là phần trích dẫn từ tác nhân mẫu RBM.

C#

using RCSBusinessMessaging;
…

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

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
);
Mã này là phần trích dẫn từ tác nhân mẫu RBM.

Nội dung tin nhắn cơ bản - chuyển đổi SMS

Các nhà mạng đã ra mắt mô hình thanh toán để hỗ trợ việc di chuyển tin nhắn SMS sang RBM. Thông báo RBM chứa tối đa 160 ký tự UTF-8 sẽ được gọi là Thông báo cơ bản.

Khi tạo yêu cầu gửi Thông báo cơ bản, hãy nhớ rằng các ký tự được tính là 1 byte (UTF-8). Nếu bạn gửi tin nhắn chứa các ký tự đặc biệt, chẳng hạn như biểu tượng cảm xúc hoặc một bộ ký tự nhiều byte, thì mỗi ký tự sẽ được tính là 2 ký tự UTF-8.

Nhập nội dung văn bản vào hộp để kiểm tra độ dài của văn bản:

Mật khẩu một lần để xác minh người dùng

Bạn có thể sử dụng RBM để gửi mật khẩu một lần (OTP) nhằm tự động xác minh người dùng bằng SMS Retriever API. Để tìm hiểu thêm về Trình thu thập dữ liệu SMS và các API liên quan, hãy xem tài liệu về Trình truy xuất qua SMS. Để biết thông tin chi tiết về tính năng tự động xác minh người dùng trong các ứng dụng đã đăng ký bằng SMS Retriever API, hãy xem sơ đồ quy trình này.

Trong quá trình xác minh, SMS Retriever API sẽ theo dõi thông báo RBM. Tin nhắn này phải chứa một OTP và một hàm băm xác định ứng dụng. Sau khi khớp với ứng dụng, OTP sẽ được trích xuất và chuyển tiếp đến ứng dụng để tự động xác minh người dùng.

Dưới đây là tin nhắn văn bản RBM mẫu để xác minh người dùng: Mã của bạn là <OTP> <hàm băm ứng dụng>.

Ví dụ: Your code is 123456 M8tue43FGT.

Tệp đa phương tiện và PDF

Khi bạn gửi tin nhắn có tệp hình ảnh, video hoặc PDF, nhân viên hỗ trợ của bạn phải cung cấp URL có thể truy cập công khai cho nội dung hoặc trực tiếp tải tệp lên. Đối với tệp nội dung nghe nhìn, bạn cũng có thể chỉ định hình thu nhỏ để người dùng có thể xem trước nội dung trước khi nhấp vào.

Nền tảng RBM sẽ lưu các tệp vào bộ nhớ đệm trong 60 ngày và API sẽ trả về một mã tệp mà nhân viên hỗ trợ của bạn có thể đưa vào thông báo gửi tới người dùng. Sau 60 ngày, RBM sẽ xoá các tệp khỏi bộ nhớ đệm.

Xem các phương pháp hay nhất để nắm được đề xuất và giới hạn về kích thước tệp.

Ví dụ về URL của tệp

Mã sau đây gửi một hình ảnh. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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);
});
Mã này là phần trích dẫn từ tác nhân mẫu 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();
}
Mã này là phần trích dẫn từ tác nhân mẫu 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')
Mã này là phần trích dẫn từ tác nhân mẫu 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");
Mã này là phần trích dẫn từ tác nhân mẫu RBM.

Ngoài ra, bạn có thể tải nội dung nghe nhìn lên trước khi gửi trong thông báo bằng files.create.

Ví dụ về tải tệp lên

Mã sau đây tải một tệp video và một tệp hình thu nhỏ lên, sau đó gửi cả hai tệp trong một thông báo. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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'
   }
  }
}"

Loại nội dung nghe nhìn được hỗ trợ

RBM hỗ trợ các loại nội dung nghe nhìn sau đây:

Loại nội dung nghe nhìn Loại tài liệu Phần mở rộng Hoạt động với thẻ thông tin
ứng dụng/pdf PDF .pdf Không
image/jpeg JPEG .jpeg, .jpg
hình ảnh/gif GIF .gif
image/png PNG .png
video/h263 Video H263 .h263
video/m4v Video M4V .m4v
video/mp4 Video MP4 .mp4
video/mpeg4 Video MPEG-4 .mp4, .m4p
video/mpeg Video MPEG .mpeg
video/webm Video WEBM .webm

Câu trả lời đề xuất

Câu trả lời đề xuất sẽ hướng dẫn người dùng đi qua các cuộc trò chuyện bằng cách cung cấp câu trả lời mà nhân viên hỗ trợ của bạn biết cách phản ứng. Nhân viên hỗ trợ của bạn gửi các câu trả lời đề xuất trong danh sách khối đề xuất hoặc trong thẻ nhiều định dạng.

Khi người dùng nhấn vào một câu trả lời đề xuất, nhân viên hỗ trợ sẽ nhận được một sự kiện chứa văn bản của câu trả lời đó và dữ liệu đăng lại.

Câu trả lời đề xuất có tối đa 25 ký tự.

Ví dụ:

Mã sau đây gửi văn bản cùng với hai câu trả lời đề xuất. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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);
});
Mã này là phần trích dẫn từ tác nhân mẫu 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();
}
Mã này là phần trích dẫn từ tác nhân mẫu 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')
Mã này là phần trích dẫn từ tác nhân mẫu 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
);
Mã này là phần trích dẫn từ tác nhân mẫu RBM.

Hành động đề xuất

Các thao tác đề xuất sẽ hướng dẫn người dùng đi qua các cuộc trò chuyện bằng cách kích hoạt chức năng gốc của thiết bị của họ. Nhân viên hỗ trợ của bạn có thể đề xuất người dùng quay số, mở một vị trí trên bản đồ, chia sẻ vị trí, mở URL hoặc tạo một sự kiện trên lịch. Nhân viên hỗ trợ của bạn gửi các hành động được đề xuất trong danh sách khối đề xuất hoặc trong thẻ nhiều định dạng.

Khi người dùng nhấn vào một hành động đề xuất, nhân viên hỗ trợ sẽ nhận được một sự kiện có chứa dữ liệu đăng lại của hành động đó.

Các hành động được đề xuất có tối đa 25 ký tự.

Để biết các tuỳ chọn định dạng và giá trị, hãy xem SuggestedAction.

Quay số

Thao tác quay số sẽ hướng dẫn người dùng gọi đến số điện thoại mà nhân viên hỗ trợ của bạn chỉ định. Số điện thoại cần có dấu + ở đầu, mã quốc gia và mã vùng, nhưng không được chứa dấu phân cách. Ví dụ: +14155555555.

Ví dụ:

Mã sau đây sẽ gửi một thao tác quay số. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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);
});
Mã này là phần trích dẫn từ tác nhân mẫu 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();
}
Mã này là phần trích dẫn từ tác nhân mẫu 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')
Mã này là phần trích dẫn từ tác nhân mẫu 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
);
Mã này là phần trích dẫn từ tác nhân mẫu RBM.

Xem vị trí

Thao tác Xem vị trí hiển thị một vị trí trong ứng dụng bản đồ mặc định của người dùng. Bạn có thể chỉ định vị trí theo vĩ độ và kinh độ hoặc bằng truy vấn dựa trên vị trí hiện tại của người dùng. Bạn cũng có thể đặt nhãn tuỳ chỉnh cho ghim hiển thị trong ứng dụng bản đồ.

Ví dụ:

Mã sau đây sẽ gửi một thao tác xem vị trí. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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);
});
Mã này là phần trích dẫn từ tác nhân mẫu 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();
}
Mã này là phần trích dẫn từ tác nhân mẫu 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')
Mã này là phần trích dẫn từ tác nhân mẫu 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
);
Mã này là phần trích dẫn từ tác nhân mẫu RBM.

Chia sẻ vị trí

Thao tác Chia sẻ vị trí cho phép người dùng gửi thông tin vị trí cho nhân viên hỗ trợ của bạn. Vị trí mà người dùng chỉ định không nhất thiết là vị trí của người dùng.

Ví dụ:

Mã sau đây sẽ gửi thao tác chia sẻ vị trí. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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);
});
Mã này là phần trích dẫn từ tác nhân mẫu 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();
}
Mã này là phần trích dẫn từ tác nhân mẫu 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')
Mã này là phần trích dẫn từ tác nhân mẫu 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
);
Mã này là phần trích dẫn từ tác nhân mẫu RBM.

Mở một URL

Thao tác Mở URL sẽ mở trình duyệt web của người dùng đến URL được chỉ định. Nếu một ứng dụng được đăng ký làm trình xử lý mặc định cho URL, thì ứng dụng đó sẽ mở ra và biểu tượng của hành động đó sẽ là biểu tượng của ứng dụng.

Ví dụ:

Mã sau đây sẽ gửi một thao tác mở URL. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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);
});
Mã này là phần trích dẫn từ tác nhân mẫu 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();
}
Mã này là phần trích dẫn từ tác nhân mẫu 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')
Mã này là phần trích dẫn từ tác nhân mẫu 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
);
Mã này là phần trích dẫn từ tác nhân mẫu RBM.

Tạo sự kiện lịch

Thao tác Tạo sự kiện trên lịch sẽ mở ứng dụng lịch của người dùng và bắt đầu tạo sự kiện mới với thông tin được chỉ định.

Ví dụ:

Mã sau đây sẽ gửi một thao tác tạo sự kiện trên lịch. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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);
});
Mã này là phần trích dẫn từ tác nhân mẫu 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();
}
Mã này là phần trích dẫn từ tác nhân mẫu 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')
Mã này là phần trích dẫn từ tác nhân mẫu 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
);
Mã này là phần trích dẫn từ tác nhân mẫu RBM.

Danh sách khối đề xuất

Nhân viên hỗ trợ của bạn sẽ gửi danh sách khối đề xuất kèm theo thông báo để hướng dẫn người dùng thực hiện các hành động tiếp theo. Danh sách khối chỉ hiển thị khi tin nhắn liên quan nằm ở cuối cuộc trò chuyện. Mọi tin nhắn tiếp theo trong cuộc trò chuyện (của người dùng hoặc nhân viên hỗ trợ của bạn) sẽ ghi đè danh sách khối.

Các khối trong danh sách là câu trả lời đề xuấthành động được đề xuất.

Danh sách khối chứa tối đa 11 khối đề xuất và mỗi nhãn khối có thể có tối đa 25 ký tự.

Để biết các tuỳ chọn định dạng và giá trị, hãy xem AgentContentMessage.

Thẻ thông tin

Khi cần gửi một đoạn thông tin, nội dung nghe nhìn hoặc đề xuất liên quan, bạn nên gửi một thẻ thông tin. Thẻ thông tin cho phép nhân viên hỗ trợ gửi nhiều đơn vị thông tin trong một tin nhắn.

Thẻ thông tin có thể chứa các mục sau:

  • Hình ảnh/video
  • Văn bản tiêu đề
  • Nội dung mô tả
  • Danh sách câu trả lời đề xuất và hành động được đề xuất (tối đa 4)

Thẻ thông tin có thể chứa tất cả các mục được liệt kê, nhưng thẻ phải chứa ít nhất một hình ảnh, video hoặc tiêu đề thì mới hợp lệ. Mỗi thẻ thông tin có thể chứa tối đa 4 hành động được đề xuất hoặc câu trả lời đề xuất. Thẻ này không thể kết hợp hành động đề xuất và câu trả lời đề xuất trên một thẻ.

Nhân viên hỗ trợ của bạn có thể gửi nhiều thẻ thông tin cùng nhau trong một băng chuyền thẻ thông tin.

Chiều cao thẻ

Thẻ sẽ mở rộng theo chiều dọc để vừa với nội dung. Thẻ thông tin có chiều cao tối thiểu là 112 DP và chiều cao tối đa là 344 DP. Nếu nội dung của thẻ không đủ lớn để lấp đầy chiều cao thẻ tối thiểu, thì thẻ sẽ mở rộng và lấp đầy chiều cao thừa bằng khoảng trắng.

Nội dung nghe nhìn trong thẻ đa phương tiện phải vừa với một trong ba chiều cao:

  • Ngắn: 112 DP
  • Trung bình: 168 DP
  • Cao: 264 DP

Nếu nội dung nghe nhìn không vừa với kích thước trong thẻ dựa trên chiều cao đã chọn, thì bản xem trước nội dung nghe nhìn sẽ được chọn bằng cách thu phóng và cắt nội dung nghe nhìn.

Ví dụ:

Mã sau đây sẽ gửi một thẻ thông tin có hình ảnh và các câu trả lời đề xuất. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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);
});
Mã này là phần trích dẫn từ tác nhân mẫu 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();
}
Mã này là phần trích dẫn từ tác nhân mẫu 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')
Mã này là phần trích dẫn từ tác nhân mẫu 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");
Mã này là phần trích dẫn từ tác nhân mẫu RBM.

Băng chuyền thẻ thông tin

Khi bạn cần hiển thị cho người dùng nhiều tuỳ chọn để lựa chọn, hãy sử dụng băng chuyền thẻ thông tin. Băng chuyền xâu chuỗi nhiều thẻ thông tin lại với nhau, cho phép người dùng so sánh các mục và tương tác với từng mục.

Băng chuyền có thể chứa tối thiểu hai và tối đa mười thẻ thông tin. Thẻ thông tin trong băng chuyền phải tuân thủ các yêu cầu chung về thẻ thông tin về nội dung và chiều cao.

Giống như thẻ nhiều định dạng, có nhiều yếu tố (chẳng hạn như độ phân giải màn hình, mật độ pixel và lựa chọn ưu tiên của người dùng) ảnh hưởng đến cách thẻ hiển thị cho người dùng cuối. Tuy nhiên, trong băng chuyền, chiều cao của một số thẻ đầu tiên xác định chiều cao của tất cả các thẻ trong băng chuyền và chiều cao thẻ ảnh hưởng đến tiêu đề, nội dung mô tả và việc cắt bớt đề xuất.

Nếu thiết bị không thể hiển thị tất cả các phần tử của thẻ do các hạn chế về màn hình hoặc chiều cao của thẻ, thì RBM sẽ cắt bớt thẻ cho đến khi có thể hiển thị trên thiết bị, bằng cách sử dụng logic sau:

  1. Hãy rút gọn nội dung mô tả xuống còn một dòng.
  2. Hãy rút ngắn tiêu đề xuống còn một dòng.
  3. Bỏ qua các đề xuất không phù hợp với thẻ, bắt đầu từ cuối danh sách đã xác định.
  4. Bỏ qua phần mô tả.
  5. Bỏ qua tiêu đề.

Để tránh bị cắt bớt, hãy giữ tiêu đề và nội dung mô tả càng ngắn gọn càng tốt. Đối với nội dung đa phương tiện, hãy sử dụng tiêu đề và nội dung mô tả hoặc một đề xuất. Đối với nội dung nghe nhìn trung bình, hãy sử dụng tối đa 2 đề xuất. Đối với nội dung truyền thông ngắn, hãy dùng tối đa 3 đề xuất. Để điều chỉnh vừa với 4 đề xuất, không đưa nội dung nghe nhìn vào thẻ.

Giữ các thẻ tương đương về kích thước và độ dài nội dung. Nếu cần, hãy tải trước băng chuyền bằng các thẻ lớn hơn để tránh bị cắt bớt trong các thẻ sau.

Ví dụ:

Mã sau đây sẽ gửi một băng chuyền thẻ thông tin. Để biết các tuỳ chọn định dạng và giá trị, hãy xem 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);
});
Mã này là phần trích dẫn từ tác nhân mẫu 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();
        }
Mã này là phần trích dẫn từ tác nhân mẫu 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')
Mã này là phần trích dẫn từ tác nhân mẫu 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);
Mã này là phần trích dẫn từ tác nhân mẫu RBM.