Getting Gmail to display programmatically generated draft reply

49 views
Skip to first unread message

Eddie Sirota

unread,
Mar 16, 2023, 8:21:31 PM3/16/23
to Google Apps Script Community
Hi All,

New to Apps Script. Appreciate any help possible. I created a Gmail Add-on which works in a context of a Gmail message. Add-on is an internal tool that looks up subscription info from a user that emailed us and enables customer support actions as per request. Upon successfully completing an action, the add-on generates a pre-populated draft reply to the Gmail message that started the whole process. Everything works great. However, even though the gmail draft gets created, it doesn't auto-appear within the Gmail message pane. I have to refresh my browser tab, or go back to inbox and click on the email thread again before seeing the draft. I've tried message.refresh(), thread.refresh(),  GmailApp.refreshThread(currentMessage.getThread()). No luck. Appreciate any help .

Thanks,

Eddie

Eddie Sirota

unread,
Mar 16, 2023, 8:24:35 PM3/16/23
to Google Apps Script Community
Here's my code for clarity:
var currentMessage = getCurrentMessage(e);
var draft = currentMessage.createDraftReplyAll(emailBodyPlain, {htmlBody: emailBodyHTML});
CardService.newComposeActionResponseBuilder().setGmailDraft(draft).build();
currentMessage.refresh();
currentMessage.getThread().refresh();
GmailApp.refreshThread(currentMessage.getThread());

Eddie Sirota

unread,
Mar 17, 2023, 6:39:53 PM3/17/23
to Google Apps Script Community
ok, I figured it out. I was trying to both update my card and generate an email draft on success. But looks like you can do one or the other and not both. So now I'm updating my card on action success and giving user a way to generate an email draft with a button click post card update. Not ideal, but gets the job done. If anyone know how you can do both, update card and generate an email draft with one action handler, please let me know.
Reply all
Reply to author
Forward
0 new messages