Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug gmail-addons with real email

I want to create a gmail add-on. I've already created the quick start application:

https://developers.google.com/gmail/add-ons/guides/quickstart

So, trigger function for that example is :

    function buildAddOn(e) {
  // Activate temporary Gmail add-on scopes.
  var accessToken = e.messageMetadata.accessToken;
  GmailApp.setCurrentMessageAccessToken(accessToken);

  var messageId = e.messageMetadata.messageId;
  var senderData = extractSenderData(messageId);
  var cards = [];

  // Build a card for each recent thread from this email's sender.
  if (senderData.recents.length > 0) {
    senderData.recents.forEach(function(threadData) {
      cards.push(buildRecentThreadCard(senderData.email, threadData));
    });
  } else {
    // Present a blank card if there are no recent threads from
    // this sender.
    cards.push(CardService.newCardBuilder()
      .setHeader(CardService.newCardHeader()
        .setTitle('No recent threads from this sender')).build());
  }
  return cards;
}

In apps script editor, you can debug this function, but, since we are not in gmail, we can not get the "e" parameter, so actually you can not debug it with the real data.

I have deployed that example as a developer add-on and I can use it in my gmail account. I tried to find the function somewhere in the code, I put debugger; or console.log() but I was not able to debug in browser.

So, how can I debug gmail add-on script with real gmail data ?

like image 410
esayli Avatar asked Oct 30 '17 12:10

esayli


People also ask

How do I debug a Google App Script?

Run a script in debug mode To run the script in debug mode, at the top of the editor click Debug. Before the script runs the line with the breakpoint it pauses and displays a table of debug information. You can use this table to inspect data like the values of parameters and the information stored in objects.

What are Gmail services?

Gmail. This Service lets you send email, compose drafts, manage labels, mark messages and threads, and conduct a variety of other Gmail account management tasks. See also Mail Service, a simpler service that only allows the sending of email.


1 Answers

Gmail addons can't run client-side code so the browser console will not be very helpful but we could use Logger to log messages to Script Editor or to use console to log messages to Stackdriver.

like image 173
Rubén Avatar answered Nov 14 '22 20:11

Rubén