事件是服務專員可傳送及接收的通知。事件分為三種類型:
- 伺服器產生:由 RBM 平台傳送給您的代理程式
- User-generated:由使用者的裝置傳送至代理程式
- Agent-generated:由代理程式傳送給使用者
伺服器產生的事件
RBM 平台會傳送事件來通知代理程式,例如訊息到期時間。
如需格式設定和值選項,請參閱 ServerEvent
。
訊息已過期;撤銷成功
訊息已過期且已成功撤銷。這個事件可觸發備用訊息策略。
{ "phoneNumber": [phone number of recipient that the original message was intended for] , "messageId": [RCS message ID of the message], "agentId": [bot ID], "eventType": "TTL_EXPIRATION_REVOKED", "eventId": [unique ID generated by the RBM platform], "sendTime": [time at which the server sent this event] }
訊息已過期;撤銷失敗
訊息已過期,但並未撤銷。
{ "phoneNumber": [phone number of recipient that the original message was intended for] , "messageId": [RCS message ID of the message], "agentId": [bot ID], "eventType": "TTL_EXPIRATION_REVOKE_FAILED", "eventId": [unique ID generated by the RBM platform], "sendTime": [time at which the server sent this event] }
但不保證一定能傳送訊息。
- 如果訊息已送出,您會在 Webhook 收到
DELIVERED
事件。 - 如果系統未傳送訊息,請使用撤銷 API 傳送撤銷要求。
如果訊息具時效性 (例如動態密碼或詐欺警報),建議您透過替代管道 (例如簡訊) 傳送訊息,即使這樣會導致使用者重複傳送訊息。
使用者產生的事件
如同使用者訊息和功能檢查,代理程式會以 JSON 格式接收使用者事件。
如需格式設定和值選項,請參閱 UserEvent
。
使用者收到服務專員訊息
這個事件表示已收到訊息。
{ "senderPhoneNumber": "PHONE_NUMBER", "eventType": "DELIVERED", "eventId": "EVENT_ID", "messageId": "MESSAGE_ID", "agentId": "AGENT_ID" }
使用者讀取服務專員訊息
這個事件表示訊息已開啟或確認。
{ "senderPhoneNumber": "PHONE_NUMBER", "eventType": "READ", "eventId": "EVENT_ID", "messageId": "MESSAGE_ID", "agentId": "AGENT_ID" }
使用者開始輸入
這個事件表示使用者正在輸入內容。
{ "senderPhoneNumber": "PHONE_NUMBER", "eventType": "IS_TYPING", "eventId": "EVENT_ID",, "agentId": "AGENT_ID" }
使用者傳送簡訊
{ "senderPhoneNumber": "PHONE_NUMBER", "text": "Hi", "eventId": "EVENT_ID", "agentId": "AGENT_ID" }
使用者傳送檔案
{ "senderPhoneNumber": "PHONE_NUMBER", "userFile": { "payload": { "mimeType": "image/gif", "fileSizeBytes": 127806, "fileUri": "https://storage.googleapis.com/copper_test/77ddb795-24ad-4607-96ae-b08b4d86406a/d2dcc67ab888d34ee272899c020b13402856f81597228322079eb007e8c9", "fileName": "4_animated.gif" } }, "eventId": "EVENT_ID",, "agentId": "AGENT_ID" }
使用者輕觸建議的回覆
使用者輕觸建議回覆時,服務專員會收到含有回覆回傳資料和文字的事件。
{ "senderPhoneNumber": "PHONE_NUMBER", "eventId": "EVENT_ID", "agentId": "AGENT_ID", "suggestionResponse": { "postbackData": "postback_1234", "text": "Hello there!" } }
使用者輕觸建議的動作
使用者輕觸建議的動作時,您的代理程式會收到含有該動作回傳資料的事件。
{ "senderPhoneNumber": "PHONE_NUMBER", "eventId": "EVENT_ID", "agentId": "AGENT_ID", "suggestionResponse": { "postbackData": "postback_1234" } }
代理程式產生的事件
您的代理程式會傳送事件來模擬真人互動,並告知使用者您的代理程式正在與訊息互動。而對使用者而言,這類事件會在使用者對話中顯示為通知。
如需格式設定和值選項,請參閱 phones.agentEvents
。
服務專員傳送 READ
事件
對使用者而言,這個事件會顯示為特定訊息的讀取回條。這會讓使用者知道 RBM 平台已傳遞訊息,而代理程式正在處理訊息。
下列程式碼會針對包含相符 messageId
的訊息傳送 READ
事件。
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentEvents?eventId=EVENT_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('../libs/rbm_api_helper'); // Send the device an event to indicate that messageId has been read rbmApiHelper.sendReadMessage('+12223334444', messageId);這是 RBM 範例代理程式摘錄的內容。
Java
import com.google.rbm.samples.lib.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");這是 RBM 範例代理程式摘錄的內容。
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)這是 RBM 範例代理程式摘錄的內容。
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");這是 RBM 範例代理程式摘錄的內容。
服務專員傳送 IS_TYPING
事件
對使用者而言,這個事件會顯示為輸入指標,並告知服務專員正在撰寫訊息。輸入指標會在短時間 (約 20 秒) 後或使用者裝置收到來自代理程式的新訊息時到期。代理程式可傳送多個 IS_TYPING
事件,重設輸入指標的到期時間。
以下程式碼會傳送 IS_TYPING
事件。
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentEvents?eventId=EVENT_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('../libs/rbm_api_helper'); // Send the device an event to indicate that the agent is typing rbmApiHelper.sendIsTypingMessage('+12223334444', function() { console.log('Typing event sent!'); });這是 RBM 範例代理程式摘錄的內容。
Java
import com.google.rbm.samples.lib.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");這是 RBM 範例代理程式摘錄的內容。
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')這是 RBM 範例代理程式摘錄的內容。
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");這是 RBM 範例代理程式摘錄的內容。