在 Business Messages 对话中,事件通过传达非信息内容来传达并丰富用户与代理的对话体验。对于用户,事件在对话中显示为通知,并根据用户可能会执行的各种操作触发。代理在 webhook 中接收事件,并通过 API 调用发送事件。
代理应了解用户发起的事件,并能够相应地做出响应。例如,如果用户请求实时代理,但该代理无法对请求做出正面或负面响应,则会导致用户体验不佳。
事件类型
每个事件都属于特定类型的:
已请求人工客服事件表示用户希望直接与人工客服交流。
如果代理可以将对话转换为人工代表,请发送有代表性加入事件,然后发送人工代表发送的后续消息。
如果代理无法将对话转接到人工代表,请发送消息通知用户,并在在线客服可用时通知用户。
代表性加入/离开事件会告知人工客服何时加入或离开对话。这些事件会在对话中显示通知,并帮助用户建立对响应速度和可以询问的问题类型的期望。
输入事件表示用户或代理正在输入。
对于用户而言,布尔值
isTyping
表示用户的输入状态。每个状态变化都会触发一个新事件。代理可以发送
TYPING_STARTED
和TYPING_STOPPED
事件以在对话中显示输入指示符。输入代理中的事件会告知用户真人代表正在撰写回复,或者后端自动化正在处理其问题或请求。
发送事件
如需发送事件,请运行以下命令。请替换以下内容:
- 将 CONVERSATION_ID 替换为您要发送调查问卷的对话的标识符
- 将 EVENT_ID 替换为事件的唯一标识符
- 将 PATH_TO_SERVICE_ACCOUNT_KEY 替换为机器上的服务帐号密钥的路径
- 将 EVENT_TYPE 替换为
EventType
中的值 - 将 REPRESENTATIVE_NAME 替换为面向用户的直播代理或创建事件的自动化名称
- 将 REPRESENTATIVE_TYPE 替换为
RepresentativeType
中的值
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/CONVERSATION_ID/events?eventId=EVENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-messages" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY businessmessages`" \ -d "{ 'eventType': 'EVENT_TYPE', 'representative': { 'avatarImage': 'REPRESENTATIVE_AVATAR_URL', 'displayName': 'REPRESENTATIVE_NAME', 'representativeType': 'REPRESENTATIVE_TYPE', }, }"
如需了解格式设置和值选项,请参阅 conversations.events
。
示例:发送代表性加入的活动
# Copyright 2021 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # https://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This code sends a REPRESENTATIVE_JOINED event to the user. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/message/events#send # Replace the __CONVERSATION_ID__ with a conversation id that you can send messages to # Make sure a service account key file exists at ./service_account_key.json curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/events?eventId=6a0af2c6-787d-4097-870d-93fe20351747" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-messages" \ -H "$(oauth2l header --json ./service_account_key.json businessmessages)" \ -d "{ 'eventType': 'REPRESENTATIVE_JOINED', 'representative': { 'avatarImage': 'https://developers.google.com/identity/images/g-logo.png', 'displayName': 'Chatbot', 'representativeType': 'HUMAN' } }"
接收事件
当用户在其设备上触发事件时,您的代理会在其网络钩子上接收事件。像处理消息一样接收和处理事件。
用户发起的事件采用以下格式。
{ "agent": "brands/BRAND_ID/agents/AGENT_ID", "requestId": "REQUEST_ID", "conversationId": "CONVERSATION_ID", "customAgentId": "CUSTOM_AGENT_ID", "sendTime": "SEND_TIME", "userStatus": { "isTyping": "BOOLEAN", "requestedLiveAgent": "BOOLEAN", "createTime": "CREATION_TIME", } }
如需了解格式设置和值选项,请参阅 UserMessage
。