গুগল পিকার ব্যবহার করে গুগল ড্রাইভ ফাইল এবং ফোল্ডার নির্বাচন করুন

ব্যবহারকারীদের Google ড্রাইভ থেকে ফাইল বা ফোল্ডার নির্বাচন করতে দেওয়ার জন্য, আপনি Google Picker ব্যবহার করার জন্য একটি SelectionInput উইজেট কনফিগার করতে পারেন। এই নির্দেশিকাটি আপনার অ্যাড-অনের কনফিগারেশন কার্ডে Google Picker কীভাবে সেট আপ করবেন তা ব্যাখ্যা করে।

গুগল পিকার কনফিগার করুন

গুগল ড্রাইভ থেকে ফাইল বা ফোল্ডার নির্বাচন করার জন্য নির্বাচন ইনপুট উইজেট সক্ষম করতে, আপনাকে এর PlatformDataSource CommonDataSource এবং DriveDataSourceSpec দিয়ে কনফিগার করতে হবে।

  1. CommonDataSource কে DRIVE তে সেট করুন। এটি নির্বাচন ইনপুটের জন্য Google Drive কে উৎস হিসেবে মনোনীত করে।
  2. (ঐচ্ছিক) ব্যবহারকারীরা কোন ধরণের ফাইল নির্বাচন করতে পারবেন তা নির্দিষ্ট করতে, একটি DriveDataSourceSpec যোগ করুন। আপনি নিম্নলিখিত আইটেমের এক বা একাধিক প্রকার নির্দিষ্ট করতে পারেন:
    • DOCUMENTS
    • SPREADSHEETS
    • PRESENTATIONS
    • PDFS
    • FORMS
    • FOLDERS

উদাহরণ: স্প্রেডশিট এবং পিডিএফ নির্বাচন করুন

নিম্নলিখিত উদাহরণটি একটি কনফিগারেশন কার্ড তৈরি করে যা ব্যবহারকারীদের Google ড্রাইভ থেকে একাধিক স্প্রেডশিট বা PDF ফাইল নির্বাচন করতে দেয়। ধাপটি চালানোর সময়, এটি নির্বাচিত আইটেমগুলির ফাইল আইডিগুলিকে আউটপুট ভেরিয়েবল হিসাবে ফেরত দেয়।

JSON সম্পর্কে

{
  "timeZone": "America/Los_Angeles",
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "addOns": {
    "common": {
      "name": "Drive Picker Demo",
      "logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
      "useLocaleFromApp": true
    },
    "flows": {
      "workflowElements": [
        {
          "id": "file_selection",
          "state": "ACTIVE",
          "name": "File selection",
          "workflowAction": {
            "inputs": [
              {
                "id": "drive_picker_1",
                "description": "Choose a file from Google Drive",
                "dataType": {
                  "basicType": "STRING"
                }
              }
            ],
            "outputs": [
              {
                "id": "fileId",
                "description": "The id of the selected file",
                "cardinality": "SINGLE",
                "dataType": {
                  "basicType": "STRING"
                }
              }
            ],
            "onConfigFunction": "onConfig",
            "onExecuteFunction": "onExecute"
          }
        }
      ]
    }
  }
}

অ্যাপস স্ক্রিপ্ট

/**
* Returns a configuration card for the step.
* This card includes a selection input widget configured as a Google Picker
* that lets users select spreadsheets and PDFs.
*/
function onConfig() {
  // Allows users to select either spreadsheets or PDFs
  const driveSpec = CardService.newDriveDataSourceSpec()
    .addItemType(
      CardService.DriveItemType.SPREADSHEETS
    )
    .addItemType(
      CardService.DriveItemType.PDFS
    );

  const platformSource = CardService.newPlatformDataSource()
    .setCommonDataSource(
      CardService.CommonDataSource.DRIVE
    )
    .setDriveDataSourceSpec(driveSpec);

  const selectionInput =
    CardService.newSelectionInput()
      .setFieldName("drive_picker_1")
      .setPlatformDataSource(platformSource)
      .setTitle("Drive Picker")
      .setType(
        CardService.SelectionInputType.MULTI_SELECT
      );

  var sectionBuilder =
    CardService.newCardSection()
      .addWidget(selectionInput)

  return CardService.newCardBuilder()
    .addSection(sectionBuilder)
    .build();
}

/**
* Executes when the step runs.
* This function retrieves the file ID of the item selected in the Google Picker
* and returns it as an output variable.
* @param {Object} event The event object passed by the Flows runtime.
* @return {Object} The output variables object.
*/
function onExecute(event) {
  //Extract the selected file's ID during execution
  console.log("eventObject: " + JSON.stringify(event));
  var fileId = event.workflow.actionInvocation.inputs["drive_picker_1"].stringValues[0];

  const variableData = AddOnsResponseService.newVariableData()
    .addStringValue(fileId);

  let textFormatElement = AddOnsResponseService.newTextFormatElement()
    .setText("A file has been selected!");

  let workflowTextFormat = AddOnsResponseService.newWorkflowTextFormat()
    .addTextFormatElement(textFormatElement);

  let workflowAction = AddOnsResponseService.newReturnOutputVariablesAction()
    .addVariableData("fileId", variableData)
    .setLog(workflowTextFormat);

  let hostAppAction = AddOnsResponseService.newHostAppAction()
    .setWorkflowAction(workflowAction);

  return AddOnsResponseService.newRenderActionBuilder()
    .setHostAppAction(hostAppAction)
    .build();
}