问题
I'm actually trying to create a Chat interface in Gmail using Add-ons with App Script. All the interactions are working. But it keeps navigating to different cards rather than have it all in one card. Like in Google Tasks.
Is there a way in which I can just keep adding sections to the same card dynamically to create a chat like interface.
I assume if it is possible on Google Tasks Add-on it should be possible in this case too. Please help me out as it is a necessary requirement.
回答1:
Update : Try this
function renderRootCard(){
var card = CardService.newCardBuilder();
var section = CardService.newCardSection();
var btnSet = CardService.newButtonSet();
section.addWidget(CardService.newTextParagraph().setText("old widget"));
section.addWidget(btnSet.addButton(addTaskBtn));
card.addSection(section);
var addTask = CardService.newAction().setFunctionName("addTask");
var addTaskBtn = CardService.newTextButton()
.setText("Add Task")
.setOnClickAction(addTask);
return card.build();
}
function addTask(e) {
var card = CardService.newCardBuilder();
var section = CardService.newCardSection();
var btnSet = CardService.newButtonSet();
section.addWidget(CardService.newTextParagraph().setText("old widget"));
section.addWidget(btnSet.addButton(addTaskBtn));
section.addWidget(CardService.newTextParagraph().setText("new widget"));
var addTask = CardService.newAction().setFunctionName("addTask");
var addTaskBtn = CardService.newTextButton()
.setText("Add Task")
.setOnClickAction(addTask);
return CardService.newNavigation().updateCard(card.build());
}
Original answer:
In short: Possible
I understand what you are trying to do. This involves replacing the current card by updating it with a new card that has the same widgets as that of current card and additional widgets that are required.
Let's say, you are building a to-do app. When you click add task(say), you just create the same card, add some widgets and replace the current card with a new one.
来源:https://stackoverflow.com/questions/53257853/how-can-i-add-new-sections-to-an-existing-card-on-gmail-addon