Thursday 31 January 2019

Save email to Drive add-on - get username

Overview blog post.

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.
Screenshot of the username prompt for the email add-on
Save message to Drive add-on
We begin by building the card that requests this information and do so via the 'CardService.newCardBuilder' class, to which we need to create a 'newCardSection' to display our information. Next we create a 'textInput' widget to ask for the username:
var inputWidget = CardService.newTextInput()
    .setTitle('Enter username here')
Then add this to the section we created:
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()
var button = CardService.newTextButton()
var buttonSet = CardService.newButtonSet()
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.

No comments:

Post a Comment