代理會將狀態事件傳送至使用者裝置,模擬真人互動。對使用者來說,這些事件會顯示為讀取回條或輸入指標,確保訊息正在處理中。
如需完整的格式和值選項,請參閱 phones.agentEvents 參考資料。
如要進一步瞭解代理從 RBM 平台收到的 Webhook 事件,請參閱「接收事件」。
代理傳送 READ 事件
對使用者來說,這個事件會顯示為特定訊息的讀取回條。這項功能可讓使用者知道 RBM 平台已傳送訊息,且代理正在處理。
READ 事件會保留並儲存 30 天。如果使用者已啟用 RCS,但無法連線,事件會排入佇列。如果未啟用 RCS,RCS for Business 平台會傳回 NOT_FOUND (HTTP 404) 錯誤。
下列程式碼會針對 messageId 相符的訊息傳送 READ 事件。
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 事件
對使用者來說,這項事件會顯示為輸入指標,讓他們知道服務專員正在撰寫訊息。輸入指標會在短時間後 (預設約 5 秒) 或使用者的裝置收到代理的新訊息時失效。代理可以傳送多個 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");