Interaction between Hangouts Chat and bots take place using messages in the context of particular spaces. For example, a bot may send some simple text (a type of message) into a specific chat room (a type of space).
Messages between Hangouts Chat and a bot implementation follow a defined message format, where each message consists of a JSON object whose components specify the user ID, style, content, and other aspects of the message.
There are several kinds of messages used in the interaction of bots with Hangouts Chat.
Messages from Hangouts Chat to a bot are known as events, and can be of several different types.
Messages from a bot to Hangouts Chat can have either or both of two kinds of content:
- Simple text contains plain text content with limited text formatting.
- Cards define the format, content, and behavior of cards to be displayed in the target space.
A space in Hangouts Chat is a generalization of chat rooms and direct messages. While each type of space has specific properties (for example, a chat room is visible to multiple users, while a direct message is not) the general concept of a space is often used.
For example, a bot can send a message to a space, regardless of what kind of space it is. However, there can be constraints on that message that affect how it is handled, depending on the target space's specific type.
In addition to simple text replies, bots can also display more complex UIs in the form of cards.
In this example, a project management bot replies to a query by building a list of data, wrapping it with header information into a card data structure, and returning it to the chat. Hangouts Chat then parses the data and displays the card.