import { BotAttachment } from '../models/BotAttachment'; import { IAttachment } from './DirectLineTypes'; interface IFileManager { /** * Uploads a file. * @param files Array of IFileUploadRequest which contains information about each file to upload. * @returns An array of uploaded files which contains the file id and optional metadata. */ uploadFiles(files: IFileUploadRequest[]): Promise; /** * Downloads a file. * @param files Array of IUploadedFile to download the files. * @returns Array of File objects. */ downloadFiles(files: IUploadedFile[]): Promise; /** * Sets file permissions. * @param file * @param permissions */ updatePermissions(file: IUploadedFile, permissions: PermissionsOptions): Promise; /** * Retrieve the property from ChatMessage metadata that contains the file ids. * This is the same property constructed by createFileIdProperty(), and sent as part of the message. * @param metadata The metadata property from a ChatMessage, ChatMessageReceivedEvent, or ChatMessageEditedEvent. * @returns An array of strings that represent the file ids. */ getFileIds(metadata?: Record): string[] | undefined; /** * Construct the property that contains the file ids for a send chat message request. * It is added to the send message request and is the same property returned by getFileIdProperty(). * @param fileIds The file ids to set in the property. * @returns A record where the key is the property name and the value is the stringified array of file ids. */ createFileIdProperty(fileIds: string[]): Record; /** * Retrieve the property from ChatMessage metadata that contains the optional file metadata. * This is the same property constructed by createFileMetadataProperty(), and sent as part of the message. * @param metadata The metadata property from a ChatMessage, ChatMessageReceivedEvent, or ChatMessageEditedEvent. * @returns An array of FileMetadata. */ getFileMetadata(metadata?: Record): FileMetadata[] | undefined; /** * Construct the property that contains the optional metadata for each file, for a send chat message request. * It is added to the send message request and is the same property returned by getFileMetadataProperty(). * @param metadata The array of metadata to set in the property. * @returns A record where the key is the property name and the value is the stringified array of metadata. */ createFileMetadataProperty(metadata: FileMetadata[]): Record; /** * Construct an attachment object adhering to bot activity attachment type. * It is added to the send message request in serialized form. If there are no files and metadata, return null. * @param metadata The array of metadata to set in the property. * @returns A bot attachment object adhering to bot activity schema. */ createBotAttachment(metadata?: Record): BotAttachment; } interface PermissionsOptions { /** * User id(s) */ users: string[]; /** * File permission */ permission: FilePermission; } enum FilePermission { READ, WRITE } /** * Contains information to upload a file. */ interface IFileUploadRequest extends IAttachment { permissions?: PermissionsOptions; } interface IUploadedFile { /** * Id to reference the file, generated by the storage provider. */ fileId: string; /** * Optional additional file metadata. */ metadata?: FileMetadata; } /** * File metadata. */ type FileMetadata = Record; export type { IFileManager, IUploadedFile, IFileUploadRequest, PermissionsOptions, FileMetadata };