Class PlatformDataSource

平台数据

对于使用多选菜单的 SelectionInput widget,需要使用 Google Workspace 中的数据源。用于填充多选菜单中的项。

const platformDataSource =
    CardService.newPlatformDataSource().setCommonDataSource(
        CardService.CommonDataSource.USER,
    );

const multiSelect = CardService.newSelectionInput()
                        .setType(CardService.SelectionInputType.MULTI_SELECT)
                        .setFieldName('contacts')
                        .setTitle('Selected contacts')
                        .setMultiSelectMaxSelectedItems(5)
                        .setMultiSelectMinQueryLength(1)
                        .setPlatformDataSource(platformDataSource);

仅适用于 Google Chat 应用。不适用于 Google Workspace 加购项。

方法

方法返回类型简介
setCommonDataSource(commonDataSource)PlatformDataSource设置 Google Workspace 中的数据源。
setDriveDataSourceSpec(driveDataSourceSpec)PlatformDataSource从 Google Workspace 设置云端硬盘数据源规范。
setHostAppDataSource(hostAppDataSource)PlatformDataSource用于填充多选菜单中的聊天室。

详细文档

setCommonDataSource(commonDataSource)

设置 Google Workspace 中的数据源。

const platformDataSource =
    CardService.newPlatformDataSource().setCommonDataSource(
        CardService.CommonDataSource.USER,
    );

const multiSelect = CardService.newSelectionInput()
                        .setType(CardService.SelectionInputType.MULTI_SELECT)
                        .setFieldName('contacts')
                        .setTitle('Selected contacts')
                        .setMultiSelectMaxSelectedItems(5)
                        .setMultiSelectMinQueryLength(1)
                        .setPlatformDataSource(platformDataSource);
仅适用于 Google Chat 应用。不适用于 Google Workspace 加购项。

参数

名称类型说明
commonDataSourceCommonDataSource要设置的数据源。

返回

PlatformDataSource - 此对象,用于链式调用。


setDriveDataSourceSpec(driveDataSourceSpec)

从 Google Workspace 设置云端硬盘数据源规范。

const driveDataSourceSpec =
    CardService.newDriveDataSourceSpec()
      .addItemType(CardService.DriveItemType.DOCUMENTS)
      .addItemType(CardService.DriveItemType.FORMS);

const platformDataSource =
    CardService.newPlatformDataSource().setCommonDataSource(
        CardService.CommonDataSource.DRIVE
    ).setDriveDataSourceSpec(driveDataSourceSpec);

const multiSelect = CardService.newSelectionInput()
                        .setType(CardService.SelectionInputType.MULTI_SELECT)
                        .setFieldName('files')
                        .setTitle('Drive Files')
                        .setMultiSelectMaxSelectedItems(5)
                        .setMultiSelectMinQueryLength(1)
                        .setPlatformDataSource(platformDataSource);
适用于 Google Chat 应用。对于 Google Workspace 插件,需要在清单中添加每个文件的访问范围(https://www.googleapis.com/auth/drive.file)。

参数

名称类型说明
driveDataSourceSpecDriveDataSourceSpec要设置的云端硬盘数据源规范。

返回

PlatformDataSource - 此对象,用于链式调用。


setHostAppDataSource(hostAppDataSource)

用于填充多选菜单中的聊天室。

const chatSpaceDataSource =
    CardService.newChatSpaceDataSource().setDefaultToCurrentSpace(true);

const chatClientDataSource =
    CardService.newChatClientDataSource().setSpaceDataSource(
        chatSpaceDataSource);

const hostAppDataSource =
    CardService.newHostAppDataSource().setChatDataSource(chatClientDataSource);

const platformDataSource =
    CardService.newPlatformDataSource().setHostAppDataSource(hostAppDataSource);

const multiSelect = CardService.newSelectionInput()
                        .setType(CardService.SelectionInputType.MULTI_SELECT)
                        .setFieldName('contacts')
                        .setTitle('Selected contacts')
                        .setMultiSelectMaxSelectedItems(5)
                        .setMultiSelectMinQueryLength(1)
                        .setPlatformDataSource(platformDataSource);
仅适用于 Google Chat 应用。不适用于 Google Workspace 加购项。

参数

名称类型说明
hostAppDataSourceHostAppDataSource要设置的数据源。

返回

PlatformDataSource - 此对象,用于链式调用。