ตัวแทนจะส่งเหตุการณ์สถานะไปยังอุปกรณ์ของผู้ใช้เพื่อจำลองการโต้ตอบของมนุษย์ สำหรับผู้ใช้ เหตุการณ์เหล่านี้จะแสดงเป็นใบตอบรับการอ่านหรือตัวบ่งชี้การพิมพ์ เพื่อให้มั่นใจว่าระบบกำลังประมวลผลข้อความ
ดูตัวเลือกการจัดรูปแบบและค่าทั้งหมดได้ในเอกสารอ้างอิง phones.agentEvents
ดูรายละเอียดเกี่ยวกับเหตุการณ์ Webhook ที่ตัวแทนได้รับจากแพลตฟอร์ม RBM, ดู รับเหตุการณ์
ตัวแทนส่งเหตุการณ์ READ
สำหรับผู้ใช้ เหตุการณ์นี้จะปรากฏเป็นใบตอบรับการอ่านสำหรับข้อความที่เฉพาะเจาะจง ซึ่งจะแจ้งให้ผู้ใช้ทราบว่าแพลตฟอร์ม RBM ได้ส่งข้อความแล้วและตัวแทนกำลังประมวลผลข้อความดังกล่าว
ระบบจะเก็บรักษาและจัดเก็บเหตุการณ์ READ ไว้เป็นเวลา 30 วัน หากผู้ใช้เปิดใช้ RCS แต่ไม่สามารถติดต่อได้ ระบบจะจัดคิวเหตุการณ์ หากผู้ใช้ไม่ได้เปิดใช้ RCS แพลตฟอร์ม RCS for Business จะแสดงข้อผิดพลาด NOT_FOUND (HTTP 404)
โค้ดต่อไปนี้จะส่งเหตุการณ์ READ สำหรับข้อความที่มี messageId ที่ตรงกัน
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentEvents?eventId=EVENT_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 "{ 'eventType': 'READ', 'messageId': 'MESSAGE_ID' }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Send the device an event to indicate that messageId has been read rbmApiHelper.sendReadMessage('+12223334444', messageId);
Java
import com.google.rbm.RbmApiHelper; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Send the device an event to indicate that messageId has been read rbmApiHelper.sendReadMessage(messageId, "+12223334444");
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service # Send the device an event to indicate that message_id was read rbm_service.send_read_event('+12223334444', message_id)
C#
using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Send the device an event to indicate that messageId has been read rbmApiHelper.SendReadMessage(messageId, "+12223334444");
ตัวแทนส่งเหตุการณ์ IS_TYPING
สำหรับผู้ใช้ เหตุการณ์นี้จะปรากฏเป็นตัวบ่งชี้การพิมพ์และแจ้งให้ผู้ใช้ทราบว่าตัวแทนกำลังเขียนข้อความ ตัวบ่งชี้การพิมพ์จะหมดอายุหลังจากผ่านไปครู่หนึ่ง (ประมาณ 20 วินาที) หรือเมื่ออุปกรณ์ของผู้ใช้ได้รับข้อความใหม่จากตัวแทน ตัวแทนสามารถส่งเหตุการณ์ IS_TYPING หลายรายการเพื่อรีเซ็ตตัวจับเวลาการหมดอายุของตัวบ่งชี้การพิมพ์
เหตุการณ์ IS_TYPING เป็นเหตุการณ์ชั่วคราวและไม่ได้จัดคิว
โค้ดต่อไปนี้จะส่งเหตุการณ์ IS_TYPING
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentEvents?eventId=EVENT_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 "{ 'eventType': 'IS_TYPING', }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Send the device an event to indicate that the agent is typing rbmApiHelper.sendIsTypingMessage('+12223334444', function() { console.log('Typing event sent!'); });
Java
import com.google.rbm.RbmApiHelper; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Send the device an event to indicate that the agent is typing rbmApiHelper.sendIsTypingMessage("+12223334444");
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service # Send the device an event to indicate that the agent is typing rbm_service.send_is_typing_event('+12223334444')
C#
using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Send the device an event to indicate that the agent is typing rbmApiHelper.SendIsTypingMessage(messageId, "+12223334444");