我正在尝试利用Google的gmail插件文本输入建议: https://developers.google.com/gsuite/add-ons/how-tos/suggestions
目标是当用户在输入框中输入文本时,会从用户的google驱动器files:list方法返回建议。
但是,似乎系统从未进入DriveApp.searchFiles行,并且没有错误报告。这就是我在日志中看到的全部内容:
[19-03-22 10:36:28:243 CET]文本输入:asdf
function getInsertImageComposeUI(e) {
return [buildInitialMailMergeCard()];
}
function refreshSpreadsheetSuggestions(e){
var suggestions = CardService.newSuggestions();
var textInput = e.formInputs.spreadsheetInput[0];
Logger.log("Text input: " + textInput);
var files = DriveApp.searchFiles({'title': textInput});
Logger.log("files: " + files);
while(files.hasNext()){
var file = files.next();
suggestions.addSuggestion(file.getName());
}
return CardService.newSuggestionsResponseBuilder()
.setSuggestions(suggestions)
.build();
}
function buildInitialMailMergeCard() {
var spreadsheetPickerChanged = CardService.newAction()
.setFunctionName('refreshSpreadsheetSuggestions')
.setParameters({"numSuggestions": "5"});
var spreadsheetPicker = CardService.newTextInput()
.setFieldName('spreadsheetInput')
.setTitle('Choose a spreadsheet')
.setSuggestionsAction(spreadsheetPickerChanged)
var drivePickerSection = CardService.newCardSection().setHeader('Choose a Spreadsheet:');
drivePickerSection.addWidget(spreadsheetPicker);
var initialCard = CardService.newCardBuilder();
initialCard.addSection(drivePickerSection);
return initialCard.build();
}