The following Google Apps Script code is the first to be run when the Gmail add-on is launched and is designed to prompt for a username of a student. The script is called via the 'onTriggerFunction' in the manifest file.
Save message to Drive add-on |
var inputWidget = CardService.newTextInput()Then add this to the section we created:
.setFieldName('userId')
.setTitle('Enter username here')
section.addWidget(inputWidget);Now we need a button action, a button to attach the action to and to add it to the card section. The action for the button is to run the getUserInfo function detailed in the next blog post. The button itself just contains the text Submit.
var buttonAction = CardService.newAction()The final part of this script finishes by adding the buttonSet widget to the section, the section to the card, then 'build' the card and return it.
.setFunctionName('getUserInfo');
var button = CardService.newTextButton()
.setText('Submit')
.setOnClickAction(buttonAction);
var buttonSet = CardService.newButtonSet()
.addButton(button)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getContextualAddOn(event) { | |
//make a card | |
var card = CardService.newCardBuilder(); | |
//make a card section | |
var section = CardService.newCardSection(); | |
//make a text input widget and add to the section | |
var inputWidget = CardService.newTextInput().setFieldName('userId').setTitle('Enter username here'); | |
section.addWidget(inputWidget); | |
//make a button action, a button, a button set and add them to the section | |
var buttonAction = CardService.newAction().setFunctionName('getUserInfo'); | |
var button = CardService.newTextButton().setText('Submit').setOnClickAction(buttonAction); | |
var buttonSet = CardService.newButtonSet() | |
.addButton(button) | |
section.addWidget(buttonSet); | |
//add section to card | |
card.addSection(section); | |
//return the built card | |
return card.build(); | |
} |
No comments:
Post a Comment