AI-generated Key Takeaways
-  DecoratedText is a widget for displaying text with optional icons, and labels above or below. 
-  Setting the text content and either a top label, bottom label, or icon is required for this widget. 
-  DecoratedText is designed to replace the KeyValue widget and is available for Google Workspace add-ons and Google Chat apps. 
A widget that displays text with optional decorations. Possible keys include an icon, a label
above and a label below. Setting the text content and one of the keys is required using  set  
and one of  Decorated  
,  Decorated  
,  set  
, or  set  
. This class is intended to replace  
   
. Key  
Available for Google Workspace add-ons and Google Chat apps.
const decoratedText = CardService . newDecoratedText (). setText ( 'Text' ). setTopLabel ( 'TopLabel' ); const multilineDecoratedText = CardService . newDecoratedText () . setText ( 'Text' ) . setTopLabel ( 'TopLabel' ) . setWrapText ( true ) . setBottomLabel ( 'BottomLabel' );
Methods
| Method | Return type | Brief description | 
|---|---|---|
|  Decorated  | Sets an authorization action that opens a URL to the authorization flow when the object is clicked. | |
|  Decorated  | Sets the label text to be used as the key and is displayed below the text content. | |
|  Decorated  | Sets the  Button 
that is displayed to the right of the text. | |
|  Decorated  | Sets an action that composes a draft email when the object is clicked. | |
|  Decorated  | Sets the optional  Icon that is displayed to the right of the content. | |
|  Decorated  | Sets an action that executes when the object is clicked. | |
|  Decorated  | Sets an action that opens a URL in a tab when the object is clicked. | |
|  Decorated  | Sets a URL to be opened when the object is clicked. | |
|  Decorated  | Sets the optional  Icon to display before the text content. | |
|  Decorated  | Sets the  Switch 
that is displayed to the right of the content. | |
|  Decorated  | Sets the text to be used as the value. | |
|  Decorated  | Sets the label text to be used as the key and is displayed above the text content. | |
|  Decorated  | Sets whether the value text should be displayed on a single line or multiple lines. | 
Detailed documentation
 set  
 
 Sets an authorization action that opens a URL to the authorization flow when the object is clicked. This opens the URL in a new window. When the user finishes the authorization flow and returns to the application, the add-on reloads.
A UI object can only have one of  set  
,  set  
,  set  
,  set  
, or  set  
set.
// ... const action = CardService . newAuthorizationAction (). setAuthorizationUrl ( 'url' ); CardService . newTextButton (). setText ( 'Authorize' ). setAuthorizationAction ( action );
Parameters
| Name | Type | Description | 
|---|---|---|
| action |  Authorization  | The object that specifies the authorization action to take when this element is clicked. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets the label text to be used as the key and is displayed below the text content.
Parameters
| Name | Type | Description | 
|---|---|---|
| text | String | The label text. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets the  Button 
 
that is displayed to the right of the text. A  Decorated  
can
only support one button or one switch.
Parameters
| Name | Type | Description | 
|---|---|---|
| button |  Button 
 | The button to add. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets an action that composes a draft email when the object is clicked. A UI object can only
have one of  set  
,  set  
,  set  
,  set  
, or  set  
set.
The  Action 
 
parameter must specify a callback function that returns a  Compose  
object configured using  Compose  
.
// ... const action = CardService . newAction (). setFunctionName ( 'composeEmailCallback' ); CardService . newTextButton () . setText ( 'Compose Email' ) . setComposeAction ( action , CardService . ComposedEmailType . REPLY_AS_DRAFT ); // ... function composeEmailCallback ( e ) { const thread = GmailApp . getThreadById ( e . threadId ); const draft = thread . createDraftReply ( 'This is a reply' ); return CardService . newComposeActionResponseBuilder () . setGmailDraft ( draft ) . build (); }
Parameters
| Name | Type | Description | 
|---|---|---|
| action |  Action 
 | The object that specifies the compose action to take when this element is clicked. | 
| composed  |  Composed  | An enum value that specifies whether the composed draft is a standalone or reply draft. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets the optional  Icon  
that is displayed to the right of the content. A  Decorated  
can only support one button, one switch or one icon.
Parameters
| Name | Type | Description | 
|---|---|---|
| end  |  Icon  | The icon to add. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets an action that executes when the object is clicked. A UI object can only have one of  set  
,  set  
,  set  
,  set  
, or  set  
set.
The  Action 
 
parameter must specify a callback function that returns a  Action  
object.
// ... const action = CardService . newAction (). setFunctionName ( 'notificationCallback' ); CardService . newTextButton () . setText ( 'Create notification' ) . setOnClickAction ( action ); // ... function notificationCallback () { return CardService . newActionResponseBuilder () . setNotification ( CardService . newNotification (). setText ( 'Some info to display to user' ), ) . build (); }
Parameters
| Name | Type | Description | 
|---|---|---|
| action |  Action 
 | The action to take when this element is clicked. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets an action that opens a URL in a tab when the object is clicked. Use this function when the
URL needs to be built or when you need to take other actions in addition to creating the  Open  
object. A UI object can only have one of  set  
,  set  
,  set  
,  set  
, or  set  
set.
The  Action 
 
parameter must specify a callback function that returns a  Action  
object configured using  Action  
.
// ... const action = CardService . newAction (). setFunctionName ( 'openLinkCallback' ); CardService . newTextButton () . setText ( 'Open Link' ) . setOnClickOpenLinkAction ( action ); // ... function openLinkCallback () { return CardService . newActionResponseBuilder () . setOpenLink ( CardService . newOpenLink (). setUrl ( 'https://www.google.com' )) . build (); }
Parameters
| Name | Type | Description | 
|---|---|---|
| action |  Action 
 | The object that specifies the open link action to take when this element is clicked. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets a URL to be opened when the object is clicked. Use this function when the URL is already
known and only needs to be opened. A UI object can only have one of  set  
,  set  
,  set  
,  set  
,
or  set  
set.
Parameters
| Name | Type | Description | 
|---|---|---|
| open  |  Open  | An  Open object describing the URL to open. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets the optional  Icon  
to display before the text content.
Parameters
| Name | Type | Description | 
|---|---|---|
| start  |  Icon  | The icon to display. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets the  Switch 
 
that is displayed to the right of the content. A  Decorated  
can only support one button or one switch.
Parameters
| Name | Type | Description | 
|---|---|---|
| switch  |  Switch 
 | The switch to add. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets the text to be used as the value. Supports basic HTML formatting . Required.
Parameters
| Name | Type | Description | 
|---|---|---|
| text | String | The text content for this widget. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets the label text to be used as the key and is displayed above the text content.
Parameters
| Name | Type | Description | 
|---|---|---|
| text | String | The label text. | 
Return
  Decorated  
— This object, for chaining.
 set  
 
 Sets whether the value text should be displayed on a single line or multiple lines.
Parameters
| Name | Type | Description | 
|---|---|---|
| wrap  | Boolean | If true, the text is wrapped and displayed on multiple lines. Otherwise
    the text is truncated. | 
Return
  Decorated  
— This object, for chaining.

