18

Can someone accurately describe the trigger criteria for Gmail Add-on scripts? Apparently, the trigger is not invoked each time the user navigates between Gmail conversations.

The only documentation I can find is https://developers.google.com/gmail/add-ons/how-tos/building#note1, which states

the only contextual trigger type available is unconditional, which triggers for all emails regardless of content.

I interpreted this to mean that the trigger is invoked every time the user navigates to a different gmail conversation, however, that is not the case:

The first time I navigate to a some Gmail conversation, the add-on trigger fires. And when I navigate to another conversation using the the “Newer” or “Older” angle-bracket button, the trigger is again invoked for the new conversation. But when I navigate back to the first page using an angle bracket button, the add-on trigger does not fire. (Easy enough to show this by displaying a timestamp when each UI card is created.) There seems to be some kind of internal caching going on — is there any way to disable this, or otherwise run my add-on script each time the user navigates between Gmail conversations?

tehhowch
  • 9,645
  • 4
  • 24
  • 42
user3754273
  • 183
  • 1
  • 6
  • 5
    No response, as expected. Typical of Google to direct support questions to Stack Overflow, and then ignore them. Disappointing, but not surprising. We are on our own... – user3754273 Feb 27 '18 at 01:29
  • 1
    Consider filing a bug report on the Gmail Add-on Issue Tracker: https://issuetracker.google.com/issues?q=componentid:325133 – tehhowch May 04 '18 at 14:58

2 Answers2

2

Currently, Google Apps Script doesn't have triggers for Gmail events so the trigger will not invoke every time, the user navigates to a different Gmail conversation. Whenever a new message open it will invoke trigger, contextual trigger. You can also tryout time-driven trigger which invokes after each time interval. To use time-driven trigger open your project on https://script.google.com/. In Apps Script Editor, navigate to Edit -> All your triggers. If there is no trigger then setUp one and Save. See this example Create Time-driven trigger in Gmail-add on

Refer this link for more information How do I detect when I view an email in gmail with google-apps-script script? I think this might be helpful.

Jai Prak
  • 2,855
  • 4
  • 29
  • 37
  • 1
    It seems that time-driven triggers are not available in Gmail addons: https://developers.google.com/gmail/add-ons/guides/restrictions Do you confirm @JaiPrak? – Basj May 29 '18 at 11:59
  • 1
    Google Apps Script has no simple or installable triggers but it has time-driven triggers. How to use them, I am updating my answer. – Jai Prak May 29 '18 at 12:24
  • 1
    Are you speaking about Google apps script in general or Gmail add-ons ? The latter seems to have no time driven : https://developers.google.com/gmail/add-ons/guides/restrictions – Basj May 29 '18 at 13:11
  • 1
    Gmail add ons require a manifest to enable other users to use it, in the manifest I don't think it's possible to put a time driven trigger. – Basj May 29 '18 at 13:13
  • 1
    Yes, you can. No need to put the time-driven trigger in the manifest and I haven't seen any example to setup time-driven trigger in manifest except contextual triggers. Once just try to create simple time-trigger in your project and in trigger method just put this there `function myTrigger(){ Logger.log('Some message'); }` Set trigger time for every minute. Each minute you will see the logger message with respective time of the trigger call. – Jai Prak May 30 '18 at 07:20
  • Can you add an answer with code example @JaiPrak showing how to create such a time driven trigger in a Gmail add on ? Thanks in advance. – Basj May 30 '18 at 07:38
  • For example please go this link https://goolgedev.blogspot.com/2018/05/create-time-driven-trigger-in-gmail-add.html – Jai Prak May 30 '18 at 10:14
  • The trigger is getting disabled, if we install it in the way suggested in the blog post. – V.i.K.i Apr 03 '19 at 11:54
2

you can use ActionResponseBuilder.setStateChanged(), to clear the cache

link: https://developers.google.com/gmail/add-ons/how-tos/interactions

fangchao
  • 36
  • 2
  • I have not verified that this works, but it sure seems like the way to go. I switched to [inboxsdk](https://www.inboxsdk.com/) over a year and a half ago. – user3754273 Nov 11 '18 at 19:28