gpt4 book ai didi

google-apps-script - Google应用程序脚本,gmail插件获取TextInput值

转载 作者:行者123 更新时间:2023-12-02 21:02:00 32 4
gpt4 key购买 nike

我已经使用谷歌脚本创建了简单的 gmail 插件,因为我在这里遇到了困难,

当我们执行某些操作时如何获取textinput值,我检查了文档,我找不到任何方法

TextInput

我尝试过以下代码,

var card = CardService.newCardBuilder();
card.setHeader(CardService.newCardHeader().setTitle("Login Here"));
var section = CardService.newCardSection()
var cleint_id_Input = CardService.newTextInput()
.setFieldName("client_id")
.setTitle("Please enter clinet id")
var username_Input = CardService.newTextInput()
.setFieldName("username")
.setTitle("Please enter username")
var password_Input = CardService.newTextInput()
.setFieldName("password")
.setTitle("Please enter password")
section.addWidget(cleint_id_Input)
section.addWidget(username_Input)
section.addWidget(password_Input)
Logger.log("Input Value%s",cleint_id_Input)
//Login action button
var action = CardService.newAction().setFunctionName('loginCallback');
section.addWidget(CardService.newTextButton().setText('Login').setOnClickAction(action))
card.addSection(section)

我需要“loginCallback”函数中的inputText值

提前致谢

最佳答案

您可以将输入的值作为 JSON 对象检索。修改后的脚本检索输入的值并显示它们。因此,请根据您的环境修改此设置。

修改后的脚本:

function buildAddOn() {
var card = CardService.newCardBuilder();
card.setHeader(CardService.newCardHeader().setTitle("Login Here"));
var section = CardService.newCardSection()
var cleint_id_Input = CardService.newTextInput()
.setFieldName("client_id")
.setTitle("Please enter clinet id")
var username_Input = CardService.newTextInput()
.setFieldName("username")
.setTitle("Please enter username")
var password_Input = CardService.newTextInput()
.setFieldName("password")
.setTitle("Please enter password")
section.addWidget(cleint_id_Input)
section.addWidget(username_Input)
section.addWidget(password_Input)
Logger.log("Input Value%s",cleint_id_Input)
//Login action button
var action = CardService.newAction().setFunctionName('loginCallback');
section.addWidget(CardService.newTextButton().setText('Login').setOnClickAction(action))
card.addSection(section)
return card.build() // Added
}

// Added
function loginCallback(e) {
return CardService.newCardBuilder()
.setHeader(CardService.newCardHeader().setTitle('sample'))
.addSection(CardService.newCardSection().addWidget(
CardService.newKeyValue().setContent(JSON.stringify(e.formInput, null, " ")))
)
.build();
}

输入值:

就您而言,loginCallback(e)e 如下。

{
"formInput": {
"password": "###",
"client_id": "###",
"username": "###"
},
"clientPlatform": "web",
"messageMetadata": {
"messageId": "###",
"accessToken": "###"
},
"formInputs": {
"password": [
"###"
],
"client_id": [
"###"
],
"username": [
"###"
]
},
"parameters": {}
}

如果我误解了你的问题,我很抱歉。

关于google-apps-script - Google应用程序脚本,gmail插件获取TextInput值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48680165/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com