We're building a Gmail Add-On however we wish to show a different card on depending on some business logic when the add-on's onTriggerFunction
is called. This works fine for the first time the function runs when an email opens.
We have the conditional logic, but Gmail appears to cache the result of the initial call returning the first card. Going to another email and back to original, the onTriggerFunction
is not called again, so the conditional logic is not run to change the initial card rendered.
Is there anyway to get the onTriggerFunction to run every time an email is opened, not just once the first time the email is opened?
Here's an example add-on with a trigger function that returns a single card displaying the current time:
Code.js
function buildAddOn(e) {
var card = CardService.newCardBuilder();
card.setHeader(CardService.newCardHeader().setTitle(new Date().toLocaleTimeString()));
return [card.build()];
}
appsscript.json
{
"timeZone": "GMT",
"dependencies": {
},
"oauthScopes": ["https://www.googleapis.com/auth/gmail.addons.execute"],
"gmail": {
"name": "Minimal example",
"logoUrl": "https://www.gstatic.com/images/icons/material/system/2x/bookmark_black_24dp.png",
"contextualTriggers": [{
"unconditional": {
},
"onTriggerFunction": "buildAddOn"
}],
"primaryColor": "#4285F4",
"secondaryColor": "#4285F4",
"openLinkUrlPrefixes": ["https://mail.google.com/"],
"version": "TRUSTED_TESTER_V2"
}
}
When navigating to older conversations a spinner is displayed followed by the current time. However, when navigating back to previously displayed conversations the old value of the time is displayed instantly, suggesting some caching is taking place:
Actions inside the add-on, or other activity in our app can affect what should be displayed when re-opening a previously displayed conversation. This means that redisplaying an old copy of the card results in unexpected behaviour for the user.
Unfortunately there is no way at the moment (July 2019) to force the trigger to run every time the email is opened. You can use ActionResponseBuilder.setStateChanged(true)
as a response to a button click to instruct Gmail to clear the cache, but it can't be sent along with a normal card response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With