Image

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

The Image widget displays a .png or .jpg image hosted on an HTTPS URL. The displayed image's width fills the entire width of the displayed card, and its height adjusts to maintain the image's aspect ratio.

The Image widget supports onclick actions that occur when users click the image. Example onclick actions include:

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

Example: a clickable image

The following image displays a card consisting of an Image widget. It displays the Google Chat developer documentation landing page image. When users click the image, the Google Chat developer documentation opens in a new tab.

A card message in Google Chat depicting a Text Paragraph widget.
Figure 1: A card message in Google Chat depicting an Image widget.

Here's the card's JSON:

JSON

{
  "cards_v2": [
    {
    "card_id": "exampleCard",
    "card": {
      "sections": [
      {
        "widgets": [
        {
        "image": {
          "imageUrl": "https://developers.google.com/chat/images/chat-app-hero-image_1440.png",
          "onClick": {
            "openLink": {
              "url": "https://developers.google.com/chat",
            }
          },
          "altText": "The Google Chat developer documentation landing page image."
        }
        }
      ]
      }
      ]
    }
    }
  ]
  }

Image JSON representation and fields

JSON representation
{
  "imageUrl": string,
  "onClick": {
    object (OnClick)
  },
  "altText": string
}
Fields
imageUrl

string

The https URL that hosts the image.

For example:

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

object ( OnClick )

When a user clicks on the image, the click triggers this action.

altText

string

The alternative text of this image, used for accessibility.

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.

Limits and considerations

  • Only .png and .jpg images are supported.
  • The host URL must be HTTPS.
  • To ensure performant cards, maximum recommended image size is 2 MB.