我目前正在撰寫使用 Google-Apps-Scripts 來更改執行緒和訊息的標簽。腳本完成后,有效負載會被移動,但用戶前端的顯示在用戶與 Gmail 互動之前不會改變。
有沒有辦法將重繪 命令推送到 Gmail?如何優雅地向用戶顯示“作業已完成”,以便他們知道訊息現在已適當標記?
我直接針對 Gmail API,而不是 GmailApp。我發現了 ActionResponseBuilder.setStateChanged(),但問題是我目前沒有使用任何型別的前端介面。這一切都在后臺。
這是我用來抓取訊息以修改(根據要求)的一些代碼的縮寫示例:
function changeLabel(ids,oldLabel,newLabel) {
Gmail.Users.Messages.batchModify({
"ids":ids,
"addLabelIds":oldLabel,
"removeLabelIds":newLabel
},"me");
}
function start() {
// Labels to work with
const FOO = "Label_5095729546757874255";
const BAR = "Label_5102306845672214551";
// API call to retrieve list of messages by Label
var msgIdsByLabel = new MessageIndex(FOO);
// API call to retrieve message contents
var payloadMessages = new Messages(msgIdsByLabel);
var manifestMessagesToMove = [];
for (var i=0;i < Object.keys(payloadMessages.response).length; i ) {
// Criteria for selecting messages to move goes here
manifestMessagesToMove[i] = payloadMessages.response[i].id;
}
// Change labels of Message Ids
changeLabel(manifestMessagesToMove,FOO,BAR);
// ??? Refresh Gmail Interface ???
}
uj5u.com熱心網友回復:
不幸的是,這是不可能的。
Gmail UI 無法從 Apps 腳本重繪 ,因為它在云中作為單獨的會話運行,與用戶在網路瀏覽器中查看的會話不同。兩者沒有連接 - Gmail API 也是如此。
如果您沒有前端界面(也就是使用 Gmail 插件CardService),那么也沒有辦法向用戶顯示訊息。必須手動完成重繪 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/468290.html
