事件是代理可以发送和接收的通知。有三个 事件类型:
服务器生成的事件
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] }
我们无法保证消息会送达。
- 如果邮件已递送,您会收到
DELIVERED
事件, webhook。 - 如果消息未送达,请使用撤消 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 平台传递了他们的消息,代理 处理。
以下代码会针对包含匹配事件的消息发送 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 秒)或用户的设备收到来自 Google 的
您的代理。您的代理可以发送多个 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");