Google 应用程序脚本,gmail 插件获取 TextInput 值

Google app script,gmail addon get TextInput value

我已经使用 google 脚本创建了简单的 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": {}
}

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