I create a Gmail add-on with a form. In this form, I have input but in my script, I can not find how to retrieve the value of input in variables. The following code opens a sidebar in the Gmail inbox when you click on an e-mail and fill in the form's input with the mail's metadata and contact information. If the contact does not exist, the user can create it by entering the name and first name of the sender (the e-mail address is retrieved from the e-mail). But I do not know how to recover the information entered by the user.
Here is my script:
function buildAddOn(e) {
// Activer les extensions complémentaires de Gmail
var accessToken = e.messageMetadata.accessToken;
GmailApp.setCurrentMessageAccessToken(accessToken);
var messageId = e.messageMetadata.messageId;
var message = GmailApp.getMessageById(messageId);
var emailAddress = recupEmail(message.getFrom(), '<', '>'); // Dans le message, l'adresse mail de l'expéditeur se trouve entre les balises '<' et '>'
var objet = message.getSubject();
var contact = ContactsApp.getContact(emailAddress);
var contactNom;
var contactPrenom;
if(contact != null){
contactPrenom = contact.getFamilyName();
contactNom = contact.getFullName().replace(contactPrenom, '');
}else{
contactNom = '';
contactPrenom = '';
}// if-else
var head = 'Expediteur';
var labelNom = 'Nom';
var labelPrenom = 'Prenom';
var labelEmail = 'Adresse e-mail';
var labelObjet = 'Objet';
var labelMessage = 'Message';
var action = CardService.newAction().setFunctionName('creatContact');
var section = CardService.newCardSection();
section.setHeader(head);
section.addWidget(CardService.newTextInput().setFieldName('nom').setTitle(labelNom).setValue(contactPrenom));
section.addWidget(CardService.newTextInput().setFieldName('prenom').setTitle(labelPrenom).setValue(contactNom));
if(contact == null){
section.addWidget(CardService.newTextButton().setText('Ajouter au contacts').setOnClickAction(action));
}
section.addWidget(CardService.newTextInput().setFieldName('mail').setTitle(labelEmail).setValue(emailAddress));
section.addWidget(CardService.newTextInput().setFieldName('objet').setTitle(labelObjet).setValue(objet));
var card = CardService.newCardBuilder()
.addSection(section)
.build();
return [card];
}
function recupEmail(from, debut, fin){
var result = from.split(debut)[1].split(fin)[0];
return result;
}
function creatContact(){
/*
var givenName = ??;
var familyName = ??;
var email = ??;
*/
ContactsApp.createContact(givenName, familyName, email)
}
Thank you in advance. Sorry for my bad english.