Gmail Add-on trigger criteria

2019-02-21 10:22发布

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?

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-21 10:58

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

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

查看更多
forever°为你锁心
3楼-- · 2019-02-21 11:03

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.

查看更多
登录 后发表回答