2

community,

I'm developing a Gmail Add-on using Card Services and trying to implement a popup that displays when a specific event occurs within the add-on. I want to provide users with additional information or options in this popup.

I've looked through the Google Apps Script documentation and Gmail Add-on guides, but I couldn't find a straightforward way to create a popup within the context of the Gmail Add-on.

Ideally, I would like the popup to appear when the user clicks a specific button or performs a particular action within the add-on. What functions or libraries should I be using for this purpose? Are there any code examples or tutorials that could help me get started?

Could someone guide me on how to add a popup to a Gmail Add-on using card services?

Shiv Yadav
  • 467
  • 2
  • 11

1 Answers1

0

SUGGESTION:

You could use Class Notification to generate a notification pop-up box and bind it to your button Actions. Here is a sample implementation, using the Gmail Card Service Quickstart Guide "Cats"

Use this sample modified version of the function:

function onChangeCat(e) {
  console.log(e);
  // Get the text that was shown in the current cat image. This was passed as a
  // parameter on the Action set for the button.
  var text = e.parameters.text;

  // The isHomepage parameter is passed as a string, so convert to a Boolean.
  var isHomepage = e.parameters.isHomepage === 'true';

  // Create a new card with the same text.
  var card = createCatCard(text, isHomepage);

  // Create an action response that instructs the add-on to replace
  // the current card with the new one.
  var navigation = CardService.newNavigation()
      .updateCard(card);
      
  var actionResponse = CardService.newActionResponseBuilder()
      .setNavigation(navigation).setNotification(CardService.newNotification()
          .setText("This is a test notification message"));

  return actionResponse.build();
}

Simply add .setNotification(CardService.newNotification().setText("This is a test notification message")) on the ActionResponseBuilder and set your predefined text within the setText method

image

Century Tuna
  • 1,378
  • 1
  • 6
  • 13
  • Hi Century Tuna, Thanks for the suggestion about using Class Notification. However, I'm actually looking for a modal dialog box, similar to `SpreadsheetApp.getUi().showModalDialog()` in Google Sheets, within a Gmail Add-on. I want a button that, upon clicking, opens a modal box. This should allow interaction before proceeding. For reference, here's the functionality I'm aiming for, as seen in Google Sheets: (https://prnt.sc/u15Xt4iaiPI-). If you can provide insights on using Card Services to achieve this in a Gmail Add-on, I'd really appreciate it. Thanks! – mohsin pathan Aug 31 '23 at 06:38