Page Summary
-
This guide details building a Google Workspace add-on to create and manage external resources (like support cases) directly within Google Docs.
-
Users can create resources via a form within Docs, which then inserts a smart chip linking to the resource in the external service.
-
The add-on requires configuration in the manifest file and utilizes Apps Script, Node.js, Python, or Java for development.
-
Comprehensive code samples are provided to guide developers through card creation, form submission, and error handling.
-
Smart chips representing the created resources offer link previews, enhancing user experience and information access.
This page explains how to build a Google Workspace add-on that lets Google Docs users create resources, such as a support case or project task, in a third-party service from within Google Docs.
With a Google Workspace add-on, you can add your service to the @ menu in Docs. The add-on adds menu items that let users create resources in your service through a form dialog in Docs.
How users create resources
To create a resource in your service from within a Google Docs document, users
type @ in a document and select your service from the @ menu:
When users type @ in a document and select your service, you present them with
a card that includes the form inputs that users need in order to create a
resource. After the user submits the resource creation form, your add-on should
create the resource in your service and generate a URL that points to it.
The add-on inserts a chip into the document for the created resource. When users hold the pointer over this chip, it invokes the add-on's associated link preview trigger. Make sure your add-on inserts chips with link patterns that are supported by your link preview triggers.
Prerequisites
Apps Script
- A Google Workspace add-on that supports link previews for the link patterns of the resources that users create. To build an add-on with link previews, refer to Preview links with smart chips.
Node.js
- A Google Workspace add-on that supports link previews for the link patterns of the resources that users create. To build an add-on with link previews, refer to Preview links with smart chips.
Python
- A Google Workspace add-on that supports link previews for the link patterns of the resources that users create. To build an add-on with link previews, refer to Preview links with smart chips.
Java
- A Google Workspace add-on that supports link previews for the link patterns of the resources that users create. To build an add-on with link previews, refer to Preview links with smart chips.
Set up resource creation for your add-on
This section explains how to set up resource creation for your add-on, which includes the following steps:
- Configure resource creation in your add-on's manifest.
- Build the form cards that users need to create resources within your service.
- Handle form submissions so that the function that creates the resource runs when users submit the form.
Configure resource creation
To configure resource creation, specify the following sections and fields in your add-on's manifest:
Under the
addOnssection in thedocsfield, implement thecreateActionTriggerstrigger that includes arunFunction. (You define this function in the following section, Build the form cards.)To learn about what fields you can specify in the
createActionTriggerstrigger, see the reference documentation for Apps Script manifests or deployment resources for other runtimes.In the
oauthScopesfield, add the scopehttps://www.googleapis.com/auth/workspace.linkcreateso that users can authorize the add-on to create resources. Specifically, this scope allows the add-on to read the information that users submit to the resource creation form and insert a smart chip into the document based on that information.
As an example, see the addons section of a manifest that configures
resource creation for the following support case service:
{
"oauthScopes": [
"https://www.googleapis.com/auth/workspace.linkpreview",
"https://www.googleapis.com/auth/workspace.linkcreate"
],
"addOns": {
"docs": {
"linkPreviewTriggers": [
...
],
"createActionTriggers": [
{
"id": "createCase",
"labelText": "Create support case",
"localizedLabelText": {
"es": "Crear caso de soporte"
},
"runFunction": "createCaseInputCard",
"logoUrl": "https://www.example.com/images/case.png"
}
]
}
}
}
In the example, the Google Workspace add-on lets users create support cases.
Each createActionTriggers trigger must have the following
fields:
- A unique ID
- A text label that appears in the Docs @ menu
- A logo URL pointing to an icon that appears next to the label text in the @ menu
- A callback function that references either an Apps Script function or an HTTP endpoint that returns a card
Build the form cards
To create resources in your service from the Docs @
menu, you must implement any functions
that you specified in the createActionTriggers object.
When a user interacts with one of your menu items, the corresponding
createActionTriggers trigger fires and its callback function presents a card
with form inputs for creating the resource.
Supported elements and actions
To create the card interface, you use widgets to display information and inputs that users need in order to create the resource. Most Google Workspace add-on widgets and actions are supported with the following exceptions:
- Card footers aren't supported.
- Notifications aren't supported.
- For navigations, only the
updateCardnavigation is supported.
Example of card with form inputs
The following example shows an Apps Script callback function that displays a card when a user selects Create support case from the @ menu:
Apps Script
Node.js
Python
Java
The createCaseInputCard function renders the following card:

The card includes text inputs, a drop-down menu, and a checkbox. It also has a
text button with anonClick action that runs another function to
handle the
submission of the creation form.
After the user fills out the form and clicks
Create, the add-on sends the form inputs to theonClick action
function–called submitCaseCreationForm in our example–at which point the
add-on can validate the inputs and use them to
create the resource in the third-party service.
Handle form submissions
After a user submits the creation form, the function associated with the
onClick action runs. For an ideal user experience, your
add-on should handle
both successful and erroneous form submissions.
Handle successful resource creation
The onClick function of your add-on should create the
resource in your third-party service and generate a URL that points to it.
In order to communicate the resource's URL back to Docs
for chip creation, the onClick function should return a SubmitFormResponse
with a one-element array in renderActions.action.links that points to a
link. The link title should represent the title of the created resource and the
URL should point to that resource.
The following example shows a SubmitFormResponse for a created resource:
Apps Script
Node.js
Python
Java
After the SubmitFormResponse is returned, the modal dialog closes and the
add-on inserts a chip into the document.
When users hold the pointer over this chip, it invokes the associated link
preview trigger. Make sure your add-on doesn't insert
chips with link patterns not supported by your link preview triggers.
Handle errors
If a user tries to submit a form with invalid fields, instead of returning a
SubmitFormResponse with a link, the add-on should
return a render action that displays an error using an updateCard navigation.
This lets the user see what they did
wrong and try again. See
updateCard(card)
for
Apps Script and updateCard
for other runtimes. Notifications and pushCard navigations aren't supported.
Example of error handling
The following example shows the code that's invoked when a user submits the
form. If the inputs are
invalid, the card updates and shows error messages. If the inputs are valid,
the add-on returns a SubmitFormResponse with a
link to the created resource.
Apps Script
Node.js
Python
Java
The following code sample validates the form inputs and creates error messages for invalid inputs: