DecoratedText

Stay organized with collections Save and categorize content based on your preferences.

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.

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.

Example: contact card

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

A card message in Google Chat depicting a DecoratedText widget.
Figure 1: A card message in Google Chat depicting a `DecoratedText` widget.

Here's the card's JSON:

JSON

{
"cards_v2": [
  {
  "card_id": "exampleCard",
  "card": {
    "sections": [
    {
      "widgets": [
      {
      "decoratedText": {
      "startIcon": {
        "knownIcon": "EMAIL",
      },
      "text": "sasha@example.com",
      }
      },
      {
      "decoratedText": {
      "startIcon": {
        "knownIcon": "PERSON",
      },
      "text": "<font color=\"#80e27e\">Online</font>",
      },
      },
      {
      "decoratedText": {
      "startIcon": {
        "knownIcon": "PHONE",
      },
      "text": "+1 (555) 555-1234",
      }
      },
      {
      "decoratedText": {
      "startIcon": {
        "knownIcon": "STAR",
      },
      "text": "<a href=\"https://developers.google.com/chat\">
        Google Chat Developer Documentation</a>",
      }
      }
      ]
    }
    ]
  }
  }
]
}

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. The following formats are supported:

Format Example Rendered Result
Bold <b>test</b> test
Italics <i>test</i> test
Underline <u>test</u> test
Strikethrough <s>test</s> test
Font color <font color="#ea9999">test</font> test
Hyperlink <a href="https://www.google.com">google</a> google
Time <time>2020-02-16 15:00</time> 2020-02-16 15:00
Newline test <br> test test
test

DecoratedText 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.

Supports simple formatting. See Text formatting for formatting details.

text

string

Required. The primary text.

Supports simple formatting. See Text formatting for formatting details.

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 truncates.

Supports simple formatting. See Text formatting for formatting details.

onClick

object ( OnClick )

When users click on topLabel or bottomLabel , this action triggers.

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 can be clicked to trigger an action.

switchControl

object ( SwitchControl )

A switch widget can be clicked to change its state and trigger an action. Currently supported in dialogs . Support for card messages is coming soon.

endIcon

object ( Icon )

An icon displayed after the text.

Supports standard and custom icons.

Button JSON representation and fields

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 in place of the text.

Support for both an icon and text is coming soon.

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 will likely result 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 can be expressed 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 )

The action to perform when the button is clicked, 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 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" .

Has no effect when an icon is set; use icon.alt_text instead.

Icon

An icon displayed in a widget on a card.

Supports standard and custom icons.

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, a default value is provided. As a best practice, you should set a helpful description. For example, if an icon displays a user's account portrait, you could describe it as "A user's account portrait."

If the icon displays in a Button , this alt text takes precedence and overwrites the button's alt text, so you should write alt text for the button: 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" .

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 standard 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 standard 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 standard 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.

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.

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.

Supported by Google Workspace Add-ons, but not Chat apps.

Action

An action that describes the behavior when the form is submitted. For example, an Apps Script can be invoked to handle the form.

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. When using LoadIndicator.NONE for actions, persistValues = true is recommended, as it ensures that any changes made by the user after form or on change actions are sent to the server are not overwritten by the response.

If false , the form values are cleared when the action is triggered. When persistValues is set to false , it is strongly recommended that the card use LoadIndicator.SPINNER for all actions, as this locks the UI to ensure no changes are made by the user while the action is being processed.

Not supported by Chat apps.

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 button on 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 is not shown.

Supported by Chat apps, but not Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.

ActionParameter

List of string parameters to supply when the action method is invoked. For example, consider three snooze buttons: snooze now, snooze 1 day, snooze next week. You might use action method = snooze(), passing the snooze type and snooze time in the list of string parameters.

To learn more, see CommonEventObject .

JSON representation
{
  "key": string,
  "value": string
}
Fields
key

string

The name of the parameter for the action script.

value

string

The value of the parameter.

LoadIndicator

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

Enums
SPINNER Displays a spinner to indicate that content is loading.
NONE Nothing is displayed.

Interaction

Optional. Required when opening a dialog .

What to do in response to an interaction with a user, such as a user clicking button on 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 is not shown.

Supported by Chat apps, but not Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.

Enums
INTERACTION_UNSPECIFIED Default value. The action executes as normal.
OPEN_DIALOG

Opens a dialog , a windowed, card-based interface that Chat apps use to interact with users.

Only supported by Chat apps in response to button-clicks on card messages.

Not supported by Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.