[null,null,["最終更新日 2024-09-10 UTC。"],[[["\u003cp\u003eIn Business Messages, events provide context and enhance user and agent experiences by conveying non-message information, appearing as notifications for users and webhook data for agents.\u003c/p\u003e\n"],["\u003cp\u003eAgents need to understand and respond to user-initiated events like live agent requests to ensure a positive user experience.\u003c/p\u003e\n"],["\u003cp\u003eKey event types include live agent requests, representative joining/leaving, and typing indicators, each serving a specific purpose in the conversation flow.\u003c/p\u003e\n"],["\u003cp\u003eAgents can send events using API calls, providing details such as event type, representative information, and conversation ID.\u003c/p\u003e\n"],["\u003cp\u003eWhen a user triggers an event, the agent receives it at its webhook, allowing for real-time responses and actions based on user interactions.\u003c/p\u003e\n"]]],[],null,["# Send and receive events to enrich conversations\n\nIn Business Messages conversations, events inform and enrich the conversational\nexperience of both users and agents by communicating non-message content. For\nusers, events display as notifications within their conversations and trigger\nbased on various actions users might make. Agents receive events at their\nwebhooks and send events with API calls.\n\nAgents should be aware of user-initiated events and be able to respond\naccordingly. For example, if a user requests a live agent, but the agent can't\nrespond positively or negatively to the request, this results in a bad user\nexperience.\n\nEvent types\n-----------\n\nEach event belongs to a particular type:\n\n- **Live agent requested** events indicate that the user wants to speak\n directly to a live agent.\n\n If the agent can transition the conversation to a human representative, send\n a **Representative joined** event, then send subsequent messages from a\n human representative.\n\n If the agent can't transition the conversation to a human representative,\n send a message to notify the user and inform them when a live agent will be\n available.\n- **Representative joined/left** events tell users when live agents join or\n leave a conversation. These events display notifications in the conversation\n and help set user expectations around responsiveness and the types of\n questions they can ask.\n\n- **Typing** events indicate that the user or agent is typing.\n\n For users, the boolean `isTyping` indicates their typing status. Each status\n change triggers a new event.\n\n Agents can send `TYPING_STARTED` and `TYPING_STOPPED` events to display\n typing indicators in the conversation. Typing events from agents tells users\n that a human representative is composing a response or that backend\n automation is processing their question or request.\n\nSend an event\n-------------\n\nTo send an event, run the following command. Replace the following items:\n\n- \u003cvar translate=\"no\"\u003eCONVERSATION_ID\u003c/var\u003e with the identifier of the conversation you want to send the survey\n- \u003cvar translate=\"no\"\u003eEVENT_ID\u003c/var\u003e with a unique identifier for the event\n- \u003cvar translate=\"no\"\u003ePATH_TO_SERVICE_ACCOUNT_KEY\u003c/var\u003e with the path to your service account key on your machine\n- \u003cvar translate=\"no\"\u003eEVENT_TYPE\u003c/var\u003e with a value from [`EventType`](/business-communications/business-messages/reference/rest/v1/conversations.events#eventtype)\n- \u003cvar translate=\"no\"\u003eREPRESENTATIVE_NAME\u003c/var\u003e with the user-facing name of the live agent or automation creating the event\n- \u003cvar translate=\"no\"\u003eREPRESENTATIVE_TYPE\u003c/var\u003e with a value from [`RepresentativeType`](/business-communications/business-messages/reference/rest/v1/Representative#RepresentativeType)\n\n```scdoc\ncurl -X POST \"https://businessmessages.googleapis.com/v1/conversations/CONVERSATION_ID/events?eventId=EVENT_ID\" \\\n-H \"Content-Type: application/json\" \\\n-H \"User-Agent: curl/business-messages\" \\\n-H \"`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY businessmessages`\" \\\n-d \"{\n 'eventType': 'EVENT_TYPE',\n 'representative': {\n 'avatarImage': 'REPRESENTATIVE_AVATAR_URL',\n 'displayName': 'REPRESENTATIVE_NAME',\n 'representativeType': 'REPRESENTATIVE_TYPE',\n },\n}\"\n```\n\nFor formatting and value options, see\n[`conversations.events`](/business-communications/business-messages/reference/rest/v1/conversations.events).\n\n### Example: Send a representative joined event\n\n```carbon\n# Copyright 2021 Google LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n# https://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# This code sends a REPRESENTATIVE_JOINED event to the user.\n# Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/message/events#send\n\n# Replace the __CONVERSATION_ID__ with a conversation id that you can send messages to\n# Make sure a service account key file exists at ./service_account_key.json\n\ncurl -X POST \"https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/events?eventId=6a0af2c6-787d-4097-870d-93fe20351747\" \\\n-H \"Content-Type: application/json\" \\\n-H \"User-Agent: curl/business-messages\" \\\n-H \"$(oauth2l header --json ./service_account_key.json businessmessages)\" \\\n-d \"{\n 'eventType': 'REPRESENTATIVE_JOINED',\n 'representative': {\n 'avatarImage': 'https://developers.google.com/identity/images/g-logo.png',\n 'displayName': 'Chatbot',\n 'representativeType': 'HUMAN'\n }\n}\"https://github.com/google-business-communications/bm-snippets-curl/blob/a38eb862642061a7041d3d4f2cdaacc74eadc778/send-event-representative-joined.sh\n```\n\nReceive an event\n----------------\n\nWhen a user triggers an event on their device, your agent receives the event at\nits webhook. Receive and process events the same way you [receive\nmessages](/business-communications/business-messages/guides/how-to/message/receive).\n\nUser-initiated events have the following format.\n**Note:** Fields within `userStatus` only appear when users trigger corresponding events. \n\n```component-pascal\n{\n \"agent\": \"brands/\u003cvar translate=\"no\"\u003eBRAND_ID\u003c/var\u003e/agents/\u003cvar translate=\"no\"\u003eAGENT_ID\u003c/var\u003e\",\n \"requestId\": \"\u003cvar translate=\"no\"\u003eREQUEST_ID\u003c/var\u003e\",\n \"conversationId\": \"\u003cvar translate=\"no\"\u003eCONVERSATION_ID\u003c/var\u003e\",\n \"customAgentId\": \"\u003cvar translate=\"no\"\u003eCUSTOM_AGENT_ID\u003c/var\u003e\",\n \"sendTime\": \"\u003cvar translate=\"no\"\u003eSEND_TIME\u003c/var\u003e\",\n \"userStatus\": {\n \"isTyping\": \"\u003cvar translate=\"no\"\u003eBOOLEAN\u003c/var\u003e\",\n \"requestedLiveAgent\": \"\u003cvar translate=\"no\"\u003eBOOLEAN\u003c/var\u003e\",\n \"createTime\": \"\u003cvar translate=\"no\"\u003eCREATION_TIME\u003c/var\u003e\",\n }\n}\n```\n\nFor formatting and value options, see\n[`UserMessage`](/business-communications/business-messages/reference/rest/v1/UserMessage)."]]