เอเจนต์จะส่งเหตุการณ์สถานะไปยังอุปกรณ์ของผู้ใช้เพื่อจำลองการโต้ตอบของมนุษย์ สำหรับผู้ใช้ เหตุการณ์เหล่านี้จะแสดงเป็นใบตอบรับการอ่านหรือตัวบ่งชี้การพิมพ์ เพื่อให้มั่นใจว่าระบบกำลังประมวลผลข้อความ
ดูตัวเลือกการจัดรูปแบบและค่าทั้งหมดได้ในข้อมูลอ้างอิงของ phones.agentEvents
ดูรายละเอียดเกี่ยวกับเหตุการณ์ Webhook ที่ตัวแทนได้รับจากแพลตฟอร์ม RBM ได้ที่รับเหตุการณ์
ตัวแทนส่งเหตุการณ์ READ
สำหรับผู้ใช้ เหตุการณ์นี้จะปรากฏเป็นใบตอบรับการอ่านสำหรับข้อความที่เฉพาะเจาะจง ซึ่งจะแจ้งให้ผู้ใช้ทราบว่าแพลตฟอร์ม RBM ได้ส่งข้อความของผู้ใช้แล้วและตัวแทนกำลังประมวลผลข้อความ
โค้ดต่อไปนี้จะส่งเหตุการณ์ 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
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");