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, tác nhân của bạn sẽ gửi yêu cầu gửi tin nhắn đến RCS Business Messaging API. Một yêu cầu có thể bao gồm văn bản, thẻ đa dạng thức, tệp đa phương tiện và PDF, cũng như câu trả lời đề xuất và hành động đề xuất.
Nền tảng RBM sẽ trả về lỗi trong một số trường hợp để giúp bạn quản lý việc gửi tin nhắn:
- Nếu bạn gửi tin nhắn cho một 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 NOT_FOUND. 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 đến một người dùng RCS trên mạng mà nhân viên hỗ trợ của bạn chưa được ra mắt hoặc trên 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 404 NOT_FOUND.
- Nếu bạn gửi một 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 400 INVALID_ARGUMENT và không gửi tin nhắn của bạn.
Trong chiến lược nhắn tin đa kênh, tốt nhất là bạn nên thu hồi những tin nhắn không được gửi sau một khoảng thời gian hợp lý và gửi chúng qua một kênh khác. Để tự động thu hồi tin nhắn vào một thời điểm xác định trước, hãy thiết lập thời gian hết hạn của tin nhắn.
Người nhận đang ngoại tuyến
Nền tảng RBM vẫn chấp nhận một tin nhắn để gửi nếu người nhận đang không kết nối mạng. Bạn nhận được phản hồi 200 OK và nền tảng RBM giữ lại thông báo và cố gắng gửi lại trong 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ừ khi tin nhắn được gửi.
Tuỳ thuộc vào trường hợp sử dụng của tác nhân, bạn có thể muốn thu hồi một thông báo 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 không có kết nối mạng 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 một tin nhắn:
- Gửi yêu cầu thu hồi để kích hoạt quy trình thu hồi.
- Đặt thời gian hết hạn cho tin nhắn để tự động thu hồi tin nhắn vào thời điểm thích hợp.
Đặt thời hạn cho tin nhắn
Tin nhắn của nhân viên hỗ trợ có cần được gửi ngay 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 sẽ hết hiệu lực. Lời nhắc về cuộc hẹn sẽ không còn phù hợp sau ngày hẹn. Để đảm bảo thông báo kịp thời và phù hợp, hãy đặt thời gian hết hạn cho thông báo. Điều này có thể ngăn người dùng không có mạng nhận được nội dung cũ khi họ kết nối lại với mạng. Thời gian hết hạn cũng là một tín hiệu tốt để kích hoạt chiến lược nhắn tin dự phòng, nhờ đó người dùng nhận được thông tin họ cần đúng lúc.
Để đặt thời gian hết hạn của tin nhắn, hãy chỉ định một trong các trường sau trong tin nhắn của tác nhân:
expireTime
: thời gian chính xác theo giờ UTC khi thư 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 lựa chọn về định dạng và giá trị, hãy xem AgentMessage
.
Sau khi tin nhắn hết hạn, nền tảng RBM sẽ ngừng cố gắng gửi tin nhắn và tin nhắn đó sẽ tự động bị thu hồi. Tuy nhiên, đôi khi điều này có thể không thành công. Ví dụ: API có thể kích hoạt lệnh 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ó bị 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.
Giá trị tối đa cho ttl
và expireTime
là 15 ngày sau khi gửi thông báo.
Mặc dù không có giá trị tối thiểu ttl
và expireTime
, nhưng bạn nên đợi ít nhất 10 giây sau khi gửi thông báo để giảm đáng kể khả năng nhận được thông báo về cả việc thu hồi và gửi.
Đặt loại lưu lượng truy cập thông báo
API RBM có một trường messageTrafficType
để phân loại tin nhắn.
Mặc dù các trường hợp sử dụng nhân viên hỗ trợ vẫn xác định hành vi của nhân viên hỗ trợ và những quy tắc kinh doanh nào được áp dụng, nhưng messageTrafficType
cho phép phân loại nội dung tin nhắn chi tiết hơn. Cuối cùng, điều này sẽ giúp một tác nhân duy nhất xử lý nhiều trường hợp sử dụng. Hiện tại, không có ảnh hưởng nào đến các trường hợp sử dụng tác nhân hiện có hoặc quy tắc kinh doanh.
Đây là trường không bắt buộc, nhưng bạn nên đặt trường này ngay bây giờ để không gặp lỗi khi trường này trở thành trường bắt buộc.
Để đặt loại lưu lượng truy cập thông báo, hãy chỉ định messageTrafficType
thích hợp cho từng thông báo dựa trên nội dung của thông báo đó. RBM hỗ trợ các loại lưu lượng truy cập sau.
Loại lưu lượng truy cập | Nội dung tin nhắn | Trường hợp sử dụng của nhân viên hỗ trợ |
---|---|---|
AUTHENTICATION |
Đối với thư xác thực. | OTP |
TRANSACTION |
Đối với những thông báo về các dịch vụ hoặc sản phẩm hiện có của người dùng. Ví dụ: thông tin xác nhận, biên lai thanh toán hoặc thông tin đặt phòng. | Giao dịch hoặc Đa năng |
PROMOTION |
Đối với tin nhắn quảng bá như ưu đãi, chiết khấu, thông báo hoặc nội dung quảng bá khác. | Khuyến mãi hoặc Đa năng |
SERVICEREQUEST |
Đối với những thông báo về các dịch vụ mà người dùng đã yêu cầu một cách rõ ràng. | OTP, Giao dịch, Khuyến mãi hoặc Nhiều mục đích |
ACKNOWLEDGEMENT |
Đối với những thông báo dùng để xác nhận hành động của người dùng – cụ thể là yêu cầu huỷ đăng ký. Điều này xác nhận rằng yêu cầu của người dùng đã được nhận và đang được xử lý. | OTP, Giao dịch, Khuyến mãi hoặc Nhiều mục đích |
Nếu bạn không đặt loại lưu lượng truy cập, hệ thống sẽ chỉ định loại mặc định cho trường hợp sử dụng của tác nhân.
Trường hợp sử dụng của nhân viên hỗ trợ | Loại lưu lượng truy cập mặc định |
---|---|
OTP | AUTHENTICATION |
Giao dịch | TRANSACTION |
Quảng bá | PROMOTION |
Đa năng | MESSAGE_TRAFFIC_TYPE_UNSPECIFIED |
Các tác nhân đa năng không có loại lưu lượng truy cập mặc định. Bạn phải đặt rõ ràng loại lưu lượng truy cập cho từng thông báo dựa trên nội dung của thông báo đó. Nếu bạn không thay thế giá trị MESSAGE_TRAFFIC_TYPE_UNSPECIFIED
, thì sẽ xảy ra lỗi.
Giới hạn kích thước thư
Kích thước tối đa của toàn bộ AgentMessage được chuyển đổi thành chuỗi là 250 KB. Phần văn bản của thông báo có giới hạn riêng là 3.072 ký tự.
Kích thước tối đa của một tệp có thể gửi qua RBM là 100 MB. Hãy tham khảo phần Tệp đa phương tiện và tệp PDF để biết thêm thông tin.
Văn bản
Những thông báo đơn giản nhất được tạo bằng văn bản. Tin nhắn văn bản phù hợp nhất để truyền đạt thông tin mà không cần hình ảnh, tương tác phức tạp hoặc phản hồi.
Ví dụ:
Đoạn mã sau đây gửi một tin nhắn văn bản thuần tuý. Để biết các lựa 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!" }, "messageTrafficType": "PROMOTION" }'
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); let params = { messageText: 'Hello, world!', msisdn: '+12223334444', }; // Send a simple message to the device rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Send simple text message to user rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444" ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a simple RBM text message message_text = messages.TextMessage('Hello, world!') # Send text message to the device messages.MessageCluster().append_message(message_text).send_to_msisdn('+12223334444')
C#
using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", );
Nội dung của Thông báo cơ bản – chuyển đổi từ SMS
Các nhà mạng đã giới thiệu mô hình thanh toán để hỗ trợ việc chuyển tin nhắn SMS sang RBM. Thông báo RBM chứa tối đa 160 ký tự UTF-8 được gọi là Thông báo cơ bản.
Khi tạo yêu cầu gửi Tin nhắn 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 một tin nhắn có chứa các ký tự đặc biệt 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 đến 4 ký tự UTF-8 trở lên.
Nhập nội dung văn bản vào hộp để kiểm tra độ dài:
Nội dung tin nhắn cơ bản và bản xem trước của đường liên kết
Các ứng dụng RCS có thể triển khai tính năng xem trước đường liên kết. Nếu một tin nhắn RBM chỉ có văn bản bao gồm URL của một trang web có thẻ openGraph, thì một hình ảnh xem trước có thể xuất hiện, tạo ấn tượng về nội dung phong phú hơn.
Xin lưu ý rằng ứng dụng RCS có thể cho phép người dùng tắt tính năng xem trước đường liên kết.
Mật khẩu một lần để xác minh người dùng
Bạn có thể dùng RBM để gửi mật khẩu dùng một lần (OTP) để tự động xác minh người dùng bằng SMS Retriever API. Không có API chuyên dụng để đọc OTP nhận được qua RBM.
Cách hoạt động trên Android
Đối với những ứng dụng Android đã đăng ký bằng SMS Retriever API, API này sẽ chờ một thông báo RBM có định dạng chính xác. Thông báo này phải chứa cả OTP và một hàm băm duy nhất để xác định ứng dụng của bạn.
Khi nhận được một tin nhắn RBM có định dạng chính xác, SMS Retriever API sẽ xử lý tin nhắn đó giống như cách xử lý OTP qua SMS. Sau khi mã băm khớp với ứng dụng của bạn, OTP sẽ được trích xuất và chuyển tiếp đến ứng dụng của bạn để tự động xác minh người dùng.
- Tin nhắn văn bản mẫu trên RBM để xác minh người dùng:
Your code is <OTP> <app hash>.
- Ví dụ:
Your code is 123456 M8tue43FGT.
Để tìm hiểu thêm về SMS Retriever và các API liên quan, hãy xem tài liệu về SMS Retriever. Để biết thông tin chi tiết về quy trình xác minh người dùng tự động trong các ứng dụng đã đăng ký bằng SMS Retriever API, hãy xem sơ đồ quy trình này.
Cách hoạt động trên iOS
Đối với iOS, tính năng xử lý OTP tích hợp sẵn của hệ thống sẽ tự động phát hiện và đề xuất OTP RBM để tự động điền, giống như OTP SMS. Ứng dụng iOS không cần tích hợp API cụ thể để đọc OTP.
Tệp nội dung nghe nhìn và tệp PDF
Khi gửi tin nhắn có tệp hình ảnh, video, âm thanh hoặc PDF, nhân viên hỗ trợ của bạn phải cung cấp một URL có thể truy cập công khai cho nội dung đó hoặc tải trực tiếp tệp lên. Đối với các tệp đa phương tiện, bạn cũng có thể chỉ định một hình thu nhỏ để người dùng xem trước nội dung trước khi nhấp vào. Đối với tệp âm thanh, tiện ích âm thanh mặc định sẽ được dùng làm phần giữ chỗ.
Nền tảng RBM lưu các tệp vào bộ nhớ đệm trong 60 ngày và API này trả về một mã nhận dạng tệp mà nhân viên hỗ trợ có thể đưa vào tin nhắn gửi cho người dùng. Sau 60 ngày, RBM sẽ xoá các tệp khỏi bộ nhớ đệm.
Khi chỉ định tệp theo URL, bạn nên đặt contentMessage.forceRefresh
thành false
. Việc đặt contentMessage.forceRefresh
thành true
buộc RBM tìm nạp nội dung mới từ URL đã chỉ định, ngay cả khi nội dung URL được lưu vào bộ nhớ đệm. Điều này làm tăng thời gian phân phối tin nhắn cho người dùng.
Xem các phương pháp hay nhất để biết các đề xuất và giới hạn về kích thước tệp.
Ví dụ về URL của tệp
Đoạn mã sau đây sẽ gửi một hình ảnh. Để biết các lựa chọn về đị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); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.AgentContentMessage; import com.google.api.services.rcsbusinessmessaging.v1.model.AgentMessage; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); String fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // create media only message AgentContentMessage agentContentMessage = new AgentContentMessage(); agentContentMessage.setContentInfo(new ContentInfo().setFileUrl(fileUrl)); // attach content to message AgentMessage agentMessage = new AgentMessage(); agentMessage.setContentMessage(agentContentMessage); rbmApiHelper.sendAgentMessage(agentMessage, "+12223334444"); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create media file attachment file_message = messages.FileMessage('http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif') messages.MessageCluster().append_message(file_message).send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); string fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // Create content info with the file url ContentInfo contentInfo = new ContentInfo { FileUrl = fileUrl }; // Attach content info to a message AgentContentMessage agentContentMessage = new AgentContentMessage { ContentInfo = contentInfo, }; // Attach content to message AgentMessage agentMessage = new AgentMessage { ContentMessage = agentContentMessage }; rbmApiHelper.SendAgentMessage(agentMessage, "+12223334444");
Ngoài ra, bạn có thể tải tệp nghe nhìn lên trước khi gửi trong tin nhắn bằng cách nhấn vào biểu tượng files.create
.
Ví dụ về việc tải tệp lên
Đoạ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 này trong một thông báo. Để biết các lựa chọn về định dạng và giá trị, hãy xem files.create
và AgentContentMessage
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/upload/v1/files?agentId=AGENT_ID" \ -H "Content-Type: video/mp4" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ --upload-file "FULL_PATH_TO_VIDEO_MEDIA_FILE"
# Capture server-specified video file name from response body JSON
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/upload/v1/files?agentId=AGENT_ID" \ -H "Content-Type: image/jpeg" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ --upload-file "FULL_PATH_TO_THUMBNAIL_MEDIA_FILE"
# Capture server-specified image file name from response body JSON
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d '{ "contentMessage": { "uploadedRbmFile": { "fileName": "SERVER-SPECIFIED_VIDEO_FILE_NAME", "thumbnailName": "SERVER-SPECIFIED_THUMBNAIL_FILE_NAME" } } }'
Các loại nội dung nghe nhìn được hỗ trợ
RBM hỗ trợ các loại nội dung đa phương tiện sau. Đối với hình thu nhỏ, chỉ hỗ trợ image/jpeg, image/jpg, image/gif và image/png.
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 |
---|---|---|---|
application/ogg | Âm thanh OGG | .ogx | Không |
application/pdf | Không | ||
audio/aac | Âm thanh AAC | .aac | Không |
audio/mp3 | Âm thanh MP3 | .mp3 | Không |
audio/mpeg | Âm thanh MPEG | .mpeg | Không |
audio/mpg | Âm thanh MPG | .mp3 | Không |
audio/mp4 | Âm thanh MP4 | .mp4 | Không |
audio/mp4-latm | Âm thanh MP4-latm | .mp4 | Không |
audio/3gpp | Âm thanh 3GPP | .3gp | Không |
image/jpeg | JPEG | .jpeg, .jpg | Có |
hình ảnh/gif | GIF | .gif | Có |
hình ảnh/png | PNG | .png | Có |
video/h263 | Video H263 | .h263 | Có |
video/m4v | Video M4V | .m4v | Có |
video/mp4 | Video MP4 | .mp4 | Có |
video/mpeg4 | Video MPEG-4 | .mp4, .m4p | Có |
video/mpeg | Video MPEG | .mpeg | Có |
video/webm | Video WEBM | .webm | Có |
Nội dung đề xuất
Trợ lý của bạn sẽ gửi các đề xuất (câu trả lời đề xuất và hành động đề xuất) trong danh sách đề xuất dạng chip (tối đa 11 đề xuất) hoặc trong thẻ đa dạng (tối đa 4 đề xuất).
Mỗi đề xuất có tối đa 25 ký tự.
Câu trả lời đề xuất
Câu trả lời đề xuất hướng dẫn người dùng trong các cuộc trò chuyện bằng cách cung cấp những câu trả lời mà nhân viên hỗ trợ của bạn biết cách phản hồi.
Khi người dùng nhấn vào một câu trả lời được đề xuất, nhân viên hỗ trợ của bạn sẽ nhận được một sự kiện chứa văn bản và dữ liệu gửi lại của câu trả lời đó. Tải trọng có tối đa 2048 ký tự.
Ví dụ:
Đoạn mã sau đây gửi văn bản có 2 câu trả lời đề xuất. Để biết các lựa chọn về đị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); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; import com.google.rbm.SuggestionHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); suggestions.add( new SuggestionHelper("Suggestion #1", "suggestion_1").getSuggestedReply()); suggestions.add( new SuggestionHelper("Suggestion #2", "suggestion_2").getSuggestedReply()); // Send simple text message to user rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggested replies for the message to send to the user cluster.append_suggestion_chip(messages.SuggestedReply('Suggestion #1', 'reply:suggestion_1')) cluster.append_suggestion_chip(messages.SuggestedReply('Suggestion #2', 'reply:suggestion_2')) # Send a simple message with suggestion chips to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); List<Suggestion> suggestions = new List<Suggestion> { // Create suggestion chips new SuggestionHelper("Suggestion #1", "suggestion_1").SuggestedReply(), new SuggestionHelper("Suggestion #2", "suggestion_2").SuggestedReply() }; // Send simple text message with suggestions to user rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
Hành động đề xuất
Các hành động đề xuất hướng dẫn người dùng trong các cuộc trò chuyện bằng cách tận dụng chức năng tích hợp của thiết bị. Trợ lý 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ở một URL hoặc tạo một sự kiện trên lịch.
Đối với mỗi thao tác được đề xuất, bạn có thể cung cấp một URL dự phòng (tối đa 2048 ký tự). URL này sẽ mở trong một cửa sổ trình duyệt mới nếu thiết bị của người dùng không hỗ trợ thao tác được đề xuất.
Khi người dùng nhấn vào một hành động được đề xuất, tác nhân của bạn sẽ nhận được một sự kiện chứa dữ liệu gửi lại của hành động đó.
Để biết các lựa chọn về định dạng và giá trị, hãy xem SuggestedAction
.
Quay số
Hành động Quay số hướng dẫn người dùng quay số điện thoại do trợ lý ảo của bạn chỉ định.
Số điện thoại chỉ có thể chứa chữ số (0-9
), dấu cộng (+
), dấu hoa thị (*
) và dấu thăng (#
). Định dạng quốc tế E.164 (ví dụ: +14155555555
) được hỗ trợ nhưng không bắt buộc. Tức là cả +14155555555
và 1011
đều là các mục hợp lệ.
Ví dụ:
Đoạn mã sau đây gửi một thao tác quay số. Để biết các lựa chọn về đị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); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.DialAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a dial suggested action DialAction dialAction = new DialAction(); dialAction.setPhoneNumber("+15556667777"); // creating a suggested action based on a dial action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Call"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setDialAction(dialAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a dial suggested action suggestions = [ messages.DialAction('Call', 'reply:postback_data_1234', '+15556667777') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a dial an agent suggested action DialAction dialAction = new DialAction { PhoneNumber = "+15556667777" }; // Creating a suggested action based on a dial action SuggestedAction suggestedAction = new SuggestedAction { Text = "Call", PostbackData = "postback_data_1234", DialAction = dialAction }; // Attach action to a suggestion Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
Xem một vị trí
Thao tác Xem vị trí sẽ 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 một 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 xuất hiện trong ứng dụng bản đồ.
Ví dụ:
Đoạn mã sau đây sẽ gửi một thao tác xem vị trí. Để biết các lựa 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); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.ViewLocationAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a view location suggested action ViewLocationAction viewLocationAction = new ViewLocationAction(); viewLocationAction.setQuery("Googleplex, Mountain View, CA"); // creating a suggested action based on a view location action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("View map"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setViewLocationAction(viewLocationAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a view location suggested action suggestions = [ messages.ViewLocationAction('View map', 'reply:postback_data_1234', query='Googleplex, Mountain View, CA') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // create an view location action ViewLocationAction viewLocationAction = new ViewLocationAction { Query = "Googleplex Mountain View, CA" }; // Attach the view location action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { ViewLocationAction = viewLocationAction, Text = "View map", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
Chia sẻ vị trí
Thao tác Chia sẻ vị trí cho phép người dùng chia sẻ vị trí với nhân viên hỗ trợ của bạn. Người dùng có thể chia sẻ vị trí hiện tại hoặc vị trí mà họ chọn theo cách thủ công trong ứng dụng Maps.
Ví dụ:
Đoạn mã sau đây sẽ gửi một thao tác chia sẻ vị trí. Để biết các lựa 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); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.ShareLocationAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a share location suggested action ShareLocationAction shareLocationAction = new ShareLocationAction(); // creating a suggested action based on a share location action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Share location"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setShareLocationAction(shareLocationAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a share location suggested action suggestions = [ messages.ShareLocationAction('Share location', 'reply:postback_data_1234') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a share location action ShareLocationAction shareLocationAction = new ShareLocationAction(); // Attach the share location action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { ShareLocationAction = shareLocationAction, Text = "Share location", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
Mở một URL
Thao tác Mở URL cho phép bạn hướng dẫn người dùng đến một trang web do tác nhân của bạn chỉ định. Theo mặc định, trang web sẽ mở trong trình duyệt của người dùng. Nếu người dùng đã định cấu hình một ứng dụng mặc định cho trang web, thì ứng dụng đó sẽ mở ra. Trong trường hợp đó, biểu tượng trên nút hành động đề xuất sẽ là biểu tượng của ứng dụng.
Thao tác Mở URL cũng hỗ trợ webview tích hợp; hãy xem phần Mở URL bằng webview.
Ví dụ:
Đoạn mã sau đây gửi một thao tác mở URL. Để biết các lựa chọn về đị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); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.OpenUrlAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating an open url suggested action OpenUrlAction openUrlAction = new OpenUrlAction(); openUrlAction.setUrl("https://www.google.com"); // creating a suggested action based on an open url action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Open Google"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setOpenUrlAction(openUrlAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create an open url suggested action suggestions = [ messages.OpenUrlAction('Open Google', 'reply:postback_data_1234', 'https://www.google.com') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create an open url action OpenUrlAction openUrlAction = new OpenUrlAction { Url = "https://www.google.com" }; // Attach the open url action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { OpenUrlAction = openUrlAction, Text = "Open Google", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
Mở một URL bằng webview
Thao tác Mở URL bằng webview sẽ tải trang web đã chỉ định vào bên trong ứng dụng nhắn tin bằng công cụ kết xuất của trình duyệt mặc định. Điều này cho phép người dùng tương tác với trang web mà không cần rời khỏi cuộc trò chuyện trên RBM. Nếu thiết bị của người dùng không hỗ trợ webview, thì trang web sẽ mở trong trình duyệt của người dùng. Để bật chế độ xem web, hãy xem phần OpenURLApplication
.
Webview có 3 chế độ hiển thị. Để biết các lựa chọn về định dạng và giá trị, hãy xem WebviewViewMode
.
- Đầy đủ: Trang web chiếm toàn bộ màn hình
- Nửa màn hình: Trang web chiếm một nửa màn hình
- Dọc: Trang web chiếm 3/4 màn hình
Ví dụ:
Đoạn mã sau đây gửi một thao tác Mở URL bằng webview. Để biết các lựa chọn về đị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", "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; }
Tạo sự kiện trê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 một sự kiện mới có thông tin được chỉ định.
Bạn phải nhập tiêu đề sự kiện trên lịch. Thuộc tính này có tối đa 100 ký tự. Bạn không bắt buộc phải nhập nội dung mô tả sự kiện trên lịch và nội dung này có tối đa 500 ký tự.
Ví dụ:
Đoạn mã sau đây sẽ gửi một thao tác tạo sự kiện trên lịch. Để biết các lựa chọn về đị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); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.CreateCalendarEventAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a create calendar event suggested action CreateCalendarEventAction createCalendarEventAction = new CreateCalendarEventAction(); calendarEventAction.setTitle("My calendar event"); calendarEventAction.setDescription("Description of the calendar event"); calendarEventAction.setStartTime("2020-06-30T19:00:00Z"); calendarEventAction.setEndTime("2020-06-30T20:00:00Z"); // creating a suggested action based on a create calendar event action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Save to calendar"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setCreateCalendarEventAction(createCalendarEventAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a calendar event suggested action suggestions = [ messages.CreateCalendarEventAction('Save to Calendar', 'reply:postback_data_1234', '2020-06-30T19:00:00Z', '2020-06-30T20:00:00Z', 'My calendar event', 'Description of the calendar event') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a calendar event action CreateCalendarEventAction calendarEventAction = new CreateCalendarEventAction { Title = "My calendar event", Description = "Description of the calendar event", StartTime = "2020-06-30T19:00:00Z", EndTime = "2020-06-30T20:00:00Z" }; // Attach the calendar event action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { CreateCalendarEventAction = calendarEventAction, Text = "Save to calendar", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
Danh sách khối đề xuất
Nhân viên hỗ trợ của bạn gửi danh sách các đề xuất dạng chip kèm theo tin nhắn để 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ỉ xuất hiện khi thông báo 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 (từ người dùng hoặc nhân viên hỗ trợ của bạn) sẽ ghi đè danh sách các đề xuất.
Các khối trong danh sách là câu trả lời đề xuất và hành động đề 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ể chứa tối đa 25 ký tự.
Để biết các lựa chọn về định dạng và giá trị, hãy xem AgentContentMessage
.
Thẻ thông tin
Khi cần gửi một khối thông tin, nội dung nghe nhìn hoặc đề xuất có liên quan, bạn nên gửi một thẻ thông tin chi tiết. Thẻ rich cho phép tác nhân của bạn gửi nhiều đơn vị thông tin trong một thông báo.
Thẻ thông tin có thể chứa những mục sau:
- Hình ảnh hoặc video
- Văn bản tiêu đề
- Văn bản mô tả
- Câu trả lời và hành động đề xuất (tối đa 4)
Thẻ thông tin phong phú có thể chứa tất cả các mục được liệt kê, nhưng thẻ thông tin phải chứa ít nhất một hình ảnh, video hoặc tiêu đề thì mới hợp lệ. Một thẻ nhiều định dạng có thể chứa tối đa 4 hành động đề xuất và câu trả lời đề xuất.
Agent của bạn có thể gửi nhiều thẻ thông tin chi tiết cùng lúc trong một băng chuyền thẻ thông tin chi tiết.
Kích thước tối đa của tải trọng thẻ đa dạng là 250 KB. Hãy xem các phương pháp hay nhất để biết các đề xuất và giới hạn về kích thước tệp nội dung nghe nhìn.
Bạn có thể xem thông số kỹ thuật của thẻ thông tin chi tiết trong phần Thẻ thông tin chi tiết.
Chiều cao thẻ
Thẻ mở rộng theo chiều dọc để phù hợp với nội dung. Thẻ đa dạng 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 tối thiểu của thẻ, thì thẻ sẽ mở rộng và lấp đầy chiều cao bổ sung bằng khoảng trắng.
Nội dung nghe nhìn trong thẻ đa phương tiện phải có một trong ba chiều cao sau:
- 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ẻ theo 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 phóng to và cắt nội dung nghe nhìn.
Ví dụ:
Mã sau đây gửi một thẻ thông tin chi tiết có hình ảnh và câu trả lời đề xuất. Để biết các lựa chọn về đị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); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.StandaloneCard; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.cards.CardOrientation; import com.google.rbm.cards.MediaHeight; import com.google.rbm.RbmApiHelper; import com.google.rbm.SuggestionHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); suggestions.add( new SuggestionHelper("Suggestion #1", "suggestion_1").getSuggestedReply()); suggestions.add( new SuggestionHelper("Suggestion #2", "suggestion_2").getSuggestedReply()); String imageUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // Create a standalone rich card to send to the user StandaloneCard standaloneCard = rbmApiHelper.createStandaloneCard( "Hello, world!", "RBM is awesome!", imageUrl, MediaHeight.MEDIUM, CardOrientation.VERTICAL, suggestions ); rbmApiHelper.sendStandaloneCard(standaloneCard, "+12223334444"); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Suggested replies to be used in the card suggestions = [ messages.SuggestedReply('Suggestion #1', 'reply:suggestion_1'), messages.SuggestedReply('Suggestion #2', 'reply:suggestion_2') ] # Image to be displayed by the card image_url = 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif'; # Define rich card structure rich_card = messages.StandaloneCard('VERTICAL', 'Hello, world!', 'RBM is awesome!', suggestions, image_url, None, None, 'MEDIUM') # Append rich card and send to the user cluster = messages.MessageCluster().append_message(rich_card) cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; using RCSBusinessMessaging.Cards; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); List<Suggestion> suggestions = new List<Suggestion> { // Create suggestion chips new SuggestionHelper("Suggestion #1", "suggestion_1").SuggestedReply(), new SuggestionHelper("Suggestion #2", "suggestion_2").SuggestedReply() }; string imageUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // Create rich card with suggestions StandaloneCard standaloneCard = rbmApiHelper.CreateStandaloneCard( "Hello, world!", "RBM is awesome", imageUrl, MediaHeight.TALL, CardOrientation.VERTICAL, suggestions ); // Send rich card to user rbmApiHelper.SendStandaloneCard(standaloneCard, "+12223334444");
Băng chuyền thẻ thông tin chi tiết
Khi bạn cần cung cấp cho người dùng nhiều lựa chọn để chọn, hãy sử dụng băng chuyền thẻ thông tin chi tiết. Băng chuyền kết hợp nhiều thẻ đa dạng, cho phép người dùng so sánh các mục và phản ứng với từng mục riêng lẻ.
Băng chuyền có thể chứa tối thiểu 2 và tối đa 10 thẻ đa dạng. Thẻ nhiều định dạng trong băng chuyền phải tuân thủ các yêu cầu chung về thẻ nhiều định dạng đối với nội dung và chiều cao. Bạn có thể xem các quy cách về băng chuyền trong phần Thẻ đa dạng.
Kích thước tối đa của tải trọng băng chuyền thẻ đa dạng là 250 KB. Hãy xem các phương pháp hay nhất để biết các đề xuất và giới hạn về kích thước tệp nội dung nghe nhìn.
Cắt bớt
Tương tự như thẻ thông tin, nhiều yếu tố (chẳng hạn như độ phân giải màn hình, mật độ điểm ảnh và lựa chọn ưu tiên của người dùng) ảnh hưởng đến cách thẻ xuất hiện với người dùng cuối. Tuy nhiên, trong băng chuyền, chiều cao của một vài thẻ đầu tiên sẽ xác định chiều cao của tất cả các thẻ trong băng chuyền, đồng thời chiều cao của thẻ ảnh hưởng đến việc cắt bớt tiêu đề, nội dung mô tả và đề xuất.
Nếu một 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 thẻ, thì RBM sẽ cắt ngắn thẻ cho đến khi thẻ có thể hiển thị trên thiết bị, bằng cách sử dụng logic sau:
- Giảm phần mô tả xuống còn một dòng.
- Giảm tiêu đề xuống còn một dòng.
- Bỏ qua những đề xuất không phù hợp với thẻ, bắt đầu từ cuối danh sách đã xác định.
- Bỏ qua nội dung mô tả.
- Bỏ qua tiêu đề.
Để tránh bị cắt bớt, hãy giữ tiêu đề và nội dung mô tả ngắn gọn nhất có thể. Đối với nội dung đa phương tiện dọc, 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 vừa, hãy sử dụng tối đa 2 đề xuất. Đối với nội dung nghe nhìn ngắn, hãy sử dụng tối đa 3 đề xuất. Để vừa 4 đề xuất, đừng thêm nội dung nghe nhìn vào thẻ.
Giữ cho các thẻ có kích thước và độ dài nội dung tương đương nhau. Nếu cần, hãy đặt các thẻ lớn hơn lên đầu băng chuyền để tránh bị cắt bớt nội dung trong các thẻ tiếp theo.
Ví dụ:
Đoạn mã sau đây sẽ gửi một băng chuyền thẻ thông tin chi tiết. Để biết các lựa chọn về đị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); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.CardContent; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.cards.CardOrientation; import com.google.rbm.cards.CardWidth; import com.google.rbm.cards.MediaHeight; import com.google.rbm.RbmApiHelper; import com.google.rbm.SuggestionHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); List cardContents = new ArrayList(); // Images for the carousel cards String card1Image = "https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg"; // Create suggestions for first carousel card List card1Suggestions = new ArrayList(); card1Suggestions.add( new SuggestionHelper("Card #1", "card_1")); cardContents.add( new StandaloneCardHelper( "Card #1", "The description for card #1", card1Image, card1Suggestions) .getCardContent(MediaHeight.SHORT) ); // Images for the carousel cards String card2Image = "https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg"; // Create suggestions for second carousel card List card2Suggestions = new ArrayList(); card2Suggestions.add( new SuggestionHelper("Card #2", "card_2")); cardContents.add( new StandaloneCardHelper( "Card #2", "The description for card #2", card2Image, card2Suggestions) .getCardContent(MediaHeight.SHORT) ); // Send the carousel to the user rbmApiHelper.sendCarouselCards(cardContents, CardWidth.MEDIUM, "+12223334444"); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Images for the carousel cards card_image_1 = 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg'; card_image_2 = 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg'; # Suggested replies to be used in the cards suggestions1 = [ messages.SuggestedReply('Card #1', 'reply:card_1') ] suggestions2 = [ messages.SuggestedReply('Card #2', 'reply:card_2') ] # Define the card contents for a carousel with two cards, # each with one suggested reply card_contents = [] card_contents.append(messages.CardContent('Card #1', 'The description for card #1', card_image_1, 'MEDIUM', suggestions1)) card_contents.append(messages.CardContent('Card #2', 'The description for card #2', card_image_2, 'MEDIUM', suggestions2)) # Send the device the carousel card defined above carousel_card = messages.CarouselCard('MEDIUM', card_contents) cluster = messages.MessageCluster().append_message(carousel_card) cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; using RCSBusinessMessaging.Cards; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Image references to be used in the carousel cards string card1Image = "https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg"; string card2Image = "https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg"; // Suggestion chip lists to be used in carousel cards List<Suggestion> suggestions1 = new List<Suggestion> { new SuggestionHelper("Card #1", "card_1").SuggestedReply() }; List<Suggestion> suggestions2 = new List<Suggestion> { new SuggestionHelper("Card #2", "card_2").SuggestedReply() }; // Create the card content for the carousel List<CardContent> cardContents = new List<CardContent> { // Add items as card content new StandaloneCardHelper( "Card #1", "The description for card #1", card1Image, suggestions1).GetCardContent(), new StandaloneCardHelper( "Card #2", "The description for card #2", card2Image, suggestions2).GetCardContent() }; // Send the carousel to the user rbmApiHelper.SendCarouselCards(cardContents, CardWidth.MEDIUM, msisdn);