ตัวแทน RCS for Business จะสื่อสารกับผู้ใช้โดยการส่งและรับข้อความ หากต้องการส่งข้อความถึงผู้ใช้ ตัวแทนจะส่งคำขอข้อความไปยัง API การรับส่งข้อความทางธุรกิจ RCS คำขอเดียวสามารถมีข้อความ, Rich Card, ไฟล์สื่อและ PDF, การตอบกลับที่แนะนำ และการดำเนินการที่แนะนำ
แพลตฟอร์ม RCS for Business จะแสดงข้อผิดพลาดในบางสถานการณ์เพื่อช่วยคุณจัดการการนำส่งข้อความ ดังนี้
- หากคุณส่งข้อความถึงผู้ใช้ที่อุปกรณ์ไม่รองรับ RCS หรือไม่ได้เปิดใช้ RCS แพลตฟอร์ม RCS for Business จะแสดงข้อผิดพลาด
404 NOT_FOUNDในกรณีนี้ คุณสามารถพยายามติดต่อผู้ใช้ผ่านวิธีการสำรองที่กำหนดไว้ในโครงสร้างพื้นฐานของคุณ - หากคุณส่งข้อความถึงผู้ใช้ RCS ในเครือข่ายที่ยังไม่ได้เปิดตัว Agent หรือในเครือข่ายที่ไม่ได้เปิดใช้การรับส่งข้อมูล RCS แพลตฟอร์ม RCS for Business จะแสดงข้อผิดพลาด
404 NOT_FOUND - หากคุณส่งข้อความที่มีฟีเจอร์ที่อุปกรณ์ของผู้ใช้ไม่รองรับ แพลตฟอร์ม RCS for Business จะแสดงข้อผิดพลาด
400 INVALID_ARGUMENTและไม่นำส่งข้อความของคุณ
ในฐานะส่วนหนึ่งของกลยุทธ์การรับส่งข้อความแบบหลายช่องทาง วิธีที่ดีที่สุดคือเพิกถอนข้อความที่ไม่ได้ส่งหลังจากผ่านไประยะเวลาที่เหมาะสม แล้วส่งข้อความเหล่านั้นผ่านช่องทางอื่น หากต้องการเพิกถอนข้อความโดยอัตโนมัติในเวลาที่กำหนดไว้ล่วงหน้า ให้ตั้งค่าการหมดอายุของข้อความ
ผู้รับออฟไลน์อยู่
แพลตฟอร์ม RCS for Business ยังคงยอมรับข้อความเพื่อนำส่งแม้ว่าผู้รับจะออฟไลน์อยู่ก็ตาม คุณได้รับการตอบกลับ 200 OK และแพลตฟอร์ม RCS for Business จะเก็บข้อความไว้และพยายามส่งใหม่เป็นเวลา 30 วัน คุณไม่จำเป็นต้องขอให้ RCS for Business ส่งข้อความอีกครั้ง
RCS for Business จะลบข้อความที่ยังไม่ได้นำส่งหลังจากส่งไปแล้ว 30 วัน
คุณอาจต้องเพิกถอนข้อความที่ยังไม่ได้นำส่งก่อนหมดระยะเวลา 30 วันนี้ ทั้งนี้ขึ้นอยู่กับกรณีการใช้งานของตัวแทน การเพิกถอนจะช่วยป้องกันไม่ให้ผู้ใช้ออฟไลน์ได้รับข้อความที่ล้าสมัยเมื่อกลับมาออนไลน์ คุณเพิกถอนข้อความได้หลายวิธี ดังนี้
- ส่งคำขอเพิกถอนเพื่อเรียกใช้การเพิกถอน
- ตั้งค่าการหมดอายุของข้อความเพื่อเพิกถอนข้อความโดยอัตโนมัติในเวลาที่เหมาะสม
ตั้งค่าการหมดอายุของข้อความ
ข้อความของตัวแทนเป็นเรื่องที่ต้องดำเนินการอย่างเร่งด่วนหรือไม่ เช่น OTP จะใช้ได้ในระยะเวลาสั้นๆ เท่านั้น ข้อเสนอนี้มีเวลาจำกัดจะหมดอายุ และการช่วยเตือนการนัดหมายก็จะไม่เกี่ยวข้องอีกต่อไปหลังจากวันที่นัดหมาย ตั้งค่าการหมดอายุของข้อความเพื่อให้ข้อความมีความเกี่ยวข้องและเป็นปัจจุบันอยู่เสมอ ซึ่งจะช่วยป้องกันไม่ให้ผู้ใช้ออฟไลน์ได้รับเนื้อหาที่ล้าสมัยเมื่อกลับมาออนไลน์อีกครั้ง การหมดอายุยังเป็นสัญญาณที่ดีในการเรียกใช้กลยุทธ์การรับส่งข้อความสำรองเพื่อให้ผู้ใช้ได้รับข้อมูลที่ต้องการอย่างทันท่วงที
หากต้องการตั้งค่าการหมดอายุของข้อความ ให้ระบุช่องใดช่องหนึ่งต่อไปนี้ในข้อความของตัวแทน
expireTime: เวลาที่แน่นอนในเขตเวลา UTC ที่ข้อความหมดอายุttl(ระยะเวลาที่ใช้งานได้): ระยะเวลาก่อนที่ข้อความจะหมดอายุ
ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ AgentMessage
ค่าสูงสุดสำหรับ ttl และ expireTime คือ 15 วันหลังจากส่งข้อความ
ค่าต่ำสุดสำหรับ ttl และ expireTime คือ 6 วินาทีหลังจากส่งข้อความ
คำแนะนำในการตั้งค่าการหมดอายุของข้อความ
สำหรับข้อความการตรวจสอบสิทธิ์ (OTP): ตั้งค่า
ttlเป็น 15 วินาทีขึ้นไปหลังจากส่งข้อความเพื่อลดโอกาสที่จะเกิดภาวะแข่งขันในการนำส่งและการเพิกถอนได้อย่างมากสำหรับข้อความธุรกรรมและข้อความโปรโมชัน: ตั้งค่าการหมดอายุให้นานขึ้น (อย่างน้อย 60 วินาที หรือเป็นนาทีถึงชั่วโมง ทั้งนี้ขึ้นอยู่กับกรณีการใช้งาน) เนื่องจากอุปกรณ์ต้องใช้เวลาเพิ่มเติมในการสแกนข้อความและดาวน์โหลดหรือประมวลผลเนื้อหาริชมีเดีย และผู้ใช้อาจพบปัญหาการเชื่อมต่อขาดหายเป็นระยะเวลาสั้นๆ (เช่น ในลิฟต์หรืออุโมงค์)
Time to Live (TTL) สำหรับข้อความ
เมื่อตั้งค่า TTL สำหรับข้อความ RCS for Business คุณจะต้องระบุระยะเวลาที่ข้อความควรได้รับการพิจารณาว่าถูกต้องและส่งได้ หากส่งข้อความไปยังอุปกรณ์ของผู้ใช้ไม่สำเร็จภายในระยะเวลา TTL นี้ แพลตฟอร์ม RCS for Business จะพยายามเพิกถอนข้อความโดยอัตโนมัติ
เมื่อเริ่มการเพิกถอนข้อความ คุณจะขอให้แพลตฟอร์ม RCS for Business หยุดพยายามส่งข้อความนั้น อย่างไรก็ตาม การดำเนินการนี้จะมีผลกับการพยายามนำส่งในอนาคตเท่านั้น หากอุปกรณ์ของผู้ใช้ดึงข้อมูลข้อความเรียบร้อยแล้ว แสดงว่าข้อความกำลังอยู่ระหว่างการประมวลผล และแพลตฟอร์ม RCS for Business จะเพิกถอนข้อความออกจากอุปกรณ์ของผู้ใช้ไม่ได้
สิ่งที่จะเกิดขึ้นเกี่ยวกับการแจ้งเตือนมีดังนี้
ข้อความที่ส่งภายใน TTL: หากอุปกรณ์ของผู้ใช้ออนไลน์และได้รับข้อความก่อนที่ TTL จะหมดอายุ คุณจะได้รับการแจ้งเตือน
DELIVEREDระบบจะไม่ส่งการแจ้งเตือนการเพิกถอนเนื่องจากส่งข้อความเรียบร้อยแล้ว สถานการณ์นี้พบได้บ่อยที่สุดและเป็นไปตามที่คาดไว้ข้อความไม่ได้รับการนำส่งก่อนที่ TTL จะหมดอายุ: หาก TTL หมดอายุก่อนที่ข้อความจะไปถึงอุปกรณ์ของผู้ใช้ (เช่น อุปกรณ์ออฟไลน์) แพลตฟอร์ม RCS for Business จะพยายามเพิกถอนข้อความ คุณจะได้รับการแจ้งเตือน
TTL_EXPIRATION_REVOKEDซึ่งระบุว่าระบบนำข้อความออกจากคิวการนำส่งเรียบร้อยแล้ว ในกรณีนี้ ผู้ใช้จะไม่ได้รับข้อความ
คำแนะนำในการจัดการกรณีที่เกิดขึ้นไม่บ่อยนัก
ระบบของเราจะประมวลผลการนำส่งข้อความ RCS for Business และการหมดอายุของ TTL ไปพร้อมกัน ด้วยเหตุนี้ คุณจึงอาจเห็นกรณีที่เกิดขึ้นไม่บ่อยนักซึ่งเวลาในการแจ้งเตือนไม่เป็นไปตามที่คาดไว้ ตัวอย่างเช่น คุณอาจได้รับการแจ้งเตือนทั้งการนำส่งและ TTL หรืออาจไม่ได้รับการแจ้งเตือนใดเลย
คำแนะนำในการจัดการการแจ้งเตือนข้อความ RCS for Business มีดังนี้
การแจ้งเตือน
DELIVERED: หากคุณได้รับการแจ้งเตือนDELIVEREDสำหรับข้อความ แสดงว่าข้อความไปถึงผู้ใช้แล้ว คุณสามารถเพิกเฉยต่อการแจ้งเตือน TTL ที่ตามมาสำหรับข้อความนั้นๆ ได้อย่างปลอดภัยการแจ้งเตือน
TTL_EXPIRATION_REVOKED: หากคุณได้รับการแจ้งเตือน TTL ที่มีสถานะTTL_EXPIRATION_REVOKEDหมายความว่าระบบ RCS for Business จะหยุดพยายามส่งข้อความนั้น คุณควรพิจารณาว่าข้อความนี้ส่งไม่สำเร็จและดำเนินการตามกลยุทธ์สำรองหากจำเป็นการแจ้งเตือน TTL ที่มีสถานะอื่นๆ: หากคุณได้รับการแจ้งเตือน TTL ที่มีสถานะอื่นๆ แสดงว่าการพยายามเพิกถอนไม่สามารถสรุปได้
- สำหรับข้อความสำคัญ เช่น รหัสผ่านแบบใช้ครั้งเดียว (OTP) ให้เริ่มใช้วิธีสำรอง
- สำหรับข้อความที่ไม่สำคัญ ให้ตัดสินใจว่าจะเริ่มใช้โหมดสำรองหรือไม่
- ไม่มีการแจ้งเตือน: ในกรณีที่เกิดขึ้นไม่บ่อยนัก ระบบอาจส่งการแจ้งเตือน TTL ไม่สำเร็จ และไคลเอ็นต์อาจสร้างการแจ้งเตือนการนำส่งไม่สำเร็จด้วย กรณีนี้เกิดขึ้นได้น้อยมาก
ตั้งค่าประเภทการรับส่งข้อความ
RBM API มีช่อง messageTrafficType เพื่อจัดหมวดหมู่ข้อความ
แม้ว่ากรณีการใช้งานของตัวแทนจะยังคงกำหนดลักษณะการทำงานของตัวแทนและกฎทางธุรกิจที่ใช้ แต่ messageTrafficType ช่วยให้จัดหมวดหมู่เนื้อหาข้อความได้ละเอียดยิ่งขึ้น ซึ่งจะช่วยให้ตัวแทนคนเดียวสามารถจัดการกรณีการใช้งานหลายกรณีได้ในที่สุด ซึ่งการดำเนินการนี้จะไม่ส่งผลกระทบต่อกรณีการใช้งานหรือกฎทางธุรกิจของตัวแทนที่มีอยู่ในขณะนี้
ฟิลด์นี้จะกรอกหรือไม่ก็ได้ แต่เราขอแนะนำให้ตั้งค่าไว้เลยเพื่อไม่ให้เกิดข้อผิดพลาดเมื่อฟิลด์นี้กลายเป็นฟิลด์ที่ต้องกรอก
หากต้องการตั้งค่าประเภทการเข้าชมข้อความ ให้กำหนด messageTrafficType ที่เหมาะสมสำหรับแต่ละข้อความตามเนื้อหา ตารางต่อไปนี้แสดงประเภทการเข้าชมที่รองรับและกรณีการใช้งาน Agent ที่คาดไว้ การแมปนี้เป็นคำแนะนำที่แนะนําเกี่ยวกับการใช้งานที่คาดไว้ ไม่ใช่ข้อจํากัดที่บังคับใช้โดย API ในขณะนี้
| ประเภทการเข้าชม | เนื้อหาข้อความ | กรณีการใช้งานของตัวแทนที่แนะนำ |
|---|---|---|
AUTHENTICATION |
สำหรับข้อความการตรวจสอบสิทธิ์ | OTP |
TRANSACTION |
สำหรับข้อความเกี่ยวกับบริการหรือผลิตภัณฑ์ที่มีอยู่ของผู้ใช้ เช่น การยืนยัน ใบเสร็จรับเงิน หรือรายละเอียดการจอง | ธุรกรรมหรือการใช้งานหลายอย่าง |
PROMOTION |
สำหรับข้อความส่งเสริมการขาย เช่น ข้อเสนอ ส่วนลด ประกาศ หรือเนื้อหาส่งเสริมการขายอื่นๆ | โปรโมชันหรือการใช้งานหลายอย่าง |
SERVICEREQUEST |
สำหรับข้อความเกี่ยวกับบริการที่ผู้ใช้ร้องขออย่างชัดแจ้ง | OTP, ธุรกรรม, โปรโมชัน หรืออเนกประสงค์ |
ACKNOWLEDGEMENT |
สำหรับข้อความที่ใช้เพื่อรับทราบการดำเนินการของผู้ใช้ โดยเฉพาะคำขอยกเลิกการสมัครรับข้อมูล ซึ่งเป็นการยืนยันว่าเราได้รับคำขอของผู้ใช้แล้วและกำลังดำเนินการอยู่ | OTP, ธุรกรรม, โปรโมชัน หรืออเนกประสงค์ |
หากไม่ได้ตั้งค่าประเภทการเข้าชม ระบบจะกำหนดประเภทเริ่มต้นสำหรับกรณีการใช้งานของ Agent
| กรณีการใช้งานของตัวแทน | ประเภทการเข้าชมเริ่มต้น |
|---|---|
| OTP | AUTHENTICATION |
| ธุรกรรม | TRANSACTION |
| โปรโมชัน | PROMOTION |
| ใช้ได้หลายครั้ง | MESSAGE_TRAFFIC_TYPE_UNSPECIFIED |
Multi-use Agent ไม่มีประเภทการเข้าชมเริ่มต้น คุณควรตั้งค่าประเภทการเข้าชมอย่างชัดเจนสำหรับแต่ละข้อความตามเนื้อหา หากคุณไม่แทนที่ค่า MESSAGE_TRAFFIC_TYPE_UNSPECIFIED ระบบจะยังคงยอมรับและส่งข้อความโดยไม่มีการจำแนกประเภทการเข้าชมที่เฉพาะเจาะจง
ขีดจำกัดขนาดข้อความ
ขนาดสูงสุดของ AgentMessage ที่แปลงเป็นสตริงทั้งหมดคือ 250 KB ส่วนข้อความของข้อความมีขีดจำกัดของตัวเองอยู่ที่ 3,072 อักขระ
เพื่อป้องกันไม่ให้ผู้ใช้ใช้ข้อมูลโดยไม่คาดคิด ขนาดสูงสุดของไฟล์ที่ส่งผ่าน RCS for Business ได้คือ 100 MiB และขนาดรวมของไฟล์แนบสื่อและ PDF ทั้งหมดภายในข้อความ RCS for Business ข้อความเดียวต้องไม่เกิน 100 MiB (1 MiB = 1,048,576 ไบต์) ดูข้อมูลเพิ่มเติมได้ที่ไฟล์สื่อและไฟล์ PDF
ข้อความ
ข้อความที่เรียบง่ายที่สุดจะประกอบด้วยข้อความ ข้อความเหมาะที่สุดสำหรับการสื่อสารข้อมูลโดยไม่จำเป็นต้องใช้ภาพ การโต้ตอบที่ซับซ้อน หรือการตอบกลับ
ตัวอย่าง
โค้ดต่อไปนี้จะส่งข้อความธรรมดา ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ phones.agentMessages.create
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d '{ "contentMessage": { "text": "Hello, world!" }, "messageTrafficType": "PROMOTION" }'
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); let params = { messageText: 'Hello, world!', msisdn: '+12223334444', }; // Send a simple message to the device rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Send simple text message to user rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444" ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a simple RBM text message message_text = messages.TextMessage('Hello, world!') # Send text message to the device messages.MessageCluster().append_message(message_text).send_to_msisdn('+12223334444')
C#
using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", );
เนื้อหาข้อความพื้นฐาน - การแปลง SMS
ผู้ให้บริการได้เปิดตัวรูปแบบการเรียกเก็บเงินเพื่อรองรับการเปลี่ยนจากการส่งข้อความ SMS ไปเป็นการส่งข้อความ RCS for Business ข้อความ RCS for Business ที่มีอักขระ UTF-8 ไม่เกิน 160 ตัวเรียกว่าข้อความพื้นฐาน
เมื่อสร้างคำขอเพื่อส่งข้อความพื้นฐาน โปรดทราบว่าระบบจะนับอักขระเป็น 1 ไบต์ (UTF-8) หากคุณส่งข้อความที่มีสัญลักษณ์พิเศษ เช่น อีโมจิหรือการเข้ารหัสข้อความแบบหลายไบต์ อักขระแต่ละตัวจะนับเป็นการเข้ารหัสข้อความ UTF-8 จำนวน 2-4 ตัวขึ้นไป
ป้อนข้อความในช่องเพื่อตรวจสอบความยาว
เนื้อหา SMS และตัวอย่างลิงก์
ไคลเอ็นต์ RCS อาจใช้ตัวอย่างลิงก์ หากข้อความ RCS for Business แบบข้อความเท่านั้นมี URL ของเว็บไซต์ที่มีแท็ก openGraph ไคลเอ็นต์จะสร้างตัวอย่าง (รูปภาพ ชื่อ ฯลฯ) เพื่อมอบประสบการณ์การใช้งานที่สมบูรณ์ยิ่งขึ้นได้ ตัวอย่างเช่น ดูข้อความพื้นฐานที่มีตัวอย่าง URL
โปรดทราบว่าไคลเอ็นต์ RCS อาจอนุญาตให้ผู้ใช้ปิดใช้ตัวอย่างลิงก์ได้
รหัสผ่านแบบใช้ครั้งเดียวสำหรับการยืนยันผู้ใช้
คุณสามารถใช้ RCS for Business เพื่อส่งรหัสผ่านแบบใช้ครั้งเดียว (OTP) สำหรับการยืนยันผู้ใช้อัตโนมัติด้วย SMS Retriever API ไม่มี API เฉพาะสำหรับการอ่าน OTP ที่ส่งผ่าน RCS for Business
วิธีการทำงานสำหรับ Android
สำหรับแอป Android ที่ลงทะเบียนกับ SMS Retriever API แล้ว API จะคอยฟังข้อความ RCS for Business ที่จัดรูปแบบอย่างถูกต้อง ข้อความนี้ต้องมีทั้ง OTP และแฮชที่ไม่ซ้ำกันซึ่งระบุแอปของคุณ
เมื่อได้รับข้อความ RCS for Business ในรูปแบบที่ถูกต้อง SMS Retriever API จะประมวลผลข้อความดังกล่าวเหมือนกับ OTP ทาง SMS หลังจากแฮชตรงกับแอปของคุณแล้ว ระบบจะดึงข้อมูล OTP และส่งต่อไปยังแอปเพื่อยืนยันผู้ใช้โดยอัตโนมัติ
- ตัวอย่างข้อความ RCS for Business สำหรับการยืนยันผู้ใช้:
Your code is <OTP><app hash>. - ตัวอย่าง:
Your code is 123456 M8tue43FGT.
ดูข้อมูลเพิ่มเติมเกี่ยวกับ SMS Retriever และ API ที่เกี่ยวข้องได้ที่เอกสารประกอบเกี่ยวกับ SMS Retriever ดูรายละเอียดเกี่ยวกับการยืนยันผู้ใช้โดยอัตโนมัติในแอปที่ลงทะเบียนกับ SMS Retriever API ได้ที่แผนภาพโฟลว์นี้
วิธีการทำงานสำหรับ iOS
สำหรับ iOS การจัดการ OTP ในตัวของระบบจะตรวจหาและแนะนำ OTP ของ RCS for Business สำหรับการป้อนข้อความอัตโนมัติโดยอัตโนมัติ เช่นเดียวกับ OTP ของ SMS แอป iOS ไม่จำเป็นต้องผสานรวม API ที่เฉพาะเจาะจงเพื่ออ่าน OTP
ไฟล์สื่อและ PDF
เมื่อส่งข้อความที่มีรูปภาพ วิดีโอ เสียง หรือไฟล์ PDF ตัวแทนของคุณต้องระบุ URL ที่เข้าถึงได้แบบสาธารณะสำหรับเนื้อหาหรืออัปโหลดไฟล์โดยตรง
ขนาดสูงสุดของไฟล์ที่ส่งได้คือ 100 MiB และขนาดรวมของไฟล์แนบสื่อและ PDF ทั้งหมดภายในข้อความเดียวต้องไม่เกิน 100 MiB
การบีบอัดและการแปลงสื่อ
แพลตฟอร์ม RCS for Business จะแปลงและบีบอัดไฟล์สื่อ (เช่น รูปภาพและวิดีโอ) โดยอัตโนมัติก่อนส่ง เพื่อให้มั่นใจว่าไฟล์จะโหลดได้อย่างรวดเร็วและทำงานได้ดีในเครือข่ายและอุปกรณ์ต่างๆ
การบีบอัดจะอิงตามคุณภาพของสื่อที่ป้อนเข้ามา ไม่ใช่การจำกัดขนาดไฟล์อย่างเคร่งครัด ซึ่งหมายความว่าคุณสามารถบีบอัดไฟล์ได้แม้ว่าไฟล์จะมีขนาดต่ำกว่าขีดจำกัดสูงสุด 100 MiB มากก็ตาม มาตรฐานการแปลงมีการเปลี่ยนแปลงอยู่ตลอดเวลา ดังนั้นจึงไม่มีการจำกัดขนาดไฟล์ที่แน่นอนซึ่งจะกำหนดว่าเมื่อใดที่ระบบจะข้ามการแปลง ทดลองใช้รูปแบบสื่อ ขนาด และอัตราการบีบอัดที่แตกต่างกันเพื่อค้นหาความสมดุลที่เหมาะสมที่สุดสำหรับเพย์โหลด
ข้อกำหนดเฉพาะเกี่ยวกับภาพปก
สำหรับไฟล์สื่อ คุณยังสามารถระบุภาพขนาดย่อที่ช่วยให้ผู้ใช้ดูตัวอย่างเนื้อหาก่อนคลิกได้ด้วย สำหรับไฟล์เสียง ระบบจะใช้วิดเจ็ตเสียงเริ่มต้นเป็นตัวยึดตำแหน่ง
- ขนาดไฟล์สูงสุดของภาพขนาดย่อคือ 100 kB เราขอแนะนำให้ใช้ขนาดไม่เกิน 50 KB เพื่อประสบการณ์การใช้งานที่ดีที่สุดของผู้ใช้
- สัดส่วนภาพของภาพปกควรตรงกับสัดส่วนของไฟล์ต้นฉบับ
การแคชและการจัดการ URL
แพลตฟอร์ม RCS for Business จะแคชไฟล์ไว้เป็นเวลา 60 วัน และ API จะแสดงรหัสไฟล์ที่ตัวแทนสามารถใส่ไว้ในข้อความถึงผู้ใช้ได้ หลังจากผ่านไป 60 วัน RCS for Business จะนำไฟล์ออกจากแคช
เมื่อระบุไฟล์ตาม URL แนวทางปฏิบัติแนะนำคือตั้งค่า contentMessage.forceRefresh เป็น false การตั้งค่า contentMessage.forceRefresh เป็น true จะบังคับให้ RCS for Business ดึงข้อมูลเนื้อหาใหม่จาก URL ที่ระบุ แม้ว่าเนื้อหา URL จะแคชไว้ก็ตาม ซึ่งจะเพิ่มเวลานำส่งข้อความสำหรับผู้ใช้
ตัวอย่าง 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); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.AgentContentMessage; import com.google.api.services.rcsbusinessmessaging.v1.model.AgentMessage; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); String fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // create media only message AgentContentMessage agentContentMessage = new AgentContentMessage(); agentContentMessage.setContentInfo(new ContentInfo().setFileUrl(fileUrl)); // attach content to message AgentMessage agentMessage = new AgentMessage(); agentMessage.setContentMessage(agentContentMessage); rbmApiHelper.sendAgentMessage(agentMessage, "+12223334444"); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create media file attachment file_message = messages.FileMessage('http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif') messages.MessageCluster().append_message(file_message).send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); string fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // Create content info with the file url ContentInfo contentInfo = new ContentInfo { FileUrl = fileUrl }; // Attach content info to a message AgentContentMessage agentContentMessage = new AgentContentMessage { ContentInfo = contentInfo, }; // Attach content to message AgentMessage agentMessage = new AgentMessage { ContentMessage = agentContentMessage }; rbmApiHelper.SendAgentMessage(agentMessage, "+12223334444");
หรือจะอัปโหลดสื่อก่อนส่งในข้อความด้วย files.create ก็ได้
ตัวอย่างการอัปโหลดไฟล์
โค้ดต่อไปนี้จะอัปโหลดไฟล์วิดีโอและไฟล์ภาพปก จากนั้นจะส่งทั้ง 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 JSONcurl -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 JSONcurl -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" } } }'
ประเภทสื่อที่รองรับ
RCS for Business รองรับสื่อประเภทต่อไปนี้ สำหรับภาพปก ระบบรองรับเฉพาะ image/jpeg, image/jpg, image/gif และ image/png เท่านั้น
| ประเภทสื่อ | ประเภทเอกสาร | ส่วนขยาย | ใช้ได้กับ Rich Card |
|---|---|---|---|
| application/ogg | เสียง OGG | .ogx | ไม่ |
| application/pdf | ใช่ (เฉพาะ Google Messages ในอินเดียเท่านั้น) | ||
| audio/aac | เสียง AAC | .aac | ไม่ |
| audio/mp3 | เสียง MP3 | .mp3 | ไม่ |
| audio/mpeg | เสียง MPEG | .mpeg | ไม่ |
| audio/mpg | เสียง MPG | .mp3 | ไม่ |
| audio/mp4 | เสียง MP4 | .mp4 | ไม่ |
| audio/mp4-latm | เสียง MP4-latm | .mp4 | ไม่ |
| audio/3gpp | เสียง 3GPP | .3gp | ไม่ |
| image/jpeg | JPEG | .jpeg, .jpg | ใช่ |
| image/gif | GIF | .gif | ใช่ |
| image/png | PNG | .png | ใช่ |
| video/h263 | วิดีโอ H263 | .h263 | ใช่ |
| video/m4v | วิดีโอ M4V | .m4v | ใช่ |
| video/mp4 | วิดีโอ MP4 | .mp4 | ใช่ |
| video/mpeg4 | วิดีโอ MPEG-4 | .mp4, .m4p | ใช่ |
| video/mpeg | วิดีโอ MPEG | .mpeg | ใช่ |
| video/webm | วิดีโอ WEBM | .webm | ใช่ |
คำแนะนำ
ตัวแทนจะส่งคำแนะนำ (การตอบกลับที่แนะนำและการดำเนินการที่แนะนำ) ในรายการชิปคำแนะนำหรือใน Rich Card
การตอบกลับที่แนะนำ
การตอบกลับที่แนะนำจะช่วยแนะนำผู้ใช้ตลอดการสนทนาโดยให้คำตอบที่ตัวแทนของคุณรู้วิธีโต้ตอบ
เมื่อผู้ใช้แตะการตอบกลับที่แนะนำ ตัวแทนจะได้รับเหตุการณ์ที่มีข้อความของการตอบกลับและข้อมูล Postback เพย์โหลดมีอักขระได้สูงสุด 2,048 ตัว
ตัวอย่าง
โค้ดต่อไปนี้จะส่งข้อความพร้อมการตอบกลับที่แนะนำ 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); });
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 );
การดำเนินการที่แนะนำ
การดำเนินการที่แนะนำจะช่วยแนะนำผู้ใช้ตลอดการสนทนาโดยใช้ประโยชน์จากฟังก์ชันการทำงานในตัวของอุปกรณ์ ตัวแทนสามารถแนะนำให้ผู้ใช้โทรออก เปิดตำแหน่งบนแผนที่ แชร์ตำแหน่ง เปิด URL หรือสร้างกิจกรรมในปฏิทินได้
สำหรับการดำเนินการที่แนะนำแต่ละรายการ คุณสามารถระบุ URL สำรอง (สูงสุด 2, 048 อักขระ) ได้ (ไม่บังคับ) URL นี้จะเปิดในหน้าต่างเบราว์เซอร์ใหม่หากอุปกรณ์ของผู้ใช้ไม่รองรับการดำเนินการที่แนะนำ
เมื่อผู้ใช้แตะการดำเนินการที่แนะนำ ตัวแทนจะได้รับเหตุการณ์ที่มีข้อมูล Postback ของการดำเนินการ
ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ SuggestedAction
การแสดงคำแนะนำ
การแสดงคำแนะนำมี 2 วิธีดังนี้
- Persistent: การดำเนินการที่แนะนำหรือการตอบกลับที่แสดงอยู่ภายในบับเบิลข้อความและคงอยู่ตลอดการสนทนา
- ชั่วคราว: คำแนะนำที่แสดงนอกบับเบิลข้อความและหายไปเมื่อการสนทนาดำเนินต่อไป
รูปแบบข้อความที่รองรับ
- คำแนะนำแบบถาวร: ใช้ได้กับข้อความแบบสแตนด์อโลนและ Rich Card
- คำแนะนำชั่วคราว: ใช้ได้กับ SMS, MMS และ Rich Card แบบสแตนด์อโลน
รวมคำแนะนำ
คุณสามารถผสมคำแนะนำแบบถาวรและแบบชั่วคราวในข้อความหรือ Rich Card เดียวกันได้
- ข้อความ: คำแนะนำจะเป็นแบบชั่วคราวโดยค่าเริ่มต้น หากต้องการให้แอปอยู่ในบับเบิล คุณต้องกำหนดค่าแอปเป็นแบบถาวร
- Rich Card: รองรับคำแนะนำแบบถาวรสูงสุด 4 รายการโดยค่าเริ่มต้น จากนั้นคุณสามารถเพิ่มคำแนะนำชั่วคราวเป็น "รายการชิป" ใต้การ์ดได้
ขีดจำกัดคำแนะนำ
ข้อความ SMS 1 ข้อความรองรับคำแนะนำได้สูงสุด 11 รายการ คำแนะนำแบบถาวรที่คุณรวมไว้จะนับรวมในขีดจำกัดทั้งหมดนี้ เช่น หากคุณรวมคำแนะนำแบบถาวร 4 รายการ คุณจะเพิ่มคำแนะนำแบบชั่วคราวได้สูงสุด 7 รายการ
| ประเภทคำแนะนำ | ขีดจำกัด | ตำแหน่งที่ปรากฏ |
|---|---|---|
| ต่อเนื่อง | สูงสุด 4 ตัว | ภายในบับเบิลข้อความ |
| เป็นค่าชั่วคราว | สูงสุด 11 รายการ | นอกบับเบิล (เป็นชิป) |
จำนวนอักขระสูงสุด
คำแนะนำแต่ละรายการมีอักขระได้สูงสุด 25 ตัว
ความโปร่งใสของ URL ในการดำเนินการที่แนะนำ
เพื่อสร้างความไว้วางใจของผู้ใช้ ระบบจะแสดง URL ที่เกี่ยวข้องเป็นข้อความบรรทัดที่ 2 ภายในปุ่มคำแนะนำสำหรับการดำเนินการที่แนะนำ "เปิด URL" ลักษณะการทำงานที่สอดคล้องกันนี้จะมีผลกับข้อความแบบสแตนด์อโลน, Rich Card และภาพสไลด์
ไคลเอ็นต์ที่รองรับสำหรับคำแนะนำแบบถาวร
- รองรับ: Google Messages (เวอร์ชัน
20260225.00ขึ้นไป) - ไม่รองรับ: Google Messages เวอร์ชันก่อน
20260225.00, iOS และ Samsung Messages
คำแนะนำในการแจ้งเตือนของระบบ
เมื่อผู้ใช้ได้รับข้อความ Google Messages จะแสดงคำแนะนำแรกที่มีสิทธิ์ในระบบการแจ้งเตือนของ Android โดยตรง ผู้ใช้สามารถแตะคำแนะนำนี้เพื่อส่งการตอบกลับหรือเรียกใช้การดำเนินการโดยไม่ต้องเปิดแอป
โปรดคำนึงถึงลักษณะการทำงานต่อไปนี้เมื่อออกแบบข้อความ
- ลำดับมีความสำคัญ: ระบบจะแสดงคำแนะนำเพียงรายการเดียวต่อการแจ้งเตือน หากต้องการเพิ่มการมีส่วนร่วมให้ได้มากที่สุด ให้วางการตอบกลับที่แนะนำหรือการดำเนินการที่แนะนำซึ่งมีลำดับความสำคัญสูงสุดไว้เป็นอันดับแรกในรายการคำแนะนำ
- การดำเนินการที่ยกเว้น: การดำเนินการแชร์ตำแหน่งจะไม่แสดงในการแจ้งเตือนของระบบ ผู้ใช้ต้องเปิดการสนทนาเพื่อแชร์ตำแหน่งของตน
กดหมายเลขโทรศัพท์
การดำเนินการโทรจะแนะนำให้ผู้ใช้โทรไปยังหมายเลขโทรศัพท์ที่ตัวแทนระบุไว้
หมายเลขโทรศัพท์ต้องมีเฉพาะตัวเลข (0-9) เครื่องหมายบวก (+) เครื่องหมายดอกจัน (*) และเครื่องหมายสี่เหลี่ยม (#) เท่านั้น ระบบรองรับรูปแบบระหว่างประเทศ E.164 (เช่น +14155555555) แต่ไม่จำเป็นต้องใช้ ซึ่งหมายความว่าทั้ง +14155555555 และ 1011 เป็นรายการที่ถูกต้อง
ตัวอย่าง
โค้ดต่อไปนี้จะส่งการดำเนินการโทรออก ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ DialAction
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d '{ "contentMessage": { "text": "Hello, world!", "suggestions": [ { "action": { "text": "Call", "postbackData": "postback_data_1234", "fallbackUrl": "https://www.google.com/contact/", "dialAction": { "phoneNumber": "+15556667777" } } } ] } }'
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a dial suggested action let suggestions = [ { action: { text: 'Call', postbackData: 'postback_data_1234', dialAction: { phoneNumber: '+15556667777' } } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a dial suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.DialAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a dial suggested action DialAction dialAction = new DialAction(); dialAction.setPhoneNumber("+15556667777"); // creating a suggested action based on a dial action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Call"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setDialAction(dialAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a dial suggested action suggestions = [ messages.DialAction('Call', 'reply:postback_data_1234', '+15556667777') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a dial an agent suggested action DialAction dialAction = new DialAction { PhoneNumber = "+15556667777" }; // Creating a suggested action based on a dial action SuggestedAction suggestedAction = new SuggestedAction { Text = "Call", PostbackData = "postback_data_1234", DialAction = dialAction }; // Attach action to a suggestion Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
ดูสถานที่ตั้ง
การดำเนินการดูตำแหน่งจะแสดงตำแหน่งในแอปแผนที่เริ่มต้นของผู้ใช้ คุณสามารถระบุตำแหน่งด้วยละติจูดและลองจิจูด หรือด้วยคำค้นหาที่อิงตามตำแหน่งปัจจุบันของผู้ใช้ นอกจากนี้ คุณยังตั้งค่าป้ายกำกับที่กำหนดเองสำหรับหมุดที่แสดงในแอปแผนที่ได้ด้วย
ตัวอย่าง
โค้ดต่อไปนี้จะส่งการดำเนินการดูตำแหน่ง ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ ViewLocationAction
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d '{ "contentMessage": { "text": "Hello, world!", "suggestions": [ { "action": { "text": "View map", "postbackData": "postback_data_1234", "fallbackUrl": "https://www.google.com/maps/@37.4220188,-122.0844786,15z", "viewLocationAction": { "latLong": { "latitude": "37.4220188", "longitude": "-122.0844786" }, "label": "Googleplex" } } } ] } }'
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a view location suggested action let suggestions = [ { action: { text: 'View map', postbackData: 'postback_data_1234', viewLocationAction: { latLong: { latitude: 37.4220188, longitude: -122.0844786 }, label: 'Googleplex' } } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a view location suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.ViewLocationAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a view location suggested action ViewLocationAction viewLocationAction = new ViewLocationAction(); viewLocationAction.setQuery("Googleplex, Mountain View, CA"); // creating a suggested action based on a view location action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("View map"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setViewLocationAction(viewLocationAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a view location suggested action suggestions = [ messages.ViewLocationAction('View map', 'reply:postback_data_1234', query='Googleplex, Mountain View, CA') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // create an view location action ViewLocationAction viewLocationAction = new ViewLocationAction { Query = "Googleplex Mountain View, CA" }; // Attach the view location action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { ViewLocationAction = viewLocationAction, Text = "View map", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
แชร์ตำแหน่ง
การดำเนินการแชร์ตำแหน่งช่วยให้ผู้ใช้แชร์ตำแหน่งกับ Agent ของคุณได้ ผู้ใช้สามารถแชร์ตำแหน่งปัจจุบันหรือตำแหน่งที่เลือกด้วยตนเองจากแอป Maps ได้
ตัวอย่าง
โค้ดต่อไปนี้จะส่งการดำเนินการแชร์ตำแหน่ง ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ 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 );
เปิด URL
การดำเนินการ Open URL ช่วยให้คุณนำผู้ใช้ไปยังหน้าเว็บที่ตัวแทนระบุได้ โดยค่าเริ่มต้น หน้าเว็บจะเปิดในเบราว์เซอร์ของผู้ใช้ นอกจากนี้ คุณยังตั้งค่าหน้าเว็บให้เปิดใน WebView ได้ด้วย ดูรายละเอียดได้ที่เปิด URL ด้วย WebView
เฉพาะใน Google Messages
การแสดง URL พื้นฐาน: เพื่อเพิ่มความโปร่งใสในการรับส่งข้อความ A2P Google Messages จะแสดงที่อยู่ URL พื้นฐานภายในการดำเนินการที่แนะนำ "เปิด URL" การเปลี่ยนแปลงนี้ส่งผลต่อการดำเนินการที่แนะนำใน Rich Card และภาพสไลด์ของ Rich Card มาตรฐาน
การแสดงไอคอนแอปสำหรับเว็บลิงก์: หากผู้ใช้กำหนดค่าแอปเริ่มต้นสำหรับหน้าเว็บไว้ แอปนั้นจะเปิดขึ้นแทนเบราว์เซอร์หรือ WebView และปุ่มคำแนะนำจะแสดงไอคอนของแอป หากต้องการให้ไอคอนแอปปรากฏใน Google Messages คุณต้องระบุ 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); });
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 );
เปิด URL ด้วย WebView
การดำเนินการเปิด URL ด้วย WebView จะโหลดหน้าเว็บที่ระบุภายในแอปรับส่งข้อความด้วยเครื่องมือแสดงผลของเบราว์เซอร์เริ่มต้น ซึ่งช่วยให้ผู้ใช้โต้ตอบกับหน้าเว็บได้โดยไม่ต้องออกจากการสนทนา RCS for Business หากอุปกรณ์ของผู้ใช้ไม่รองรับ WebView หน้าเว็บจะเปิดในเบราว์เซอร์ของผู้ใช้แทน หากต้องการเปิดใช้ WebView โปรดดู OpenURLApplication
WebView มีโหมดการแสดงผล 3 โหมด ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ WebviewViewMode
- เต็มหน้าจอ: หน้าเว็บแสดงเต็มหน้าจอ
- ครึ่งหน้าจอ: หน้าเว็บจะแสดงครึ่งหน้าจอ
- สูง: หน้าเว็บใช้พื้นที่ 3 ใน 4 ของหน้าจอ
ตัวอย่าง
โค้ดต่อไปนี้จะส่งการดำเนินการเปิด URL ด้วย WebView ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ OpenURLAction
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d '{ "contentMessage": { "text": "Hello, world!", "suggestions": [ { "action": { "text": "Open Google", "postbackData": "postback_data_1234", "openUrlAction": { "url": "https://www.google.com", "application": "WEBVIEW", "webviewViewMode": "FULL", "description": "Accessibility description" } } } ] } }'
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.OpenUrlAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { String URL = "https://www.google.com"; // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // Create suggestion to view webpage in full mode Suggestion viewInFullMode = getUrlActionInWebview(URL, "FULL") suggestions.add(viewInFullMode); // create suggestion to view webpage in half mode Suggestion viewInHalfMode = getUrlActionInWebview(URL, "HALF") suggestions.add(viewInHalfMode); // create suggestion to view webpage in tall mode Suggestion viewInTallMode = getUrlActionInWebview(URL, "TALL") suggestions.add(viewInTallMode); // Send simple text message with the suggested action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); } /** * Creates a suggested action to open URL in webview. * * @return a suggestion object for an open URL in webview action . */ private Suggestion getUrlActionInWebview(String url, String viewMode) { // create an open url action OpenUrlAction openUrlAction = new OpenUrlAction(); openUrlAction.setUrl(url); openUrlAction.setApplication("WEBVIEW"); openUrlAction.setWebviewViewMode(viewMode); openUrlAction.setDescription("Accessibility description"); // attach the open url action to a suggested action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setOpenUrlAction(openUrlAction); suggestedAction.setText('display_text'); suggestedAction.setPostbackData('postback_data_123'); // attach the action to a suggestion object Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); return suggestion; }
สร้างกิจกรรมในปฏิทิน
การดำเนินการสร้างกิจกรรมในปฏิทินจะเปิดแอปปฏิทินของผู้ใช้และเริ่มสร้างกิจกรรมใหม่ด้วยข้อมูลที่ระบุ
ต้องระบุชื่อกิจกรรมในปฏิทิน โดยมีความยาวสูงสุด 100 อักขระ คำอธิบายกิจกรรมในปฏิทินเป็นข้อมูลที่ไม่บังคับและมีอักขระได้สูงสุด 500 ตัว
ตัวอย่าง
โค้ดต่อไปนี้จะส่งการดำเนินการสร้างกิจกรรมในปฏิทิน ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ CreateCalendarEventAction
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d '{ "contentMessage": { "text": "Hello, world!", "suggestions": [ { "action": { "text": "Save to calendar", "postbackData": "postback_data_1234", "fallbackUrl": "https://www.google.com/calendar", "createCalendarEventAction": { "startTime": "2020-06-30T19:00:00Z", "endTime": "2020-06-30T20:00:00Z", "title": "My calendar event", "description": "Description of the calendar event" } } } ] } }'
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a create calendar event suggested action let suggestions = [ { action: { text: 'Save to calendar', postbackData: 'postback_data_1234', createCalendarEventAction: { startTime: '2020-06-30T19:00:00Z', endTime: '2020-06-30T20:00:00Z', title: 'My calendar event', description: 'Description of the calendar event', }, } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a create calendar event suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.CreateCalendarEventAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a create calendar event suggested action CreateCalendarEventAction createCalendarEventAction = new CreateCalendarEventAction(); calendarEventAction.setTitle("My calendar event"); calendarEventAction.setDescription("Description of the calendar event"); calendarEventAction.setStartTime("2020-06-30T19:00:00Z"); calendarEventAction.setEndTime("2020-06-30T20:00:00Z"); // creating a suggested action based on a create calendar event action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Save to calendar"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setCreateCalendarEventAction(createCalendarEventAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a calendar event suggested action suggestions = [ messages.CreateCalendarEventAction('Save to Calendar', 'reply:postback_data_1234', '2020-06-30T19:00:00Z', '2020-06-30T20:00:00Z', 'My calendar event', 'Description of the calendar event') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a calendar event action CreateCalendarEventAction calendarEventAction = new CreateCalendarEventAction { Title = "My calendar event", Description = "Description of the calendar event", StartTime = "2020-06-30T19:00:00Z", EndTime = "2020-06-30T20:00:00Z" }; // Attach the calendar event action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { CreateCalendarEventAction = calendarEventAction, Text = "Save to calendar", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
รายการชิปคำแนะนำ
ตัวแทนจะส่งรายการชิปคำแนะนำพร้อมข้อความเพื่อแนะนำการดำเนินการต่อๆ ไปของผู้ใช้ รายการชิปจะแสดงก็ต่อเมื่อข้อความที่เกี่ยวข้องอยู่ด้านล่างสุดของการสนทนาเท่านั้น ข้อความต่อๆ มาในการสนทนา (จากผู้ใช้หรือ Agent) จะเขียนทับรายการชิป
ชิปในรายการคือการตอบกลับที่แนะนำและการดำเนินการที่แนะนำ
รายการชิปมีชิปคำแนะนำได้สูงสุด 11 รายการ และป้ายกำกับชิปแต่ละรายการมีอักขระได้สูงสุด 25 ตัว
ดูตัวเลือกการจัดรูปแบบและค่าได้ที่ AgentContentMessage
การ์ดริชมีเดีย
Rich Card จะรวมสื่อ ข้อความ และคำแนะนำแบบอินเทอร์แอกทีฟไว้ในข้อความเดียว ซึ่งเหมาะสำหรับการนำเสนอข้อมูลที่เกี่ยวข้อง (เช่น ผลิตภัณฑ์ที่มีรูปภาพ ชื่อ และราคา) และแนะนำผู้ใช้ด้วยขั้นตอนถัดไปที่ชัดเจน เช่น คำแนะนำ "ดูรายละเอียด"
Rich Card อาจมีข้อมูลต่อไปนี้
- สื่อ (รูปภาพ, GIF หรือวิดีโอ)
- ข้อความชื่อ
- ข้อความคำอธิบาย
- การตอบกลับที่แนะนำและการดำเนินการที่แนะนำ (สูงสุด 4 รายการ)
แต่ละช่องเหล่านี้ไม่บังคับ แต่ต้องรวมช่อง 1-3 อย่างน้อย 1 ช่องไว้ใน Rich Card
คุณสามารถส่งการ์ดหลายใบพร้อมกันในภาพสไลด์ที่เลื่อนในแนวนอนได้
โปรดทราบว่าเพย์โหลดทั้งหมดสำหรับ Rich Card คือ 250 KB
ดูรายละเอียดทางเทคนิคทั้งหมดได้ในเอกสารประกอบของ Rich Card
ความสูงของการ์ด
Rich Card จะขยายในแนวตั้งเพื่อให้พอดีกับเนื้อหา โดยมีความสูงขั้นต่ำ 112 DP และความสูงสูงสุด 344 DP หากเนื้อหาการ์ดมีขนาดไม่ใหญ่พอที่จะเติมความสูงขั้นต่ำของการ์ด การ์ดจะขยายและเติมความสูงที่เหลือด้วยช่องว่าง
สื่อในการ์ด Rich Card ต้องมีความสูงอย่างใดอย่างหนึ่งใน 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); });
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");
ภาพสไลด์ Rich Card
ภาพสไลด์จะเชื่อมโยง Rich Card หลายรายการเข้าด้วยกัน ซึ่งช่วยให้ผู้ใช้เปรียบเทียบรายการและโต้ตอบกับแต่ละรายการได้
ภาพสไลด์มี Rich Card ได้อย่างน้อย 2 รายการและสูงสุด 10 รายการ Rich Card ภายในภาพสไลด์ต้องเป็นไปตามข้อกำหนดทั่วไปของ Rich Card สำหรับเนื้อหาและความสูงตามที่อธิบายไว้ในเอกสารประกอบของ Rich Card ดูข้อมูลเพิ่มเติมเกี่ยวกับเลย์เอาต์และข้อกำหนดของภาพสไลด์ได้ที่เอกสารประกอบเกี่ยวกับภาพสไลด์
ตัวอย่าง
โค้ดต่อไปนี้จะส่งภาพสไลด์ 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/welcome-bot-sample-images/200.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/welcome-bot-sample-images/201.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/welcome-bot-sample-images/200.jpg'; let card2Image = 'https://storage.googleapis.com/welcome-bot-sample-images/201.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/welcome-bot-sample-images/200.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/welcome-bot-sample-images/201.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/welcome-bot-sample-images/200.jpg'; card_image_2 = 'https://storage.googleapis.com/welcome-bot-sample-images/201.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/welcome-bot-sample-images/200.jpg"; string card2Image = "https://storage.googleapis.com/welcome-bot-sample-images/201.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);