Card
A card is a UI element that can contain UI widgets such as text and images. For more information, see Cards . For example, the following JSON creates a card that has a header with the name, position, icons, and link for a contact, followed by a section with contact information like email and phone number.
{
"header": {
"title": "Sasha",
"subtitle": "Software Engineer",
"imageStyle": "ImageStyle.AVATAR",
"imageUrl": "https://example.com/sasha.png",
"imageAltText": "Avatar for Sasha"
},
"sections" : [
{
"header": "Contact Info",
"widgets": [
{
"decoratedText": {
"icon": {
"knownIcon": "EMAIL"
},
"content": "sasha@example.com"
}
},
{
"decoratedText": {
"icon": {
"knownIcon": "PERSON"
},
"content": "<font color=\"#80e27e\">Online</font>"
}
},
{
"decoratedText": {
"icon": {
"knownIcon": "PHONE"
},
"content": "+1 (555) 555-1234"
}
},
{
"buttons": [
{
"textButton": {
"text": "Share",
},
"onClick": {
"openLink": {
"url": "https://example.com/share"
}
}
},
{
"textButton": {
"text": "Edit",
},
"onClick": {
"action": {
"function": "goToView",
"parameters": [
{
"key": "viewType",
"value": "EDIT"
}
],
"loadIndicator": "LoadIndicator.SPINNER"
}
}
}
]
}
],
"collapsible": true,
"uncollapsibleWidgetsCount": 3
}
],
"cardActions": [
{
"actionLabel": "Send Feedback",
"onClick": {
"openLink": {
"url": "https://example.com/feedback"
}
}
}
],
"name": "contact-card-K3wB6arF2H9L"
}
JSON representation |
---|
{ "header": { object ( |
Fields | |
---|---|
header
|
The header of the card. A header usually contains a title and an image. |
sections[]
|
Sections are separated by a line divider. |
cardActions[]
|
The card's actions. Actions are added to the card's generated toolbar menu. For example, the following JSON constructs a card action menu with Settings and Send Feedback options:
|
name
|
Name of the card. Used as a card identifier in card navigation. |
fixedFooter
|
The fixed footer shown at the bottom of this card. |
displayStyle
|
The |
peekCardHeader
|
When displaying contextual content, the peek card header acts as a placeholder so that the user can navigate forward between the homepage cards and the contextual cards. Not supported by Google Chat apps. |
CardHeader
Represents a card header.
JSON representation |
---|
{
"title": string,
"subtitle": string,
"imageType": enum (
|
Fields | |
---|---|
title
|
Required. The title of the card header. The header has a fixed height: if both a title and subtitle are specified, each takes up one line. If only the title is specified, it takes up both lines. |
subtitle
|
The subtitle of the card header. |
imageType
|
The image's type. |
imageUrl
|
The URL of the image in the card header. |
imageAltText
|
The alternative text of this image which is used for accessibility. |
ImageType
The image type determines the cropping of the image that it is applied to.
SQUARE
means that no cropping is applied,
CIRCLE
applies a circular mask to the image.
Enums | |
---|---|
SQUARE
|
Applies no cropping to the image. |
CIRCLE
|
Applies a circular mask to the image. |
Section
A section contains a collection of widgets that are rendered vertically in the order that they are specified. Across all platforms, cards have a narrow fixed width, so there is currently no need for layout properties, for example, float.
JSON representation |
---|
{
"header": string,
"widgets": [
{
object (
|
Fields | |
---|---|
header
|
The header of the section. Formatted text is supported. |
widgets[]
|
A section must contain at least 1 widget. |
collapsible
|
Indicates whether this section is collapsible. If a section is collapsible, the description must be given. |
uncollapsibleWidgetsCount
|
The number of uncollapsible widgets. For example, when a section contains five widgets and the
|
Widget
A widget is a UI element that presents texts, images, etc.
JSON representation |
---|
{ "horizontalAlignment": enum ( |
Fields | |
---|---|
horizontalAlignment
|
The horizontal alignment of this widget. |
Union field
data
. A widget can only have one of the following items. You can use multiple widget fields to display more items.
data
can be only one of the following:
|
|
textParagraph
|
Displays a text paragraph in this widget. For example, the following JSON creates a bolded text:
|
image
|
Displays an image in this widget. For example, the following JSON creates an image with alternative text:
|
decoratedText
|
Displays a decorated text item in this widget. For example, the following JSON creates a decorated text widget showing email address:
|
buttonList
|
A list of buttons. For example, the following JSON creates two buttons. The first is a filled text button and the second is an image button that opens a link:
|
textInput
|
Displays a text input in this widget. For example, the following JSON creates a text input for mail address:
As another example, the following JSON creates a text input for programming language with static suggestions:
|
selectionInput
|
Displays a switch control in this widget. For example, the following JSON creates a dropdown selection for size:
|
dateTimePicker
|
Displays a selection/input widget for date/time. For example, the following JSON creates a date/time picker for an appointment time:
|
divider
|
Displays a divider. For example, the following JSON creates a divider:
|
grid
|
Displays a grid with a collection of items. For example, the following JSON creates a 2 column grid with a single item:
|
TextParagraph
A paragraph of text that supports formatting. See Text formatting for details.
JSON representation |
---|
{ "text": string } |
Fields | |
---|---|
text
|
The text that's shown in the widget. |
Image
An image that is specified by a URL and can have an
onClick
action.
JSON representation |
---|
{
"imageUrl": string,
"onClick": {
object (
|
Fields | |
---|---|
imageUrl
|
An image URL. |
onClick
|
The action triggered by an
|
altText
|
The alternative text of this image, used for accessibility. |
OnClick
Represents the response to an
onClick
event.
JSON representation |
---|
{ // Union field |
Fields | |
---|---|
Union field
|
|
action
|
If specified, an action is triggered by this
|
openLink
|
If specified, this
|
openDynamicLinkAction
|
An add-on triggers this action when the action needs to open a link. This differs from the
|
card
|
A new card is pushed to the card stack after clicking if specified. |
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 ( |
Fields | |
---|---|
function
|
Apps Script function to invoke when the containing element is clicked/activated. |
parameters[]
|
List of action parameters. |
loadIndicator
|
Specifies the loading indicator that the action displays while making the call to the action. |
persistValues
|
Indicates whether form values persist after the action. The default value is
If
If
Not supported by Google Chat apps. |
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.
JSON representation |
---|
{ "key": string, "value": string } |
Fields | |
---|---|
key
|
The name of the parameter for the action script. |
value
|
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. |
OpenLink
Represents an
onClick
event that opens a hyperlink.
JSON representation |
---|
{ "url": string, "openAs": enum ( |
Fields | |
---|---|
url
|
The URL to open. |
openAs
|
How to open a link. Not supported by Chat apps. |
onClose
|
Whether the client forgets about a link after opening it, or observes it until the window closes. Not supported by Chat apps. |
OpenAs
When an OnClick opens a link, then the client can either open it as a full size window (if that is the frame used by the client), or an overlay (such as a pop-up). The implementation depends on the client platform capabilities, and the value selected might be ignored if the client doesn't support it.
FULL_SIZE
is supported by all clients. Not supported by Chat apps.
Enums | |
---|---|
FULL_SIZE
|
The link opens as a full size window (if that's the frame used by the client. |
OVERLAY
|
The link opens as an overlay, such as a pop-up. |
OnClose
When an OnClick opens a link, then the client either forgets about it or observes until the window closes. The implementation depends on the client platform capabilities.
OnClose might cause OpenAs to be ignored; if the client platform can't support both selected values together, OnClose takes precedence. Not supported by Chat apps.
Enums | |
---|---|
NOTHING
|
Doesn’t reload the card after the child window closes. |
RELOAD
|
Reloads the card after the child window closes. If used in conjunction with OpenAs.OVERLAY , the child window acts as a modal dialog and the main card is blocked until the child window closes. |
DecoratedText
A widget that displays text with optional decorations such as a label above or below the text, an icon in front of the text, a selection widget or a button after the text.
JSON representation |
---|
{ "icon": { object ( |
Fields | |
---|---|
icon
|
Deprecated in favor of startIcon. |
startIcon
|
The icon displayed in front of the text. |
topLabel
|
The formatted text label that shows above the main text. |
text
|
Required. The main widget formatted text. See Text formatting for details. |
wrapText
|
The wrap text setting. If
|
bottomLabel
|
The formatted text label that shows below the main text. |
onClick
|
Only the top and bottom label and content region are clickable. |
Union field
control
. A control widget or image that appears after the text. You can set a button, switch control, or image, but not more than one.
control
can be only one of the following:
|
|
button
|
A button that can be clicked to trigger an action. |
switchControl
|
A switch widget can be clicked to change its state or trigger an action. |
endIcon
|
An icon displayed after the text. |
Icon
JSON representation |
---|
{ "altText": string, "imageType": enum ( |
Fields | |
---|---|
altText
|
The description of the icon, used for accessibility. The default value is provided if you don't specify one. |
imageType
|
The crop style applied to the image. In some cases, applying a
|
Union field
icons
. The icon, can be specified by KnownIcon string or a URL.
icons
can be only one of the following:
|
|
knownIcon
|
The icon specified by the string name of a list of known icons. |
iconUrl
|
The icon specified by a URL. |
Button
A button. Can be a text button or an image button.
JSON representation |
---|
{ "text": string, "icon": { object ( |
Fields | |
---|---|
text
|
The text of the button. |
icon
|
The icon image. |
color
|
If set, the button is filled with a solid background. |
onClick
|
The action to perform when the button is clicked. |
disabled
|
If
|
altText
|
The alternative text used for accessibility. Has no effect when an icon is set; use
|
Color
Represents a color in the RGBA color space. This representation is designed for simplicity of conversion to/from color representations in various languages over compactness. For example, the fields of this representation can be trivially provided to the constructor of
java.awt.Color
in Java; it can also be trivially provided to UIColor's
+colorWithRed:green:blue:alpha
method in iOS; and, with just a little work, it can be easily formatted into a CSS
rgba()
string in JavaScript.
This reference page doesn't carry information about the absolute color space that should be used to interpret the RGB value (e.g. sRGB, Adobe RGB, DCI-P3, BT.2020, etc.). By default, applications should assume the sRGB color space.
When color equality needs to be decided, implementations, unless documented otherwise, treat two colors as equal if all their red, green, blue, and alpha values each differ by at most 1e-5.
Example (Java):
import com.google.type.Color;
// ...
public static java.awt.Color fromProto(Color protocolor) {
float alpha = protocolor.hasAlpha()
? protocolor.getAlpha().getValue()
: 1.0;
return new java.awt.Color(
protocolor.getRed(),
protocolor.getGreen(),
protocolor.getBlue(),
alpha);
}
public static Color toProto(java.awt.Color color) {
float red = (float) color.getRed();
float green = (float) color.getGreen();
float blue = (float) color.getBlue();
float denominator = 255.0;
Color.Builder resultBuilder =
Color
.newBuilder()
.setRed(red / denominator)
.setGreen(green / denominator)
.setBlue(blue / denominator);
int alpha = color.getAlpha();
if (alpha != 255) {
result.setAlpha(
FloatValue
.newBuilder()
.setValue(((float) alpha) / denominator)
.build());
}
return resultBuilder.build();
}
// ...
Example (iOS / Obj-C):
// ...
static UIColor* fromProto(Color* protocolor) {
float red = [protocolor red];
float green = [protocolor green];
float blue = [protocolor blue];
FloatValue* alpha_wrapper = [protocolor alpha];
float alpha = 1.0;
if (alpha_wrapper != nil) {
alpha = [alpha_wrapper value];
}
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
static Color* toProto(UIColor* color) {
CGFloat red, green, blue, alpha;
if (![color getRed:&red green:&green blue:&blue alpha:&alpha]) {
return nil;
}
Color* result = [[Color alloc] init];
[result setRed:red];
[result setGreen:green];
[result setBlue:blue];
if (alpha <= 0.9999) {
[result setAlpha:floatWrapperWithValue(alpha)];
}
[result autorelease];
return result;
}
// ...
Example (JavaScript):
// ...
var protoToCssColor = function(rgb_color) {
var redFrac = rgb_color.red || 0.0;
var greenFrac = rgb_color.green || 0.0;
var blueFrac = rgb_color.blue || 0.0;
var red = Math.floor(redFrac * 255);
var green = Math.floor(greenFrac * 255);
var blue = Math.floor(blueFrac * 255);
if (!('alpha' in rgb_color)) {
return rgbToCssColor(red, green, blue);
}
var alphaFrac = rgb_color.alpha.value || 0.0;
var rgbParams = [red, green, blue].join(',');
return ['rgba(', rgbParams, ',', alphaFrac, ')'].join('');
};
var rgbToCssColor = function(red, green, blue) {
var rgbNumber = new Number((red << 16) | (green << 8) | blue);
var hexString = rgbNumber.toString(16);
var missingZeros = 6 - hexString.length;
var resultBuilder = ['#'];
for (var i = 0; i < missingZeros; i++) {
resultBuilder.push('0');
}
resultBuilder.push(hexString);
return resultBuilder.join('');
};
// ...
JSON representation |
---|
{ "red": number, "green": number, "blue": number, "alpha": number } |
Fields | |
---|---|
red
|
The amount of red in the color as a value in the interval [0, 1]. |
green
|
The amount of green in the color as a value in the interval [0, 1]. |
blue
|
The amount of blue in the color as a value in the interval [0, 1]. |
alpha
|
The fraction of this color that should be applied to the pixel. That is, the final pixel color is defined by the equation:
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). |
SwitchControl
Either a toggle-style switch or a checkbox.
JSON representation |
---|
{ "name": string, "value": string, "selected": boolean, "onChangeAction": { object ( |
Fields | |
---|---|
name
|
The name of the switch widget that's used in
|
value
|
The value is what is passed back in the callback. |
selected
|
If the switch is selected. |
onChangeAction
|
The action when the switch state is changed. |
controlType
|
The control type, either switch or checkbox. |
ControlType
The switch type shown in client.
Enums | |
---|---|
SWITCH
|
A toggle-style switch. |
CHECKBOX
|
Deprecated in favor of
CHECK_BOX
.
|
CHECK_BOX
|
A checkbox. |
ButtonList
A list of buttons layed out horizontally.
JSON representation |
---|
{
"buttons": [
{
object (
|
Fields | |
---|---|
buttons[]
|
An array of buttons. |
TextInput
A text input is a UI item where users can input text. A text input can also have an onChange action and suggestions.
JSON representation |
---|
{ "name": string, "label": string, "hintText": string, "value": string, "type": enum ( |
Fields | |
---|---|
name
|
The name of the text input which is used in
|
label
|
At least one of label and hintText must be specified. |
hintText
|
The hint text. |
value
|
The default value when there is no input from the user. |
type
|
The style of the text, for example, a single line or multiple lines. |
onChangeAction
|
The onChange action, for example, invoke a function. |
initialSuggestions
|
The initial suggestions made before any user input. |
autoCompleteAction
|
The refresh function that returns suggestions based on the user's input text. If the callback is not specified, autocomplete is done in client side based on the initial suggestion items. |
Type
The style of the text, for example, a single line or multiple lines.
Enums | |
---|---|
SINGLE_LINE
|
The text is put into a single line. |
MULTIPLE_LINE
|
The text is put into multiple lines. |
Suggestions
A container wrapping elements necessary for showing suggestion items used in text input autocomplete.
JSON representation |
---|
{
"items": [
{
object (
|
Fields | |
---|---|
items[]
|
A list of suggestions used for autocomplete recommendations. |
SuggestionItem
A suggestion item.
JSON representation |
---|
{ "text": string } |
Fields | |
---|---|
text
|
The suggested autocomplete result. |
SelectionInput
A widget that creates a UI item with options for users to select. For example, a dropdown menu.
JSON representation |
---|
{ "name": string, "label": string, "type": enum ( |
Fields | |
---|---|
name
|
The name of the text input which is used in
|
label
|
The label displayed ahead of the switch control. |
type
|
The type of the selection. |
items[]
|
An array of the selected items. |
onChangeAction
|
If specified, the form is submitted when the selection changes. If not specified, you must specify a separate button. |
SelectionType
The type of the selection.
Enums | |
---|---|
CHECK_BOX
|
A checkbox. |
RADIO_BUTTON
|
A radio button. |
SWITCH
|
A switch. |
DROPDOWN
|
A dropdown menu. |
SelectionItem
A selectable item in the switch control.
JSON representation |
---|
{ "text": string, "value": string, "selected": boolean } |
Fields | |
---|---|
text
|
The text to be displayed. |
value
|
The value associated with this item. The client should use this as a form input value. |
selected
|
If more than one item is selected for
|
DateTimePicker
The widget that lets users to specify a date and time. Not supported by Google Chat apps.
JSON representation |
---|
{ "name": string, "label": string, "type": enum ( |
Fields | |
---|---|
name
|
The name of the text input that's used in
|
label
|
The label for the field that displays to the user. |
type
|
The type of the date/time picker. |
valueMsEpoch
|
The value to display as the default value before user input or previous user input. It is represented in milliseconds (Epoch time). For
|
timezoneOffsetDate
|
The number representing the time zone offset from UTC, in minutes. If set, the
|
onChangeAction
|
Triggered when the user clicks Save or Clear from the date/time picker dialog. This is only triggered if the value changed as a result of the Save/Clear operation. |
DateTimePickerType
The type of the date/time picker.
Enums | |
---|---|
DATE_AND_TIME
|
The user can select a date and time. |
DATE_ONLY
|
The user can only select a date. |
TIME_ONLY
|
The user can only select a time. |
Divider
A divider that appears in between widgets.
Grid
Represents a Grid widget that displays items in a configurable grid layout.
JSON representation |
---|
{ "title": string, "items": [ { object ( |
Fields | |
---|---|
title
|
The text that displays in the grid header. |
items[]
|
The items to display in the grid. |
borderStyle
|
The border style to apply to each grid item. |
columnCount
|
The number of columns to display in the grid. A default value is used if this field isn't specified, and that default value is different depending on where the grid is shown (dialog versus companion). |
onClick
|
This callback is reused by each individual grid item, but with the item's identifier and index in the items list added to the callback's parameters. |
GridItem
Represents a single item in the grid layout.
JSON representation |
---|
{ "id": string, "image": { object ( |
Fields | |
---|---|
id
|
A user-specified identifier for this grid item. This identifier is returned in the parent Grid's onClick callback parameters. |
image
|
The image that displays in the grid item. |
title
|
The grid item's title. |
subtitle
|
The grid item's subtitle. |
textAlignment
|
The horizontal alignment of the grid item's text. |
layout
|
The layout to use for the grid item. |
ImageComponent
Represents an image.
JSON representation |
---|
{ "imageUri": string, "altText": string, "cropStyle": { object ( |
Fields | |
---|---|
imageUri
|
The image URL. |
altText
|
The accessibility label for the image. |
cropStyle
|
The crop style to apply to the image. |
borderStyle
|
The border style to apply to the image. |
ImageCropStyle
Represents the crop style applied to an image.
JSON representation |
---|
{
"type": enum (
|
Fields | |
---|---|
type
|
The crop type. |
aspectRatio
|
The aspect ratio to use if the crop type is
|
ImageCropType
Represents the crop style applied to an image.
Enums | |
---|---|
IMAGE_CROP_TYPE_UNSPECIFIED
|
No value specified. |
SQUARE
|
Applies a square crop. |
CIRCLE
|
Applies a circular crop. |
RECTANGLE_CUSTOM
|
Applies a rectangular crop with a custom aspect ratio. |
RECTANGLE_4_3
|
Applies a rectangular crop with a 4:3 aspect ratio. |
BorderStyle
Represents the complete border style applied to widgets.
JSON representation |
---|
{ "type": enum ( |
Fields | |
---|---|
type
|
The border type. |
strokeColor
|
The colors to use when the type is
|
cornerRadius
|
The corner radius for the border. |
BorderType
Represents the border types applied to widgets.
Enums | |
---|---|
BORDER_TYPE_UNSPECIFIED
|
No value specified. |
NO_BORDER
|
No border. |
STROKE
|
Outline. |
HorizontalAlignment
The horizontal alignment determines the placement of the widget. By default, a widget is shown using alignment corresponding to the
START
value, where
START
corresponds to the left in left-to-right layouts, and the right in right-to-left layouts. The
END
value corresponds to the right in left-to-right layouts, and the left in right-to-left layouts.
Enums | |
---|---|
HORIZONTAL_ALIGNMENT_UNSPECIFIED
|
Unspecified alignment. |
START
|
Alignment to the start position. |
CENTER
|
Alignment to the center position. |
END
|
Alignment to the end position. |
GridItemLayout
Represents the various layout options available for a grid item.
Enums | |
---|---|
GRID_ITEM_LAYOUT_UNSPECIFIED
|
No layout specified. |
TEXT_BELOW
|
The title and subtitle are shown below the grid item's image. |
TEXT_ABOVE
|
The title and subtitle are shown above the grid item's image. |
CardAction
A card action is the action associated with the card. For example, an invoice card might include actions such as delete invoice, email invoice, or open the invoice in a browser.
JSON representation |
---|
{
"actionLabel": string,
"onClick": {
object (
|
Fields | |
---|---|
actionLabel
|
The label that displays as the action menu item. |
onClick
|
The
|
DisplayStyle
Determines how a card is displayed. Not supported by Google Chat apps.
Enums | |
---|---|
DISPLAY_STYLE_UNSPECIFIED
|
Do not use. |
PEEK
|
The header of the card appears at the bottom of the sidebar, partially covering the current top card of the stack. Clicking the header pops the card into the card stack. If the card has no header, a generated header is used instead. |
REPLACE
|
Default value. The card is shown by replacing the view of the top card in the card stack. |