Add Item To Gmail Message Menu

229 views
Skip to first unread message

Daniel Davis

unread,
Mar 9, 2023, 12:10:36 PM3/9/23
to Google Apps Script Community
Is it possible to add a menu item to an  email message using Apps Scripts?  I'd like to add an item like to this menu:


addMenuItem.png

I used the cat email quickstart and tried modifying it to draw that menu item on an email message but I have not been able to get it to work yet.

Here is the quickstart I'm talking about:
https://developers.google.com/apps-script/add-ons/cats-quickstart

The quickstart does show how to add a menu item to the compose email screen, but I can't see how to get this to work for an inbox email.  

when composing an email the menu item is added using appsscript.json like this:

"composeTrigger": {
       
"selectActions": [{
         
"text": "Insert cat",
         
"runFunction": "onGmailCompose"
       
}],
       
"draftAccess": "NONE"
     
}

Is there some trigger that I can use for when an email is opened?  I have not found one.  I also tried creating the button inside the onGmailMessage function that is triggered by:

"gmail": {
     
"contextualTriggers": [{
       
"unconditional": {
       
},
       
"onTriggerFunction": "onGmailMessage"
     
}],

here is my onGmailMessage function:
function  onGmailMessage   (e) {
   
// Activate temporary Gmail scopes, in this case to allow
   
// message metadata to be read.
   
var accessToken = e.gmail.accessToken;
   
GmailApp.setCurrentMessageAccessToken(accessToken);

   
var messageId = e.gmail.messageId;
   
var message = GmailApp.getMessageById(messageId);
   
var subject = message.getSubject();
   
var sender = message.getFrom();

   
// Create a card with a single card section and two widgets.
   
// Be sure to execute build() to finalize the card construction.
   
var exampleCard = CardService.newCardBuilder()
       
.setHeader(CardService.newCardHeader()
           
.setTitle('Example card'))
       
.addSection(CardService.newCardSection()
           
.addWidget(CardService.newKeyValue()
               
.setTopLabel('Subject')
               
.setContent(subject))
           
.addWidget(CardService.newKeyValue()
               
.setTopLabel('From')
               
.setContent(sender)))
       
.build();   // Don't forget to build the Card!
   
return [exampleCard];
 
}

 

I don't see anything when I open an email.  Where is that card supposed to be displayed?

Jonathan Butler

unread,
Mar 9, 2023, 5:37:29 PM3/9/23
to google-apps-sc...@googlegroups.com
There should be a small arrow in the bottom right of the screen that reveals a sidebar. 

image.png

image.png

That sidebar should contain your gmail application.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/394c07e2-e5f3-4f43-a79e-c26f6ebb631fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages