Decorated text

The DecoratedText widget displays text with optional layout and functionality features. For example:

  • Display an icon in front of the text with startIcon.
  • Show a title before the text with topLabel.
  • Add a clickable button with button or switchable toggle with switchControl.


Design and preview cards with the Card Builder.

Open the Card Builder

Use the DecoratedText widget when you need to present information in an easy-to-consume and interactive way. The widget is perfect for contact cards, order status updates, and work ticket notifications.

The following is a card consisting of a DecoratedText widget used to display contact details, such as email address, online status, phone number, and website:

Format text in a DecoratedText widget

The DecoratedText widget supports simple text HTML formatting. When setting the text content of these widgets, just include the corresponding HTML tags. For more information about which HTML tags are supported, see Card text formatting.

JSON representation and fields

JSON representation
{
  "icon": {
    object (Icon)
  },
  "startIcon": {
    object (Icon)
  },
  "topLabel": string,
  "text": string,
  "wrapText": boolean,
  "bottomLabel": string,
  "onClick": {
    object (OnClick)
  },

  // Union field control can be only one of the following:
  "button": {
    object (Button)
  },
  "switchControl": {
    object (SwitchControl)
  },
  "endIcon": {
    object (Icon)
  }
  // End of list of possible types for union field control.
}
Fields
icon
(deprecated)

object (Icon)

Deprecated in favor of startIcon.

startIcon

object (Icon)

The icon displayed in front of the text.

topLabel

string

The text that appears above text. Always truncates.

text

string

Required. The primary text.

Supports simple formatting. For more information about formatting text, see Formatting text in Google Chat apps and Formatting text in Google Workspace Add-ons.

wrapText

boolean

The wrap text setting. If true, the text wraps and displays on multiple lines. Otherwise, the text is truncated.

Only applies to text, not topLabel and bottomLabel.

bottomLabel

string

The text that appears below text. Always wraps.

onClick

object (OnClick)

This action is triggered when users click topLabel or bottomLabel.

Union field control. A button, switch, checkbox, or image that appears to the right-hand side of text in the decoratedText widget. control can be only one of the following:
button

object (Button)

A button that a user can click to trigger an action.

switchControl

object (SwitchControl)

A switch widget that a user can click to change its state and trigger an action.

endIcon

object (Icon)

An icon displayed after the text.

Supports built-in and custom icons.

Icon

An icon displayed in a widget on a card. For an example in Google Chat apps, see Icon.

Supports built-in and custom icons.

Available for Google Chat apps and Google Workspace Add-ons.

JSON representation
{
  "altText": string,
  "imageType": enum (ImageType),

  // Union field icons can be only one of the following:
  "knownIcon": string,
  "iconUrl": string
  // End of list of possible types for union field icons.
}
Fields
altText

string

Optional. A description of the icon used for accessibility. If unspecified, the default value Button is provided. As a best practice, you should set a helpful description for what the icon displays, and if applicable, what it does. For example, A user's account portrait, or Opens a new browser tab and navigates to the Google Chat developer documentation at https://developers.google.com/chat.

If the icon is set in a Button, the altText appears as helper text when the user hovers over the button. However, if the button also sets text, the icon's altText is ignored.

imageType

enum (ImageType)

The crop style applied to the image. In some cases, applying a CIRCLE crop causes the image to be drawn larger than a built-in icon.

Union field icons. The icon displayed in the widget on the card. icons can be only one of the following:
knownIcon

string

Display one of the built-in icons provided by Google Workspace.

For example, to display an airplane icon, specify AIRPLANE. For a bus, specify BUS.

For a full list of supported icons, see built-in icons.

iconUrl

string

Display a custom icon hosted at an HTTPS URL.

For example:

"iconUrl":
"https://developers.google.com/chat/images/quickstart-app-avatar.png"

Supported file types include .png and .jpg.

ImageType

The shape used to crop the image.

Available for Google Chat apps and Google Workspace Add-ons.

Enums
SQUARE Default value. Applies a square mask to the image. For example, a 4x3 image becomes 3x3.
CIRCLE Applies a circular mask to the image. For example, a 4x3 image becomes a circle with a diameter of 3.

OnClick

Represents how to respond when users click an interactive element on a card, such as a button.

Available for Google Chat apps and Google Workspace Add-ons.

JSON representation
{

  // Union field data can be only one of the following:
  "action": {
    object (Action)
  },
  "openLink": {
    object (OpenLink)
  },
  "openDynamicLinkAction": {
    object (Action)
  },
  "card": {
    object (Card)
  }
  // End of list of possible types for union field data.
}
Fields

Union field data.

data can be only one of the following:

action

object (Action)

If specified, an action is triggered by this onClick.

card

object (Card)

A new card is pushed to the card stack after clicking if specified.

Available for Google Workspace Add-ons and unavailable for Google Chat apps.

Action

An action that describes the behavior when the form is submitted. For example, you can invoke an Apps Script script to handle the form. If the action is triggered, the form values are sent to the server.

Available for Google Chat apps and Google Workspace Add-ons.

JSON representation
{
  "function": string,
  "parameters": [
    {
      object (ActionParameter)
    }
  ],
  "loadIndicator": enum (LoadIndicator),
  "persistValues": boolean,
  "interaction": enum (Interaction)
}
Fields
function

string

A custom function to invoke when the containing element is clicked or othrwise activated.

For example usage, see Create interactive cards.

parameters[]

object (ActionParameter)

List of action parameters.

loadIndicator

enum (LoadIndicator)

Specifies the loading indicator that the action displays while making the call to the action.

persistValues

boolean

Indicates whether form values persist after the action. The default value is false.

If true, form values remain after the action is triggered. To let the user make changes while the action is being processed, set LoadIndicator to NONE. For card messages in Chat apps, you must also set the action's ResponseType to UPDATE_MESSAGE and use the same cardId from the card that contained the action.

If false, the form values are cleared when the action is triggered. To prevent the user from making changes while the action is being processed, set LoadIndicator to SPINNER.

interaction

enum (Interaction)

Optional. Required when opening a dialog.

What to do in response to an interaction with a user, such as a user clicking a button in a card message.

If unspecified, the app responds by executing an action —like opening a link or running a function—as normal.

By specifying an interaction, the app can respond in special interactive ways. For example, by setting interaction to OPEN_DIALOG, the app can open a dialog. When specified, a loading indicator isn't shown. If specified for an add-on, the entire card is stripped and nothing is shown in the client.

Available for Google Chat apps and unavailable for Google Workspace Add-ons.

Button

A text, icon, or text and icon button that users can click. For an example in Google Chat apps, see Button list.

To make an image a clickable button, specify an Image (not an ImageComponent) and set an onClick action.

Available for Google Chat apps and Google Workspace Add-ons.

JSON representation
{
  "text": string,
  "icon": {
    object (Icon)
  },
  "color": {
    object (Color)
  },
  "onClick": {
    object (OnClick)
  },
  "disabled": boolean,
  "altText": string
}
Fields
text

string

The text displayed inside the button.

icon

object (Icon)

The icon image. If both icon and text are set, then the icon appears before the text.

color

object (Color)

If set, the button is filled with a solid background color and the font color changes to maintain contrast with the background color. For example, setting a blue background likely results in white text.

If unset, the image background is white and the font color is blue.

For red, green, and blue, the value of each field is a float number that you can express in either of two ways: as a number between 0 and 255 divided by 255 (153/255), or as a value between 0 and 1 (0.6). 0 represents the absence of a color and 1 or 255/255 represent the full presence of that color on the RGB scale.

Optionally set alpha, which sets a level of transparency using this equation:

pixel color = alpha * (this color) + (1.0 - alpha) * (background color)

For alpha, a value of 1 corresponds with a solid color, and a value of 0 corresponds with a completely transparent color.

For example, the following color represents a half transparent red:

"color": {
   "red": 1,
   "green": 0,
   "blue": 0,
   "alpha": 0.5
}
onClick

object (OnClick)

Required. The action to perform when a user clicks the button, such as opening a hyperlink or running a custom function.

disabled

boolean

If true, the button is displayed in an inactive state and doesn't respond to user actions.

altText

string

The alternative text that's used for accessibility.

Set descriptive text that lets users know what the button does. For example, if a button opens a hyperlink, you might write: "Opens a new browser tab and navigates to the Google Chat developer documentation at https://developers.google.com/chat".

SwitchControl

Either a toggle-style switch or a checkbox inside a decoratedText widget.

Available for Google Chat apps and Google Workspace Add-ons.

Only supported in the decoratedText widget.

JSON representation
{
  "name": string,
  "value": string,
  "selected": boolean,
  "onChangeAction": {
    object (Action)
  },
  "controlType": enum (ControlType)
}
Fields
name

string

The name by which the switch widget is identified in a form input event.

For details about working with form inputs, see Receive form data.

value

string

The value entered by a user, returned as part of a form input event.

For details about working with form inputs, see Receive form data.

selected

boolean

When true, the switch is selected.

onChangeAction

object (Action)

The action to perform when the switch state is changed, such as what function to run.

controlType

enum (ControlType)

How the switch appears in the user interface.

Available for Google Chat apps and Google Workspace Add-ons.

Troubleshoot

When a Google Chat app or card returns an error, the Chat interface surfaces a message saying "Something went wrong." or "Unable to process your request." Sometimes the Chat UI doesn't display any error message, but the Chat app or card produces an unexpected result; for example, a card message might not appear.

Although an error message might not display in the Chat UI, descriptive error messages and log data are available to help you fix errors when error logging for Chat apps is turned on. For help viewing, debugging, and fixing errors, see Troubleshoot and fix Google Chat errors.