Thu thập dữ liệu bằng biến đầu vào

Hướng dẫn này giải thích cách tạo một biến đầu vào.

Để chạy, các bước yêu cầu một số thông tin nhất định. Ví dụ: để gửi email, bạn cần có địa chỉ email. Để cung cấp thông tin cần thiết này, hãy xác định các biến đầu vào. Sau khi được xác định, các biến đầu vào thường do người dùng đặt trên thẻ cấu hình của một bước trong khi người dùng thiết lập bước đó.

Xác định biến đầu vào ở 2 vị trí: tệp kê khai của tiện ích bổ sung và trong mã bằng thẻ cấu hình nơi người dùng có thể nhập các giá trị cho biến đầu vào.

Xác định biến đầu vào trong tệp kê khai

Trong tệp kê khai, hãy chỉ định các biến đầu vào bằng mảng inputs[]. Mỗi mục trong mảng inputs[] đều có các thuộc tính sau:

  • id: Giá trị nhận dạng duy nhất cho một biến đầu vào. Để cho phép luồng liên kết một phần tử đầu vào của thẻ cấu hình với biến đầu vào này, bạn phải khớp tên của phần tử thẻ tương ứng.
  • description: Nội dung mô tả về biến đầu vào sẽ hiển thị cho người dùng cuối.
  • cardinality: Số lượng giá trị được phép. Các giá trị có thể sử dụng là:
    • SINGLE: Bạn chỉ được phép gửi một giá trị.
  • dataType: Loại giá trị được chấp nhận. dataType có thuộc tính basicType xác định loại dữ liệu. Các giá trị hợp lệ bao gồm:
    • STRING: Một chuỗi dạng chữ và số.
    • INTEGER: Một số.
    • TIMESTAMP: Dấu thời gian ở định dạng "số mili giây kể từ thời gian bắt đầu của hệ thống Unix". Ví dụ: ngày 27 tháng 11 năm 2025, 16:49:02 UTC được biểu thị là 1764262142988.
    • BOOLEAN: True hoặc false.
    • EMAIL_ADDRESS: Địa chỉ email ở định dạng dana@example.com.

Ví dụ sau đây xác định 3 biến đầu vào cho một bước tính toán. Hai biến đầu vào đầu tiên là số nguyên và biến thứ ba là một phép toán số học.

JSON

{
  "timeZone": "America/Los_Angeles",
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "addOns": {
    "common": {
      "name": "Calculator",
      "logoUrl": "https://www.gstatic.com/images/branding/productlogos/calculator_search/v1/web-24dp/logo_calculator_search_color_1x_web_24dp.png",
      "useLocaleFromApp": true
    },
    "flows": {
      "workflowElements": [
        {
          "id": "calculatorDemo",
          "state": "ACTIVE",
          "name": "Calculate",
          "description": "Asks the user for two values and a math operation, then performs the math operation on the values and outputs the result.",
          "workflowAction": {
            "inputs": [
              {
                "id": "value1",
                "description": "value1",
                "cardinality": "SINGLE",
                "dataType": {
                  "basicType": "INTEGER"
                }
              },
              {
                "id": "value2",
                "description": "value2",
                "cardinality": "SINGLE",
                "dataType": {
                  "basicType": "INTEGER"
                }
              },
              {
                "id": "operation",
                "description": "operation",
                "cardinality": "SINGLE",
                "dataType": {
                  "basicType": "STRING"
                }
              }
            ],
            "outputs": [
              {
                "id": "result",
                "description": "Calculated result",
                "cardinality": "SINGLE",
                "dataType": {
                  "basicType": "INTEGER"
                }
              }
            ],
            "onConfigFunction": "onConfigCalculate",
            "onExecuteFunction": "onExecuteCalculate"
          }
        }
      ]
    }
  }
}

Xác định biến đầu vào trong mã

Mã của bước này bao gồm một hàm có tên là onConfigFunction(), trả về một thẻ cấu hình xác định một tiện ích thẻ đầu vào cho mỗi biến đầu vào được xác định trong mảng inputs[] của tệp kê khai.

Các tiện ích đầu vào được xác định trong thẻ cấu hình có các yêu cầu sau:

  • name của mỗi tiện ích đầu vào phải khớp với id của biến đầu vào tương ứng trong tệp kê khai.
  • Số lượng phần tử của tiện ích đầu vào phải khớp với cardinality của biến đầu vào trong tệp kê khai.
  • Loại dữ liệu của tiện ích đầu vào phải khớp với dataType của biến đầu vào trong tệp kê khai. Nếu biến đầu vào có dataType là số nguyên, thì biến đó không thể chứa một chuỗi.

Để được trợ giúp về cách tạo giao diện thẻ, hãy xem một trong các lựa chọn sau:

  • Trình tạo thẻ: Một công cụ tương tác mà bạn có thể dùng để tạo và xác định thẻ.
  • Thẻ: trong tài liệu tham khảo về API tiện ích bổ sung Google Workspace.
  • Dịch vụ thẻ: Một dịch vụ Apps Script cho phép tập lệnh định cấu hình và tạo thẻ.
  • Tổng quan về giao diện dựa trên thẻ: trong tài liệu dành cho nhà phát triển tiện ích bổ sung Google Workspace.

Ví dụ sau đây trả về một thẻ cấu hình cho mỗi tiện ích đầu vào được xác định trong Xác định biến đầu vào trong tệp kê khai.

Apps Script

/**
* Generates and displays a configuration card for the sample calculation step.
*
* This function creates a card with input fields for two values and a drop-down
* for selecting an arithmetic operation.
*
* The input fields are configured to let the user select outputs from previous
* workflow steps as input values using the `hostAppDataSource` property.
*/
function onConfigCalculate() {
  const firstInput = CardService.newTextInput()
    .setFieldName("value1") // "FieldName" must match an "id" in the manifest file's inputs[] array.
    .setTitle("First Value")
    .setHostAppDataSource(
      CardService.newHostAppDataSource()
        .setWorkflowDataSource(
          CardService.newWorkflowDataSource()
            .setIncludeVariables(true)
        )
    );

  const secondInput = CardService.newTextInput()
    .setFieldName("value2") // "FieldName" must match an "id" in the manifest file's inputs[] array.
    .setTitle("Second Value")
    .setHostAppDataSource(
      CardService.newHostAppDataSource()
        .setWorkflowDataSource(
          CardService.newWorkflowDataSource()
            .setIncludeVariables(true)
        )
    );

  const selectionInput = CardService.newSelectionInput()
    .setTitle("operation")
    .setFieldName("operation") // "FieldName" must match an "id" in the manifest file's inputs[] array.
    .setType(CardService.SelectionInputType.DROPDOWN)
    .addItem("+", "+", false)
    .addItem("-", "-", true)
    .addItem("x", "x", false)
    .addItem("/", "/", false);

  const sections = CardService.newCardSection()
    .setHeader("Action_sample: Calculate")
    .setId("section_1")
    .addWidget(firstInput)
    .addWidget(selectionInput)
    .addWidget(secondInput)

  let card = CardService.newCardBuilder()
    .addSection(sections)
    .build();

  return card;
}

Sử dụng biến đầu ra từ các bước trước

Bạn có thể định cấu hình các biến đầu vào để chấp nhận các biến đầu ra từ các bước trước trong quy trình công việc.

Bật tính năng chọn biến

Để cho phép người dùng chọn các biến từ các bước trước, hãy sử dụng thuộc tính includeVariables trong các tiện ích TextInputSelectionInput.

Các tiện ích TextInputSelectionInput có những tính năng dành riêng cho Workspace Studio sau đây:

  • includeVariables: Một thuộc tính boolean cho phép người dùng chọn các biến từ các bước trước. Để bộ chọn biến xuất hiện trong các bước sau, cả sự kiện bắt đầu và ít nhất một biến đầu ra tương ứng phải liên kết với biến.
  • type: Một giá trị được liệt kê tự động hoàn thành các đề xuất. Sau đây là các giá trị được hỗ trợ:
    • USER: Đưa ra đề xuất tự động hoàn thành cho những người trong danh bạ của người dùng.
    • SPACE: Đưa ra các đề xuất tự động hoàn thành cho những không gian trên Google Chat mà người dùng là thành viên.

Khi cả includeVariablestype đều được đặt, trường nhập sẽ kết hợp các trải nghiệm của chúng. Người dùng có thể chọn một biến số của type trùng khớp trong trình đơn thả xuống và xem các đề xuất tự động hoàn thành cho biến số đó.

  • Đề xuất tự động hoàn thành cho một không gian trên Google Chat.
    Hình 4: Người dùng xem xét các đề xuất tự động hoàn thành khi chọn một không gian.
  • Trình đơn biến cho phép người dùng chọn các biến đầu ra từ các bước trước đó.
    Hình 5: Người dùng chọn biến đầu ra của một bước trước đó trong trình đơn thả xuống ➕Variables (Biến).

Chỉ chọn một biến đầu ra bằng trình đơn mục bổ sung

Bạn có thể định cấu hình một tiện ích SelectionInput để cho phép người dùng chọn một biến đầu ra duy nhất từ bước trước bằng cách sử dụng một trình đơn tràn.

Khi bạn đặt SelectionInputType thành OVERFLOW_MENU, tiện ích này sẽ đóng vai trò là một bộ chọn biến chuyên dụng. Không giống như việc sử dụng includeVariables với TextInput (chuyển đổi giá trị biến thành chuỗi), OVERFLOW_MENU sẽ giữ lại kiểu dữ liệu ban đầu của biến đã chọn.

Apps Script

const selectionInput = CardService.newSelectionInput()
  .setFieldName("variable_picker_1")
  .setTitle("Variable Picker")
  .setType(
    CardService.SelectionInputType.OVERFLOW_MENU
  );

Cho phép người dùng kết hợp văn bản và các biến đầu ra

Bạn có thể định cấu hình các tiện ích TextInput để kiểm soát cách người dùng tương tác với văn bản và biến đầu ra bằng cách sử dụng setInputMode().

  • RICH_TEXT: Cho phép người dùng kết hợp văn bản và các biến đầu ra. Kết quả là một chuỗi được nối duy nhất.
  • PLAIN_TEXT: Hạn chế dữ liệu đầu vào. Người dùng có thể nhập văn bản hoặc chọn một biến đầu ra duy nhất. Khi bạn chọn một biến thể, mọi văn bản hiện có sẽ bị thay thế. Sử dụng chế độ này để thực thi các loại dữ liệu cụ thể được xác định trong tệp kê khai.

Hình ảnh sau đây cho thấy 2 tiện ích TextInput. Thao tác đầu tiên được định cấu hình dưới dạng RICH_TEXT và có văn bản cũng như một biến đầu ra. Thứ hai được định cấu hình là PLAIN_TEXT và chỉ cho phép một biến đầu ra.

  • Các tiện ích nhập văn bản được định cấu hình dưới dạng RICH_TEXT và PLAIN_TEXT
    Hình 3: Tiện ích nhập văn bản được định cấu hình dưới dạng RICH_TEXTPLAIN_TEXT.

Bạn nên đặt chế độ nhập một cách rõ ràng cho tất cả các tiện ích TextInput.

Dưới đây là tệp kê khai để định cấu hình các tiện ích TextInput bằng nhiều chế độ nhập:

JSON

{
  "timeZone": "America/Toronto",
  "dependencies": {},
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "addOns": {
    "common": {
      "name": "Text and output variable demo",
      "logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
      "useLocaleFromApp": true
    },
    "flows": {
      "workflowElements": [
        {
          "id": "richTextDemo",
          "state": "ACTIVE",
          "name": "Rich Text Demo",
          "description": "Show the difference between rich text and plain text TextInput widgets",
          "workflowAction": {
            "inputs": [
              {
                "id": "value1",
                "description": "First user input",
                "cardinality": "SINGLE",
                "dataType": {
                  "basicType": "STRING"
                }
              },
              {
                "id": "value2",
                "description": "Second user input",
                "cardinality": "SINGLE",
                "dataType": {
                  "basicType": "STRING"
                }
              }
            ],
            "onConfigFunction": "onConfiguration",
            "onExecuteFunction": "onExecution"
          }
        }
      ]
    }
  }
}

Dưới đây là mã để định cấu hình các tiện ích TextInput bằng nhiều chế độ nhập:

Apps Script

function onConfiguration() {
  const input1 = CardService.newTextInput()
    .setFieldName("value1")
    .setId("value1")
    .setTitle("Rich Text")
    .setHostAppDataSource(
      CardService.newHostAppDataSource()
        .setWorkflowDataSource(
          CardService.newWorkflowDataSource()
            .setIncludeVariables(true)
        )
    )
    // Set input mode to RICH_TEXT to allow mixed text and variables.
    .setInputMode(CardService.TextInputMode.RICH_TEXT);

  const input2 = CardService.newTextInput()
    .setFieldName("value2")
    .setId("value2")
    .setTitle("Plain text")
    .setHostAppDataSource(
      CardService.newHostAppDataSource()
        .setWorkflowDataSource(
          CardService.newWorkflowDataSource()
            .setIncludeVariables(true)
        )
    )
    // Set input mode to PLAIN_TEXT to enforce single variable selection.
    .setInputMode(CardService.TextInputMode.PLAIN_TEXT);

  const section = CardService.newCardSection()
    .addWidget(input1)
    .addWidget(input2);

  const card = CardService.newCardBuilder()
    .addSection(section)
    .build();

  return card;
}

function onExecution(e) {
}

Tuỳ chỉnh các nút chọn biến

Bạn có thể tuỳ chỉnh nút bộ chọn biến bằng cách đặt kích thước và nhãn cho nút.

Kích thước nút

Để đặt kích thước nút, hãy dùng setVariableButtonSize() với một trong các giá trị enum VariableButtonSize sau:

  • UNSPECIFIED: Mặc định. Nút này có kích thước nhỏ gọn trong bảng điều khiển bên và có kích thước đầy đủ trong các bối cảnh khác.
  • COMPACT: Nút chỉ hiển thị dấu cộng (+).
  • FULL_SIZE: Nút này hiển thị nhãn văn bản đầy đủ.

Nhãn nút

Để đặt văn bản của nút, hãy sử dụng setVariableButtonLabel().

Ví dụ: Tuỳ chỉnh bộ chọn biến

Ví dụ sau đây minh hoạ cách định cấu hình các tiện ích TextInput với nhiều kích thước nút bộ chọn biến và nhãn tuỳ chỉnh.

  • Tuỳ chỉnh nút bộ chọn biến trên web.
    Hình 1: Tuỳ chỉnh nút chọn biến trên web.
  • Tuỳ chỉnh nút chọn biến trong bảng điều khiển bên của tiện ích bổ sung.
    Hình 2: Tuỳ chỉnh nút chọn biến trong bảng điều khiển bên của tiện ích bổ sung.

Sau đây là tệp kê khai để tuỳ chỉnh các nút chọn biến:

JSON

{
  "timeZone": "America/Los_Angeles",
  "dependencies": {},
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
    "https://www.googleapis.com/auth/script.locale"
  ],
  "addOns": {
    "common": {
      "name": "Variable button customization",
      "logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
      "useLocaleFromApp": true
    },
    "flows": {
      "workflowElements": [
        {
          "id": "variable_picker_customization",
          "state": "ACTIVE",
          "name": "Variable Picker demo",
          "description": "List all possible variable picker customization options",
          "workflowAction": {
            "onConfigFunction": "onUpdateCardConfigFunction",
            "onExecuteFunction": "onUpdateCardExecuteFunction"
          }
        }
      ]
    }
  }
}

Dưới đây là mã để tuỳ chỉnh các nút chọn biến:

Apps Script

function onUpdateCardConfigFunction(event) {
  const textInput1 = CardService.newTextInput()
    .setFieldName("value1")
    .setTitle("Regular variable picker button")
    .setHostAppDataSource(
      CardService.newHostAppDataSource().setWorkflowDataSource(
        CardService.newWorkflowDataSource()
          .setIncludeVariables(true)
          .setVariableButtonSize(CardService.VariableButtonSize.UNSPECIFIED)
      )
    );

  const textInput2 = CardService.newTextInput()
    .setFieldName("value2")
    .setTitle("Size: Unspecified")
    .setHostAppDataSource(
      CardService.newHostAppDataSource().setWorkflowDataSource(
        CardService.newWorkflowDataSource()
          .setIncludeVariables(true)
          .setVariableButtonSize(CardService.VariableButtonSize.UNSPECIFIED)
      )
    );

  const textInput3 = CardService.newTextInput()
    .setFieldName("value3")
    .setTitle("Size: Full size")
    .setHostAppDataSource(
      CardService.newHostAppDataSource().setWorkflowDataSource(
        CardService.newWorkflowDataSource()
          .setIncludeVariables(true)
          .setVariableButtonSize(CardService.VariableButtonSize.FULL_SIZE)
      )
    );

  const textInput4 = CardService.newTextInput()
    .setFieldName("value4")
    .setTitle("Size: Compact")
    .setHostAppDataSource(
      CardService.newHostAppDataSource().setWorkflowDataSource(
        CardService.newWorkflowDataSource()
          .setIncludeVariables(true)
          .setVariableButtonSize(CardService.VariableButtonSize.COMPACT)
      )
    );

  const textInput5 = CardService.newTextInput()
    .setFieldName("value5")
    .setTitle("Custom button label")
    .setHostAppDataSource(
      CardService.newHostAppDataSource().setWorkflowDataSource(
        CardService.newWorkflowDataSource()
          .setIncludeVariables(true)
          .setVariableButtonLabel("New button label!")
      )
    );

  var cardSection = CardService.newCardSection()
    .addWidget(textInput1)
    .addWidget(textInput2)
    .addWidget(textInput3)
    .addWidget(textInput4)
    .addWidget(textInput5)
    .setId("section_1");

  var card = CardService.newCardBuilder().addSection(cardSection).build();

  return card;
}

function onUpdateCardExecuteFunction(event) {
}

Định cấu hình tính năng tự động hoàn thành dữ liệu trên Google Workspace

Bạn cũng có thể điền sẵn các đề xuất tự động hoàn thành từ dữ liệu trong môi trường Google Workspace của người dùng:

  • Người dùng Google Workspace: Điền sẵn thông tin người dùng trong cùng một tổ chức Google Workspace.
  • Không gian trong Google Chat: Điền sẵn các không gian trong Google Chat mà người dùng là thành viên.

Để định cấu hình chế độ này, hãy đặt PlatformDataSource trong tiện ích SelectionInput, chỉ định WorkflowDataSourceTypeUSER hoặc SPACE.

Apps Script

// User Autocomplete
var multiSelect2 =
  CardService.newSelectionInput()
    .setFieldName("value2")
    .setTitle("User Autocomplete")
    .setType(CardService.SelectionInputType.MULTI_SELECT)
    .setMultiSelectMaxSelectedItems(3)
    .setPlatformDataSource(
      CardService.newPlatformDataSource()
        .setHostAppDataSource(
          CardService.newHostAppDataSource()
            .setWorkflowDataSource(
              CardService.newWorkflowDataSource()
                .setIncludeVariables(true)
                .setType(CardService.WorkflowDataSourceType.USER)
            ))
    );

// Chat Space Autocomplete
var multiSelect3 =
  CardService.newSelectionInput()
    .setFieldName("value3")
    .setTitle("Chat Space Autocomplete")
    .setType(CardService.SelectionInputType.MULTI_SELECT)
    .setMultiSelectMaxSelectedItems(3)
    .setPlatformDataSource(
      CardService.newPlatformDataSource()
        .setHostAppDataSource(
          CardService.newHostAppDataSource()
            .setWorkflowDataSource(
              CardService.newWorkflowDataSource()
                .setIncludeVariables(true)
                .setType(CardService.WorkflowDataSourceType.SPACE)
            ))
    );

Ví dụ: Kết hợp các loại tính năng tự động hoàn thành

Ví dụ sau đây cho thấy một hàm onConfig tạo thẻ có 3 tiện ích SelectionInput, minh hoạ tính năng tự động hoàn thành phía máy chủ, người dùng và không gian:

JSON

{
  "timeZone": "America/Los_Angeles",
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "addOns": {
    "common": {
      "name": "Autocomplete Demo",
      "logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
      "useLocaleFromApp": true
    },
    "flows": {
      "workflowElements": [
        {
          "id": "autocomplete_demo",
          "state": "ACTIVE",
          "name": "Autocomplete Demo",
          "description": "Provide autocompletion in input fields",
          "workflowAction": {
            "inputs": [
              {
                "id": "value1",
                "description": "A multi-select field with autocompletion",
                "cardinality": "SINGLE",
                "dataType": {
                  "basicType": "STRING"
                }
              }
            ],
            "onConfigFunction": "onConfigAutocomplete",
            "onExecuteFunction": "onExecuteAutocomplete"
          }
        }
      ]
    }
  }
}

Apps Script

function onConfigAutocompleteTest(event) {
  // Handle autocomplete request
  if (event.workflow && event.workflow.elementUiAutocomplete) {
    return handleAutocompleteRequest(event);
  }

  // Server-side autocomplete widget
  var multiSelect1 =
    CardService.newSelectionInput()
      .setFieldName("value1")
      .setTitle("Server Autocomplete")
      .setType(CardService.SelectionInputType.MULTI_SELECT)
      .setMultiSelectMaxSelectedItems(3)
      .addDataSourceConfig(
        CardService.newDataSourceConfig()
          .setRemoteDataSource(
            CardService.newAction().setFunctionName('getAutocompleteResults')
          )
      )
      .addDataSourceConfig(
        CardService.newDataSourceConfig()
          .setPlatformDataSource(
            CardService.newPlatformDataSource()
              .setHostAppDataSource(
                CardService.newHostAppDataSource()
                  .setWorkflowDataSource(
                    CardService.newWorkflowDataSource()
                      .setIncludeVariables(true)
                  ))
          )
      );

  // User autocomplete widget
  var multiSelect2 =
    CardService.newSelectionInput()
      .setFieldName("value2")
      .setTitle("User Autocomplete")
      .setType(CardService.SelectionInputType.MULTI_SELECT)
      .setMultiSelectMaxSelectedItems(3)
      .setPlatformDataSource(
        CardService.newPlatformDataSource()
          .setHostAppDataSource(
            CardService.newHostAppDataSource()
              .setWorkflowDataSource(
                CardService.newWorkflowDataSource()
                  .setIncludeVariables(true)
                  .setType(CardService.WorkflowDataSourceType.USER)
              ))
      );

  // Space autocomplete widget
  var multiSelect3 =
    CardService.newSelectionInput()
      .setFieldName("value3")
      .setTitle("Chat Space Autocomplete")
      .setType(CardService.SelectionInputType.MULTI_SELECT)
      .setMultiSelectMaxSelectedItems(3)
      .setPlatformDataSource(
        CardService.newPlatformDataSource()
          .setHostAppDataSource(
            CardService.newHostAppDataSource()
              .setWorkflowDataSource(
                CardService.newWorkflowDataSource()
                  .setIncludeVariables(true)
                  .setType(CardService.WorkflowDataSourceType.SPACE)
              ))
      );

  var sectionBuilder =
    CardService.newCardSection()
      .addWidget(multiSelect1)
      .addWidget(multiSelect2)
      .addWidget(multiSelect3);

  var card =
    CardService.newCardBuilder()
      .addSection(sectionBuilder)
      .build();
  return card;
}

function handleAutocompleteRequest(event) {
  var invokedFunction = event.workflow.elementUiAutocomplete.invokedFunction;
  var query = event.workflow.elementUiAutocomplete.query;

  if (invokedFunction != "getAutocompleteResults" || query == undefined || query == "") {
    return {};
  }

  // Query your data source to get results
  let autocompleteResponse = AddOnsResponseService.newUpdateWidget()
    .addSuggestion(
      query + " option 1",
      query + "_option1",
      false,
      "https://developers.google.com/workspace/add-ons/images/person-icon.png",
      "option 1 bottom text"
    )
    .addSuggestion(
      query + " option 2",
      query + "_option2",
      false,
      "https://developers.google.com/workspace/add-ons/images/person-icon.png",
      "option 2 bottom text"
    ).addSuggestion(
      query + " option 3",
      query + "_option3",
      false,
      "https://developers.google.com/workspace/add-ons/images/person-icon.png",
      "option 3 bottom text"
    );

  const modifyAction = AddOnsResponseService.newAction()
    .addModifyCard(
      AddOnsResponseService.newModifyCard()
        .setUpdateWidget(autocompleteResponse)
    );

  return AddOnsResponseService.newRenderActionBuilder()
    .setAction(modifyAction)
    .build();
}

Xác thực biến đầu vào

Tốt nhất là bạn nên xác thực để đảm bảo người dùng nhập một giá trị phù hợp. Xem phần Xác thực một biến đầu vào.