Button list

The ButtonList widget displays a set of buttons. Buttons can display text, an icon, or both text and an icon.

Each Button supports an OnClick action that occurs when users click the button. For example:

  • Open a hyperlink with OpenLink, such as a hyperlink to the Google Chat developer documentation, https://developers.google.com/chat.
  • Run an action that runs a custom function, like calling an API.

You can prevent users from clicking a button by setting "disabled": "true".

For accessibility, buttons support alternative text.

Examples

The following image displays a card consisting of a ButtonList widget consisting of two Buttons. One button opens the Google Chat developer documentation in a new tab. The other button runs a custom function called goToView() and passes one parameter: viewType="Bird Eye View".

A card message in Google Chat depicting a Text Paragraph widget.
Figure 1: A card message in Google Chat depicting an ButtonList widget displaying two Buttons.

Here's the card's JSON:

JSON

{
  "cardsV2": [
    {
      "cardId": "exampleCard",
      "card": {
        "sections": [
          {
            "widgets": [
              {
                "buttonList": {
                  "buttons": [
                    {
                      "text": "Open a hyperlink",
                      "onClick": {
                        "openLink": {
                          "url": "https://developers.google.com/chat",
                        }
                      }
                    },
                    {
                      "text": "Run a custom function",
                      "onClick": {
                        "action": {
                          "function": "goToView",
                          "parameters": [
                            {
                              "key": "viewType",
                              "value": "BIRD EYE VIEW",
                            }
                          ],
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        ]
      }
    }
  ]
}

Example 2: a button with custom color and a deactivated button

The following image displays a card consisting of a ButtonList widget consisting of two Buttons. One button uses the Color field to customize the button's background color. The other button is deactivated with the Disabled field, which prevents the user from clicking the button and executing the function.

A card message in Google Chat depicting a ButtonList widget.
Figure 2: A card message in Google Chat depicting an ButtonList widget displaying two Buttons.

Here's the card's JSON:

JSON

{
 "cards_v2":[
    {
       "card_id":"exampleCard",
       "card":{
          "sections":[
             {
                "widgets":[
                   {
                      "buttonList":{
                         "buttons":[
                            {
                               "text":"View documentation hyperlink",
                               "onClick":{
                                  "openLink":{
                                     "url":"https://developers.google.com/chat"
                                  }
                               },
                               "color":{
                                  "red":0,
                                  "green":0,
                                  "blue":1,
                                  "alpha":0.5
                               }
                            },
                            {
                               "text":"Button disabled",
                               "onClick":{
                                  "openLink":{
                                     "url":"https://developers.google.com/chat"
                                  }
                               },
                               "disabled":true
                            }
                         ]
                      }
                   }
                ]
             }
          ]
       }
    }
 ]
}

Example 3: buttons that display icons

The following image displays a card consisting of a ButtonList widget with two icon Buttons. One button uses the [knownIcon]((https://developers.google.com/chat/api/guides/message-formats/cards#builtinicons)) field to display Google Chat's built-in email icon. The other button uses the iconUrl field to display a custom widget icon.

A card message in Google Chat depicting a ButtonList widget.
Figure 3: A card message in Google Chat depicting an ButtonList widget displaying two icon Buttons.

Here's the card's JSON:

JSON

{
"cards_v2": [
  {
  "card_id": "exampleCard",
  "card": {
    "sections": [
    {
      "widgets": [
      {
        "buttonList": {
          "buttons": [
                          {
              "icon": {"knownIcon": "EMAIL",},
              "onClick": {
                "action": {
                  "function": "sendEmail",
                  "parameters": [
                    {
                      "key": "emailContent",
                      "value": "Email value",
                    }
                  ],
                }
              }
            },
            {
              "icon": {"iconUrl": "https://developers.google.com/chat/images/quickstart-app-avatar.png",},
              "onClick": {
                "action": {
                  "function": "inviteBot",
                  "parameters": [
                    {
                      "key": "botType",
                      "value": "Bot value",
                    }
                  ],
                }
              }
            },
          ]
        }
      }
    ]
    }
    ]
  }
  }
]
}

Example 4: buttons with an icon and text

The following image displays a card consisting of a ButtonList widget that prompts the user to send an email. The first button displays an email icon and the second button displays text. The user can click on either the icon or text button to execute the sendEmail function.

A card message in Google Chat depicting a ButtonList widget.
Figure 1: A card message in Google Chat depicting an ButtonList widget displaying two Buttons.

Here's the card's JSON:

JSON

{
"cards_v2": [
  {
  "card_id": "exampleCard",
  "card": {
    "sections": [
    {
      "widgets": [
      {
        "buttonList": {
          "buttons": [
                          {
              "icon": {"knownIcon": "EMAIL",},
              "onClick": {
                "action": {
                  "function": "sendEmail",
                  "parameters": [
                    {
                      "key": "emailContent",
                      "value": "Email value",
                    }
                  ],
                }
              }
            },
            {
              "text": "Send email",
              "onClick": {
                "action": {
                  "function": "sendEmail",
                  "parameters": [
                    {
                      "key": "sendEmailType",
                      "value": "email value",
                    }
                  ],
                }
              }
            },
          ]
        }
      }
    ]
    }
    ]
  }
  }
]
}

JSON representation and fields

JSON representation
{
  "buttons": [
    {
      object (Button)
    }
  ]
}
Fields
buttons[]

object (Button)

An array of buttons.

Button

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

Icon

An icon displayed in a widget on a card.

Supports built-in 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, 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.

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.

Color

JSON representation
{
  "red": number,
  "green": number,
  "blue": number,
  "alpha": number
}
Fields
red

number

The amount of red in the color as a value in the interval [0, 1].

green

number

The amount of green in the color as a value in the interval [0, 1].

blue

number

The amount of blue in the color as a value in the interval [0, 1].

alpha

number

The fraction of this color that should be applied to the pixel. That is, the final pixel color is defined by the equation:

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

This means that a value of 1.0 corresponds to a solid color, whereas a value of 0.0 corresponds to a completely transparent color. This uses a wrapper message rather than a simple float scalar so that it is possible to distinguish between a default value and the value being unset. If omitted, this color object is rendered as a solid color (as if the alpha value had been explicitly given a value of 1.0).

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.