ตัวแทน RBM จะสื่อสารกับผู้ใช้ได้โดยการส่งและรับข้อความ หากต้องการส่งข้อความถึงผู้ใช้ ตัวแทนจะส่งคำขอข้อความไปยัง RCS Business Messaging API คำขอเดียวสามารถมีข้อความ การ์ดสื่อสมบูรณ์ รูปภาพ หรือวิดีโอ รวมถึงการตอบกลับที่แนะนำและการดำเนินการที่แนะนำ
หากคุณส่งข้อความถึงผู้ใช้ที่อุปกรณ์ไม่รองรับ RCS หรือไม่ได้เปิดใช้ RCS แพลตฟอร์ม RBM จะแสดงข้อผิดพลาด 404 ในกรณีนี้ คุณสามารถลองเข้าถึงผู้ใช้ผ่านวิธีสำรองที่กำหนดไว้ในโครงสร้างพื้นฐาน
หากคุณส่งข้อความถึงผู้ใช้ RCS ในเครือข่ายที่ Agent ยังไม่เปิดใช้ หรือในเครือข่ายที่ไม่ได้เปิดใช้การรับส่งข้อมูล RCS แพลตฟอร์ม RBM จะแสดงข้อผิดพลาด 403
หากคุณส่งข้อความด้วยฟีเจอร์ที่อุปกรณ์ของผู้ใช้ไม่รองรับ แพลตฟอร์ม RBM จะแสดงข้อผิดพลาดและไม่ส่งข้อความของคุณ
ขนาดสูงสุดของสตริงทั้งหมด AgentMessage คือ 250 KB
กำลังส่งไปยังผู้ใช้แบบออฟไลน์
แพลตฟอร์ม RBM จะยังคงยอมรับข้อความสำหรับการนำส่งหากผู้รับออฟไลน์อยู่ คุณได้รับการตอบกลับ 200 OK และแพลตฟอร์ม RBM จะระงับข้อความไว้และพยายามส่งใหม่เป็นเวลา 30 วัน ไม่จำเป็นต้องขอให้ RBM ส่งข้อความอีกครั้ง
RBM จะลบข้อความที่ยังไม่ได้ส่งหลังจากส่งครบ 30 วัน
คุณอาจต้องเพิกถอนข้อความที่ยังไม่ได้ส่งก่อนหมดเวลา 30 วันนี้ ทั้งนี้ขึ้นอยู่กับกรณีการใช้งานของตัวแทน การเพิกถอนจะป้องกันไม่ให้ผู้ใช้แบบออฟไลน์ได้รับข้อความที่ล้าสมัยเมื่อกลับมาออนไลน์อีกครั้ง วิธีเพิกถอนข้อความมีหลายวิธีดังนี้
- ส่งคำขอเพิกถอนเพื่อทริกเกอร์การเพิกถอน
- ตั้งค่าการหมดอายุของข้อความเพื่อเพิกถอนข้อความโดยอัตโนมัติในเวลาที่เหมาะสม
ตั้งการหมดอายุของข้อความ
เวลาส่งข้อความของตัวแทนมีความสำคัญหรือไม่ เช่น OTP จะใช้ได้เป็นระยะเวลาสั้นๆ เท่านั้น ข้อเสนอที่มีเวลาจำกัดจะหมดอายุ และการช่วยเตือนการนัดหมาย จะไม่มีผลหลังวันที่นัดหมาย โปรดตั้งเวลาหมดอายุของข้อความเพื่อให้ข้อความมีความเกี่ยวข้องและทันท่วงที ซึ่งอาจทำให้ผู้ใช้แบบออฟไลน์ไม่ได้รับเนื้อหาที่ไม่มีอัปเดตเมื่อกลับมาออนไลน์อีกครั้ง การหมดอายุยังเป็นวิธีที่ดีในการเรียกใช้กลยุทธ์การส่งข้อความสำรองเพื่อให้ผู้ใช้ได้รับข้อมูลที่ต้องการตรงเวลา
หากต้องการตั้งค่าการหมดอายุของข้อความ ให้ระบุช่องใดช่องหนึ่งต่อไปนี้ในข้อความของ Agent
expireTime
: เวลาที่แน่นอนในเขตเวลา UTC เมื่อข้อความหมดอายุttl
(Time to Live): ระยะเวลาก่อนที่ข้อความจะหมดอายุ
โปรดดูตัวเลือกการจัดรูปแบบและค่าที่หัวข้อ AgentMessage
เมื่อข้อความหมดอายุ แพลตฟอร์ม RBM จะหยุดพยายามส่งข้อความและระบบจะเพิกถอนข้อความโดยอัตโนมัติ แต่ก็อาจเกิดความล้มเหลว ในบางครั้งบ้าง เช่น API อาจทริกเกอร์การเพิกถอนขณะที่แพลตฟอร์ม RBM อยู่ในกระบวนการส่งข้อความ เพื่อยืนยันว่าข้อความที่หมดอายุเพิกถอนเรียบร้อยแล้ว RBM จะส่งเหตุการณ์การแจ้งเตือนไปยังเว็บฮุคของคุณ
ข้อความ
ข้อความที่ง่ายที่สุดประกอบด้วยข้อความ SMS เหมาะที่สุดในการสื่อสารข้อมูลโดยไม่ต้องใช้ภาพ การโต้ตอบที่ซับซ้อน หรือการโต้ตอบ
ตัวอย่าง
รหัสต่อไปนี้จะส่งข้อความธรรมดา ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ phones.agentMessages.create
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!' } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); let params = { messageText: 'Hello, world!', msisdn: '+12223334444', }; // Send a simple message to the device rbmApiHelper.sendMessage(params, function(response) { console.log(response); });โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Java
import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Send simple text message to user rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444" ); } catch(Exception e) { e.printStackTrace(); }โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a simple RBM text message message_text = messages.TextMessage('Hello, world!') # Send text message to the device messages.MessageCluster().append_message(message_text).send_to_msisdn('+12223334444')โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
C#
using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", );โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
เนื้อหาข้อความพื้นฐาน - การแปลง SMS
ผู้ให้บริการได้เปิดตัวรูปแบบการเรียกเก็บเงินเพื่อรองรับการย้ายข้อความ SMS ไปยัง RBM ข้อความ RBM ที่มีอักขระ UTF-8 ไม่เกิน 160 ตัวเรียกว่าข้อความพื้นฐาน
เมื่อสร้างคำขอเพื่อส่งข้อความพื้นฐาน โปรดทราบว่าอักขระจะนับเป็น 1 ไบต์ (UTF-8) หากคุณส่งข้อความที่มีสัญลักษณ์พิเศษ เช่น อีโมจิหรือชุดอักขระหลายไบต์ ระบบจะนับแต่ละอักขระเป็นอักขระ UTF-8 2 ตัว
ป้อนข้อความในช่องเพื่อตรวจสอบความยาว:
รหัสผ่านที่สามารถใช้งานได้เพียงครั้งเดียวสำหรับการยืนยันผู้ใช้
คุณสามารถใช้ RBM เพื่อส่งรหัสผ่านที่สามารถใช้งานได้เพียงครั้งเดียว (OTP) สำหรับการยืนยันผู้ใช้โดยอัตโนมัติด้วย SMS Retriever API หากต้องการเรียนรู้เพิ่มเติมเกี่ยวกับ SMS Retriever และ API ที่เกี่ยวข้อง โปรดดูเอกสารประกอบของ SMS Retriever โปรดดูรายละเอียดเกี่ยวกับการยืนยันผู้ใช้อัตโนมัติในแอปที่ได้ลงทะเบียนกับ SMS Retriever API ที่แผนภาพนี้
ระหว่างกระบวนการยืนยัน SMS Retriever API จะคอยตรวจจับข้อความ RBM ข้อความนี้ต้องมี OTP และแฮชที่ระบุแอป หลังจากจับคู่แฮชกับแอปแล้ว ระบบจะดึงข้อมูล OTP และส่งต่อไปยังแอปเพื่อยืนยันผู้ใช้โดยอัตโนมัติ
นี่คือตัวอย่างข้อความ RBM สำหรับการยืนยันผู้ใช้: รหัสของคุณคือ <OTP> <แฮชแอป>
ตัวอย่างเช่น Your code is 123456 M8tue43FGT.
ไฟล์สื่อและไฟล์ PDF
เมื่อคุณส่งข้อความด้วยรูปภาพ วิดีโอ หรือไฟล์ PDF ตัวแทนต้องระบุ URL ที่เข้าถึงได้แบบสาธารณะสำหรับเนื้อหาหรืออัปโหลดไฟล์โดยตรง สำหรับไฟล์สื่อ คุณยังสามารถระบุภาพขนาดย่อที่ช่วยให้ผู้ใช้ดูตัวอย่างเนื้อหาก่อนที่จะคลิกได้ด้วย
แพลตฟอร์ม RBM จะแคชไฟล์ไว้ 60 วัน และ API จะแสดงผลรหัสไฟล์ที่ Agent ของคุณใส่ไว้ในข้อความถึงผู้ใช้ได้ หลังจาก 60 วัน RBM จะนำไฟล์ออกจากแคช
ดูแนวทางปฏิบัติแนะนำสำหรับคำแนะนำเกี่ยวกับขนาดไฟล์และข้อจำกัด
ตัวอย่าง URL ของไฟล์
โค้ดต่อไปนี้จะส่งรูปภาพ ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ AgentContentMessage
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'contentInfo': { 'fileUrl': 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif', 'forceRefresh': 'false' } } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); let params = { fileUrl: 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif', msisdn: '+12223334444', }; // Send an image/video to a device rbmApiHelper.sendMessage(params, function(response) { console.log(response); });โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.AgentContentMessage; import com.google.api.services.rcsbusinessmessaging.v1.model.AgentMessage; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); String fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // create media only message AgentContentMessage agentContentMessage = new AgentContentMessage(); agentContentMessage.setContentInfo(new ContentInfo().setFileUrl(fileUrl)); // attach content to message AgentMessage agentMessage = new AgentMessage(); agentMessage.setContentMessage(agentContentMessage); rbmApiHelper.sendAgentMessage(agentMessage, "+12223334444"); } catch(Exception e) { e.printStackTrace(); }โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create media file attachment file_message = messages.FileMessage('http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif') messages.MessageCluster().append_message(file_message).send_to_msisdn('+12223334444')โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); string fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // Create content info with the file url ContentInfo contentInfo = new ContentInfo { FileUrl = fileUrl }; // Attach content info to a message AgentContentMessage agentContentMessage = new AgentContentMessage { ContentInfo = contentInfo, }; // Attach content to message AgentMessage agentMessage = new AgentMessage { ContentMessage = agentContentMessage }; rbmApiHelper.SendAgentMessage(agentMessage, "+12223334444");โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
หรือคุณจะอัปโหลดสื่อก่อนส่งในข้อความด้วย files.create
ก็ได้เช่นกัน
ตัวอย่างการอัปโหลดไฟล์
โค้ดต่อไปนี้จะอัปโหลดไฟล์วิดีโอและไฟล์ภาพขนาดย่อ จากนั้นจะส่งทั้ง 2 ไฟล์ในข้อความ ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ files.create
และ AgentContentMessage
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/upload/v1/files?agentId=AGENT_ID" \ -H "Content-Type: video/mp4" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ --upload-file "FULL_PATH_TO_VIDEO_MEDIA_FILE"
# Capture server-specified video file name from response body JSON
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/upload/v1/files?agentId=AGENT_ID" \ -H "Content-Type: image/jpeg" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ --upload-file "FULL_PATH_TO_THUMBNAIL_MEDIA_FILE"
# Capture server-specified image file name from response body JSON
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'uploadedRbmFile': { 'fileName': 'SERVER-SPECIFIED_VIDEO_FILE_NAME' 'thumbnailName': 'SERVER-SPECIFIED_THUMBNAIL_FILE_NAME' } } }"
ประเภทสื่อที่รองรับ
RBM รองรับสื่อประเภทต่อไปนี้
ประเภทสื่อ | ประเภทเอกสาร | ส่วนขยาย | ใช้งานได้กับการ์ดริชมีเดีย |
---|---|---|---|
ใบสมัคร/pdf | ไม่ได้ | ||
image/jpeg | JPEG | .jpeg, .jpg | ใช่ |
รูปภาพ/GIF | GIF | .gif | ใช่ |
image/png | PNG | .png | ใช่ |
วิดีโอ/H263 | วิดีโอ H263 | .H263 | ใช่ |
วิดีโอ/m4v | วิดีโอ M4V | .m4v | ใช่ |
วิดีโอ/MP4 | วิดีโอ MP4 | .mp4 | ใช่ |
วิดีโอ/mpeg4 | วิดีโอ MPEG-4 | .mp4, .m4p | ใช่ |
วิดีโอ/mpeg | วิดีโอ MPEG | .mpeg | ใช่ |
วิดีโอ/Webm | วิดีโอ WEBM | .webm | ใช่ |
คำตอบที่แนะนำ
การตอบกลับที่แนะนำจะแนะนำผู้ใช้ตลอดการสนทนาโดยให้คำตอบที่ตัวแทนรู้ว่าจะตอบสนองอย่างไร ตัวแทนจะส่งการตอบกลับที่แนะนำในรายการชิปคำแนะนำหรือในการ์ดริชมีเดีย
เมื่อผู้ใช้แตะการตอบกลับที่แนะนำ ตัวแทนของคุณจะได้รับเหตุการณ์ซึ่งประกอบด้วยข้อความของการตอบกลับและข้อมูลระบบรายงานผล Conversion
การตอบกลับที่แนะนำมีอักขระได้สูงสุด 25 ตัว
ตัวอย่าง
โค้ดต่อไปนี้จะส่งข้อความที่มีการตอบกลับที่แนะนำ 2 รายการ ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ SuggestedReply
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'reply': { 'text': 'Suggestion #1', 'postbackData': 'suggestion_1' } }, { 'reply': { 'text': 'Suggestion #2', 'postbackData': 'suggestion_2' } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); let suggestions = [ { reply: { 'text': 'Suggestion #1', 'postbackData': 'suggestion_1', }, }, { reply: { 'text': 'Suggestion #2', 'postbackData': 'suggestion_2', }, }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with suggestion chips to the device rbmApiHelper.sendMessage(params, function(response) { console.log(response); });โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; import com.google.rbm.SuggestionHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); suggestions.add( new SuggestionHelper("Suggestion #1", "suggestion_1").getSuggestedReply()); suggestions.add( new SuggestionHelper("Suggestion #2", "suggestion_2").getSuggestedReply()); // Send simple text message to user rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggested replies for the message to send to the user cluster.append_suggestion_chip(messages.SuggestedReply('Suggestion #1', 'reply:suggestion_1')) cluster.append_suggestion_chip(messages.SuggestedReply('Suggestion #2', 'reply:suggestion_2')) # Send a simple message with suggestion chips to the device cluster.send_to_msisdn('+12223334444')โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); List<Suggestion> suggestions = new List<Suggestion> { // Create suggestion chips new SuggestionHelper("Suggestion #1", "suggestion_1").SuggestedReply(), new SuggestionHelper("Suggestion #2", "suggestion_2").SuggestedReply() }; // Send simple text message with suggestions to user rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
การดำเนินการที่แนะนำ
การดำเนินการที่แนะนำจะนำทางผู้ใช้ไปสู่การสนทนาโดยทิ้งฟังก์ชันดั้งเดิมของอุปกรณ์เอาไว้ ตัวแทนสามารถแนะนำให้ผู้ใช้กดหมายเลข, เปิดตำแหน่งในแผนที่, แชร์ตำแหน่ง, เปิด URL หรือสร้าง กิจกรรมในปฏิทิน Agent จะส่งการดำเนินการที่แนะนำในรายการชิปคำแนะนำหรือในการ์ดริชมีเดีย
เมื่อผู้ใช้แตะการดำเนินการที่แนะนำ ตัวแทนของคุณจะได้รับเหตุการณ์ที่มีข้อมูลระบบรายงานผล Conversion ของการดำเนินการดังกล่าว
การดำเนินการที่แนะนำมีอักขระได้สูงสุด 25 ตัว
ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ SuggestedAction
กดหมายเลขโทรศัพท์
การโทรจะแนะนําให้ผู้ใช้โทรหาหมายเลขโทรศัพท์ที่ตัวแทนระบุไว้ หมายเลขโทรศัพท์ต้องมี +
นำหน้า รหัสประเทศ และรหัสพื้นที่ แต่ไม่ควรมีตัวคั่น เช่น +14155555555
ตัวอย่าง
รหัสต่อไปนี้จะส่งการดำเนินการแบบโทร ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ DialAction
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'Call', 'postbackData': 'postback_data_1234', 'fallbackUrl': 'https://www.google.com/contact/', 'dialAction': { 'phoneNumber': '+15556667777' } } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a dial suggested action let suggestions = [ { action: { text: 'Call', postbackData: 'postback_data_1234', dialAction: { phoneNumber: '+15556667777' } } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a dial suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.DialAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a dial suggested action DialAction dialAction = new DialAction(); dialAction.setPhoneNumber("+15556667777"); // creating a suggested action based on a dial action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Call"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setDialAction(dialAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a dial suggested action suggestions = [ messages.DialAction('Call', 'reply:postback_data_1234', '+15556667777') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a dial an agent suggested action DialAction dialAction = new DialAction { PhoneNumber = "+15556667777" }; // Creating a suggested action based on a dial action SuggestedAction suggestedAction = new SuggestedAction { Text = "Call", PostbackData = "postback_data_1234", DialAction = dialAction }; // Attach action to a suggestion Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
ดูสถานที่ตั้ง
การทำงาน "ดูตำแหน่ง" จะแสดงตำแหน่งในแอปแผนที่เริ่มต้นของผู้ใช้ คุณสามารถระบุตำแหน่งได้ตามละติจูดและลองจิจูด หรือด้วยข้อความค้นหาที่อิงตามตำแหน่งปัจจุบันของผู้ใช้ คุณยังสามารถกำหนดป้ายกำกับที่กำหนดเอง สำหรับหมุดที่แสดงในแอปแผนที่
ตัวอย่าง
โค้ดต่อไปนี้จะส่งการดำเนินการดูตำแหน่ง ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ ViewLocationAction
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'View map', 'postbackData': 'postback_data_1234', 'fallbackUrl': 'https://www.google.com/maps/@37.4220188,-122.0844786,15z', 'viewLocationAction': { 'latLong': { 'latitude': "37.4220188', 'longitude': "-122.0844786' }, 'label': 'Googleplex' } } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a view location suggested action let suggestions = [ { action: { text: 'View map', postbackData: 'postback_data_1234', viewLocationAction: { latLong: { latitude: 37.4220188, longitude: -122.0844786 }, label: 'Googleplex' } } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a view location suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.ViewLocationAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a view location suggested action ViewLocationAction viewLocationAction = new ViewLocationAction(); viewLocationAction.setQuery("Googleplex, Mountain View, CA"); // creating a suggested action based on a view location action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("View map"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setViewLocationAction(viewLocationAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a view location suggested action suggestions = [ messages.ViewLocationAction('View map', 'reply:postback_data_1234', query='Googleplex, Mountain View, CA') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // create an view location action ViewLocationAction viewLocationAction = new ViewLocationAction { Query = "Googleplex Mountain View, CA" }; // Attach the view location action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { ViewLocationAction = viewLocationAction, Text = "View map", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
แชร์ตำแหน่ง
การแชร์สถานที่ตั้งช่วยให้ผู้ใช้ส่งตำแหน่งไปยังตัวแทนของคุณได้ สถานที่ที่ผู้ใช้ระบุอาจไม่ใช่ตำแหน่งของผู้ใช้เสมอไป
ตัวอย่าง
โค้ดต่อไปนี้จะส่งการดำเนินการแชร์ตำแหน่ง ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ ShareLocationAction
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'Share your location', 'postbackData': 'postback_data_1234', 'shareLocationAction': {} } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a share location suggested action let suggestions = [ { action: { text: 'Share your location', postbackData: 'postback_data_1234', shareLocationAction: { } } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a share location suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.ShareLocationAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a share location suggested action ShareLocationAction shareLocationAction = new ShareLocationAction(); // creating a suggested action based on a share location action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Share location"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setShareLocationAction(shareLocationAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a share location suggested action suggestions = [ messages.ShareLocationAction('Share location', 'reply:postback_data_1234') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a share location action ShareLocationAction shareLocationAction = new ShareLocationAction(); // Attach the share location action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { ShareLocationAction = shareLocationAction, Text = "Share location", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
เปิด URL
การดำเนินการ "เปิด URL" จะเปิดเว็บเบราว์เซอร์ของผู้ใช้ไปยัง URL ที่ระบุ หากมีการลงทะเบียนแอปเป็นตัวแฮนเดิลเริ่มต้นสำหรับ URL แอปจะเปิดขึ้นแทน และไอคอนสำหรับการดำเนินการจะเป็นไอคอนของแอป
ตัวอย่าง
โค้ดต่อไปนี้จะส่งการทำงานของ URL แบบเปิด ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ OpenUrlAction
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'Open Google', 'postbackData': 'postback_data_1234', 'openUrlAction': { 'url': 'https://www.google.com' } } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define an open URL suggested action let suggestions = [ { action: { text: 'Open Google', postbackData: 'postback_data_1234', openUrlAction: { url: 'https://www.google.com' } } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with an open URL suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.OpenUrlAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating an open url suggested action OpenUrlAction openUrlAction = new OpenUrlAction(); openUrlAction.setUrl("https://www.google.com"); // creating a suggested action based on an open url action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Open Google"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setOpenUrlAction(openUrlAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create an open url suggested action suggestions = [ messages.OpenUrlAction('Open Google', 'reply:postback_data_1234', 'https://www.google.com') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create an open url action OpenUrlAction openUrlAction = new OpenUrlAction { Url = "https://www.google.com" }; // Attach the open url action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { OpenUrlAction = openUrlAction, Text = "Open Google", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
สร้างกิจกรรมปฏิทิน
การดำเนินการสร้างกิจกรรมในปฏิทินจะเปิดแอปปฏิทินของผู้ใช้ และเริ่มสร้างกิจกรรมใหม่ด้วยข้อมูลที่ระบุ
ตัวอย่าง
รหัสต่อไปนี้จะส่งการดำเนินการสร้างกิจกรรมในปฏิทิน ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ CreateCalendarEventAction
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'Save to calendar', 'postbackData': 'postback_data_1234', 'fallbackUrl': 'https://www.google.com/calendar', 'createCalendarEventAction': { 'startTime': '2020-06-30T19:00:00Z', 'endTime': '2020-06-30T20:00:00Z', 'title': 'My calendar event', 'description': 'Description of the calendar event' } } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a create calendar event suggested action let suggestions = [ { action: { text: 'Save to calendar', postbackData: 'postback_data_1234', createCalendarEventAction: { startTime: '2020-06-30T19:00:00Z', endTime: '2020-06-30T20:00:00Z', title: 'My calendar event', description: 'Description of the calendar event', }, } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a create calendar event suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.CreateCalendarEventAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a create calendar event suggested action CreateCalendarEventAction createCalendarEventAction = new CreateCalendarEventAction(); calendarEventAction.setTitle("My calendar event"); calendarEventAction.setDescription("Description of the calendar event"); calendarEventAction.setStartTime("2020-06-30T19:00:00Z"); calendarEventAction.setEndTime("2020-06-30T20:00:00Z"); // creating a suggested action based on a create calendar event action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Save to calendar"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setCreateCalendarEventAction(createCalendarEventAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a calendar event suggested action suggestions = [ messages.CreateCalendarEventAction('Save to Calendar', 'reply:postback_data_1234', '2020-06-30T19:00:00Z', '2020-06-30T20:00:00Z', 'My calendar event', 'Description of the calendar event') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a calendar event action CreateCalendarEventAction calendarEventAction = new CreateCalendarEventAction { Title = "My calendar event", Description = "Description of the calendar event", StartTime = "2020-06-30T19:00:00Z", EndTime = "2020-06-30T20:00:00Z" }; // Attach the calendar event action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { CreateCalendarEventAction = calendarEventAction, Text = "Save to calendar", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
รายการชิปคำแนะนำ
Agent จะส่งรายการชิปคำแนะนำพร้อมข้อความเพื่อแนะนำการดำเนินการที่ตามมาของผู้ใช้ รายการชิปจะแสดงก็ต่อเมื่อข้อความที่เกี่ยวข้องอยู่ที่ด้านล่างของการสนทนาเท่านั้น ข้อความในการสนทนาหลังจากนั้น (จากผู้ใช้หรือ Agent) จะเขียนทับรายการชิป
ชิปในรายการคือการตอบกลับที่แนะนำและการดำเนินการที่แนะนำ
รายการชิปมีชิปคำแนะนำสูงสุด 11 รายการ และป้ายกำกับชิปแต่ละรายการมีอักขระได้สูงสุด 25 ตัว
ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ AgentContentMessage
การ์ดริชมีเดีย
เมื่อคุณต้องส่งข้อมูล สื่อ หรือคำแนะนำที่เกี่ยวข้องทีละชุด คุณควรส่งการ์ดริชมีเดีย Rich Card จะช่วยให้ตัวแทนส่งข้อมูลหลายหน่วยในข้อความเดียวกันได้
Rich Card สามารถประกอบด้วยรายการต่อไปนี้
- ภาพ/วิดีโอ
- ข้อความชื่อ
- ข้อความคำอธิบาย
- รายการการตอบกลับที่แนะนำและการดำเนินการที่แนะนำ (ไม่เกิน 4 รายการ)
การ์ดริชมีเดียสามารถมีรายการทั้งหมดที่แสดงอยู่ แต่การ์ดจะต้องมีรูปภาพ วิดีโอ หรือชื่อเป็นอย่างน้อย การ์ดริชมีเดียจะมีการดำเนินการที่แนะนำหรือการตอบกลับที่แนะนำได้สูงสุด 4 รายการ ซึ่งต้องไม่มีการดำเนินการที่แนะนำและการตอบกลับที่แนะนำรวมกันในการ์ดเดียว
Agent สามารถส่งการ์ดริชมีเดียหลายการ์ดพร้อมกันในภาพสไลด์การ์ดริชมีเดีย
ความสูงของการ์ด
การ์ดจะขยายในแนวตั้งเพื่อให้พอดีกับเนื้อหา Rich Card มีความสูงขั้นต่ำ 112 DP และความสูงสูงสุด 344 DP หากเนื้อหาของการ์ดไม่ใหญ่พอที่จะพอดีกับความสูงขั้นต่ำของการ์ด การ์ดจะขยายและเติมช่องว่างในความสูงที่เกินมา
สื่อในการ์ดริชมีเดียต้องมีความสูง 1 ใน 3 ส่วนต่อไปนี้
- สั้น: 112 DP
- ปานกลาง: 168 DP
- สูง: 264 DP
หากสื่อไม่พอดีกับขนาดภายในการ์ดเนื่องจากความสูงที่เลือก ระบบจะเลือกตัวอย่างสื่อโดยการซูมและครอบตัดสื่อ
ตัวอย่าง
โค้ดต่อไปนี้จะส่ง Rich Card ที่มีรูปภาพและการตอบกลับที่แนะนำ ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ RichCard
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'richCard': { 'standaloneCard': { 'thumbnailImageAlignment': 'RIGHT', 'cardOrientation': 'VERTICAL', 'cardContent': { 'title': 'Hello, world!', 'description': 'RBM is awesome!', 'media': { 'height': 'TALL', 'contentInfo':{ 'fileUrl': 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif', 'forceRefresh': 'false' } }, 'suggestions': [ { 'reply': { 'text': 'Suggestion #1', 'postbackData': 'suggestion_1' } }, { 'reply': { 'text': 'Suggestion #2', 'postbackData': 'suggestion_2' } } ] } } } } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Suggested replies to be used in the card let suggestions = [ { reply: { 'text': 'Suggestion #1', 'postbackData': 'suggestion_1', }, }, { reply: { 'text': 'Suggestion #2', 'postbackData': 'suggestion_2', }, }, ]; // Image to be displayed by the card let imageUrl = 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif'; // Definition of the card parameters let params = { messageText: 'Hello, world!', messageDescription: 'RBM is awesome!', msisdn: '+12223334444', suggestions: suggestions, imageUrl: imageUrl, height: 'TALL', }; // Send rich card to device rbmApiHelper.sendRichCard(params, function(response) { console.log(response); });โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.StandaloneCard; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.cards.CardOrientation; import com.google.rbm.cards.MediaHeight; import com.google.rbm.RbmApiHelper; import com.google.rbm.SuggestionHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); suggestions.add( new SuggestionHelper("Suggestion #1", "suggestion_1").getSuggestedReply()); suggestions.add( new SuggestionHelper("Suggestion #2", "suggestion_2").getSuggestedReply()); String imageUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // Create a standalone rich card to send to the user StandaloneCard standaloneCard = rbmApiHelper.createStandaloneCard( "Hello, world!", "RBM is awesome!", imageUrl, MediaHeight.MEDIUM, CardOrientation.VERTICAL, suggestions ); rbmApiHelper.sendStandaloneCard(standaloneCard, "+12223334444"); } catch(Exception e) { e.printStackTrace(); }โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Suggested replies to be used in the card suggestions = [ messages.SuggestedReply('Suggestion #1', 'reply:suggestion_1'), messages.SuggestedReply('Suggestion #2', 'reply:suggestion_2') ] # Image to be displayed by the card image_url = 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif'; # Define rich card structure rich_card = messages.StandaloneCard('VERTICAL', 'Hello, world!', 'RBM is awesome!', suggestions, image_url, None, None, 'MEDIUM') # Append rich card and send to the user cluster = messages.MessageCluster().append_message(rich_card) cluster.send_to_msisdn('+12223334444')โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; using RCSBusinessMessaging.Cards; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); List<Suggestion> suggestions = new List<Suggestion> { // Create suggestion chips new SuggestionHelper("Suggestion #1", "suggestion_1").SuggestedReply(), new SuggestionHelper("Suggestion #2", "suggestion_2").SuggestedReply() }; string imageUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // Create rich card with suggestions StandaloneCard standaloneCard = rbmApiHelper.CreateStandaloneCard( "Hello, world!", "RBM is awesome", imageUrl, MediaHeight.TALL, CardOrientation.VERTICAL, suggestions ); // Send rich card to user rbmApiHelper.SendStandaloneCard(standaloneCard, "+12223334444");โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
ภาพสไลด์ Rich Card
เมื่อต้องการนำเสนอตัวเลือกหลายรายการให้แก่ผู้ใช้ ให้ใช้ภาพสไลด์การ์ดริชมีเดีย ภาพสไลด์จะเรียงการ์ดที่สมบูรณ์หลายรายการเข้าด้วยกัน ช่วยให้ผู้ใช้เปรียบเทียบรายการและแสดงความรู้สึกต่อแต่ละรายการได้
ภาพสไลด์อาจมีการ์ดริชมีเดียอย่างน้อย 2 ใบและได้สูงสุด 10 การ์ด การ์ดริชมีเดียภายในภาพสไลด์ต้องเป็นไปตามข้อกำหนดทั่วไปของการ์ดริชมีเดียสำหรับเนื้อหาและความสูง
การตัดข้อความ
เช่นเดียวกับการ์ดริชมีเดีย ปัจจัยต่างๆ (เช่น ความละเอียดหน้าจอ ความหนาแน่นของพิกเซล และค่ากำหนดของผู้ใช้) ส่งผลต่อลักษณะที่การ์ดปรากฏต่อผู้ใช้ปลายทาง อย่างไรก็ตาม ในภาพสไลด์ ความสูงของการ์ด 2-3 รายการแรกจะกำหนดความสูงของการ์ดทั้งหมดในภาพสไลด์ และความสูงของการ์ดมีผลต่อชื่อ คำอธิบาย และการตัดคำแนะนำ
หากอุปกรณ์ไม่สามารถแสดงองค์ประกอบทั้งหมดของการ์ดเนื่องจากข้อจำกัดด้านการแสดงผลหรือความสูงของการ์ด RBM จะตัดการ์ดจนกว่าจะสามารถแสดงบนอุปกรณ์ได้โดยใช้ตรรกะต่อไปนี้
- ลดคำอธิบายให้เหลือ 1 บรรทัด
- ลดชื่อให้เหลือ 1 บรรทัด
- ข้ามคำแนะนำที่ใส่ไม่ได้ในการ์ด โดยเริ่มจากท้ายรายการที่กำหนดไว้
- ไม่ต้องใส่คำอธิบาย
- ไม่ใส่ชื่อ
พยายามตั้งชื่อและคําอธิบายให้สั้นที่สุดเพื่อไม่ให้ถูกตัดออก สำหรับสื่อขนาดยาว ให้ใช้ชื่อและคำอธิบายหรือคำแนะนำ 1 รายการ สำหรับสื่อสื่อ ให้ใช้คำแนะนำไม่เกิน 2 รายการ ใช้คำแนะนำไม่เกิน 3 รายการสำหรับสื่อแบบสั้น อย่าใส่สื่อในการ์ดเพื่อให้เข้ากับคำแนะนำ 4 ข้อ
เก็บการ์ดในด้านขนาดและความยาวของเนื้อหาให้เท่าๆ กันโดยประมาณ และหากจำเป็น ให้ใส่การ์ดที่ใหญ่กว่าเดิมไว้ในภาพสไลด์ เพื่อหลีกเลี่ยงการตัดข้อมูลในการ์ดต่อไปนี้
ตัวอย่าง
โค้ดต่อไปนี้จะส่งภาพสไลด์ Rich Card ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ RichCard
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'richCard': { 'carouselCard': { 'cardWidth':'MEDIUM', 'cardContents': [ { 'title':'Card #1', 'description':'The description for card #1', 'suggestions': [ { 'reply': { 'text':'Card #1', 'postbackData':'card_1' } } ], 'media': { 'height':'MEDIUM', 'contentInfo': { 'fileUrl':'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg', 'forceRefresh':'false' } } }, { 'title':'Card #2', 'description':'The description for card #2', 'suggestions': [ { 'reply': { 'text':'Card #2', 'postbackData':'card_2' } } ], 'media': { 'height':'MEDIUM', 'contentInfo': { 'fileUrl':'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg', 'forceRefresh': 'false' } } } ] } } } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Images for the carousel cards let card1Image = 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg'; let card2Image = 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg'; // Define the card contents for a carousel with two cards, each with one suggested reply let cardContents = [ { title: 'Card #1', description: 'The description for card #1', suggestions: [ { reply: { text: 'Card #1', postbackData: 'card_1', } } ], media: { height: 'MEDIUM', contentInfo: { fileUrl: card1Image, forceRefresh: false, }, }, }, { title: 'Card #2', description: 'The description for card #2', suggestions: [ { reply: { text: 'Card #2', postbackData: 'card_2', } } ], media: { height: 'MEDIUM', contentInfo: { fileUrl: card2Image, forceRefresh: false, }, }, }, ]; // Definition of carousel card let params = { msisdn: '+12223334444', cardContents: cardContents, }; // Send the device the carousel card defined above rbmApiHelper.sendCarouselCard(params, function(response) { console.log(response); });โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.CardContent; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.cards.CardOrientation; import com.google.rbm.cards.CardWidth; import com.google.rbm.cards.MediaHeight; import com.google.rbm.RbmApiHelper; import com.google.rbm.SuggestionHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); List cardContents = new ArrayList(); // Images for the carousel cards String card1Image = "https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg"; // Create suggestions for first carousel card List card1Suggestions = new ArrayList(); card1Suggestions.add( new SuggestionHelper("Card #1", "card_1")); cardContents.add( new StandaloneCardHelper( "Card #1", "The description for card #1", card1Image, card1Suggestions) .getCardContent(MediaHeight.SHORT) ); // Images for the carousel cards String card2Image = "https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg"; // Create suggestions for second carousel card List card2Suggestions = new ArrayList(); card2Suggestions.add( new SuggestionHelper("Card #2", "card_2")); cardContents.add( new StandaloneCardHelper( "Card #2", "The description for card #2", card2Image, card2Suggestions) .getCardContent(MediaHeight.SHORT) ); // Send the carousel to the user rbmApiHelper.sendCarouselCards(cardContents, CardWidth.MEDIUM, "+12223334444"); } catch(Exception e) { e.printStackTrace(); }โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Images for the carousel cards card_image_1 = 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg'; card_image_2 = 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg'; # Suggested replies to be used in the cards suggestions1 = [ messages.SuggestedReply('Card #1', 'reply:card_1') ] suggestions2 = [ messages.SuggestedReply('Card #2', 'reply:card_2') ] # Define the card contents for a carousel with two cards, # each with one suggested reply card_contents = [] card_contents.append(messages.CardContent('Card #1', 'The description for card #1', card_image_1, 'MEDIUM', suggestions1)) card_contents.append(messages.CardContent('Card #2', 'The description for card #2', card_image_2, 'MEDIUM', suggestions2)) # Send the device the carousel card defined above carousel_card = messages.CarouselCard('MEDIUM', card_contents) cluster = messages.MessageCluster().append_message(carousel_card) cluster.send_to_msisdn('+12223334444')โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; using RCSBusinessMessaging.Cards; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Image references to be used in the carousel cards string card1Image = "https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg"; string card2Image = "https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg"; // Suggestion chip lists to be used in carousel cards List<Suggestion> suggestions1 = new List<Suggestion> { new SuggestionHelper("Card #1", "card_1").SuggestedReply() }; List<Suggestion> suggestions2 = new List<Suggestion> { new SuggestionHelper("Card #2", "card_2").SuggestedReply() }; // Create the card content for the carousel List<CardContent> cardContents = new List<CardContent> { // Add items as card content new StandaloneCardHelper( "Card #1", "The description for card #1", card1Image, suggestions1).GetCardContent(), new StandaloneCardHelper( "Card #2", "The description for card #2", card2Image, suggestions2).GetCardContent() }; // Send the carousel to the user rbmApiHelper.SendCarouselCards(cardContents, CardWidth.MEDIUM, msisdn);โค้ดนี้ข้อความที่ตัดตอนมาจากตัวแทนตัวอย่าง RBM