Research: Become a research participant and shape future Business Communications products and materials.

Send and receive events to enrich conversations

In Business Messages conversations, events inform and enrich the conversational experience of both users and agents by communicating non-message content. For users, events display as notifications within their conversations and trigger based on various actions users might make. Agents receive events at their webhooks and send events with API calls.

Agents should be aware of user-initiated events and be able to respond accordingly. For example, if a user requests a live agent, but the agent can't respond positively or negatively to the request, this results in a bad user experience.

Event types

Each event belongs to a particular type:

  • Live agent requested events indicate that the user wants to speak directly to a live agent.

    If the agent can transition the conversation to a human representative, send a Representative joined event, then send subsequent messages from a human representative.

    If the agent can't transition the conversation to a human representative, send a message to notify the user and inform them when a live agent will be available.

  • Representative joined/left events tell users when live agents join or leave a conversation. These events display notifications in the conversation and help set user expectations around responsiveness and the types of questions they can ask.

  • Typing events indicate that the user or agent is typing.

    For users, the boolean isTyping indicates their typing status. Each status change triggers a new event.

    Agents can send TYPING_STARTED and TYPING_STOPPED events to display typing indicators in the conversation. Typing events from agents tells users that a human representative is composing a response or that backend automation is processing their question or request.

  • Bot feedback response events represent feedback provided by users on the content of a message. Feedback buttons are only available on messages from BOT representatives.

    Bot feedback responses can have positive or negative ratings.

Send an event

To send an event, run the following command. Replace the following items:

  • CONVERSATION_ID with the identifier of the conversation you want to send the survey
  • EVENT_ID with a unique identifier for the event
  • PATH_TO_SERVICE_ACCOUNT_KEY with the path to your service account key on your machine
  • EVENT_TYPE with a value from EventType
  • REPRESENTATIVE_NAME with the user-facing name of the live agent or automation creating the event
  • REPRESENTATIVE_TYPE with a value from RepresentativeType
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/CONVERSATION_ID/events?eventId=EVENT_ID" \
-H "Content-Type: application/json" \
-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',
  },
}"

For formatting and value options, see conversations.events.

Example: Send a representative joined event

curl -X POST "https://businessmessages.googleapis.com/v1/conversations/12345/events?eventId=67890" \
-H "Content-Type: application/json" \
-H "`oauth2l header --json /path/to/service/account/key.json businessmessages`" \
-d "{
  'eventType': 'REPRESENTATIVE_JOINED',
  'representative': {
    'avatarImage': 'https://www.growingtreebank.com/representatives/janedoe.png',
    'displayName': 'Jane Doe',
    'representativeType': 'HUMAN',
  },
}"

Receive an event

When a user triggers an event on their device, your agent receives the event at its webhook. Receive and process events the same way you receive messages.

User-initiated events have the following format.

{
  "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",
  },
  "feedbackResponse": {
    "message": "MESSAGE_ID",
    "rating": "FEEDBACK_RATNG",
    "createTime": "CREATION_TIME",
  }

}

For formatting and value options, see UserMessage.

Example: Receive a bot feedback response

{
  "agent": "brands/12345/agents/67890",
  "requestId": "abcde",
  "conversationId": "conversations/fghij",
  "sendTime": "2021-10-02T15:01:23Z",
  "feedbackResponse": {
    "message": "conversations/fghij/messages/klimo",
    "rating": "POSITIVE",
    "createTime": "2021-10-02T15:01:23Z",
  }
}