| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| export interface FileConsentCardParams { |
| filename: string; |
| description?: string; |
| sizeInBytes: number; |
| |
| context?: Record<string, unknown>; |
| } |
|
|
| export interface FileInfoCardParams { |
| filename: string; |
| contentUrl: string; |
| uniqueId: string; |
| fileType: string; |
| } |
|
|
| |
| |
| |
| |
| export function buildFileConsentCard(params: FileConsentCardParams) { |
| return { |
| contentType: "application/vnd.microsoft.teams.card.file.consent", |
| name: params.filename, |
| content: { |
| description: params.description ?? `File: ${params.filename}`, |
| sizeInBytes: params.sizeInBytes, |
| acceptContext: { filename: params.filename, ...params.context }, |
| declineContext: { filename: params.filename, ...params.context }, |
| }, |
| }; |
| } |
|
|
| |
| |
| |
| |
| export function buildFileInfoCard(params: FileInfoCardParams) { |
| return { |
| contentType: "application/vnd.microsoft.teams.card.file.info", |
| contentUrl: params.contentUrl, |
| name: params.filename, |
| content: { |
| uniqueId: params.uniqueId, |
| fileType: params.fileType, |
| }, |
| }; |
| } |
|
|
| export interface FileConsentUploadInfo { |
| name: string; |
| uploadUrl: string; |
| contentUrl: string; |
| uniqueId: string; |
| fileType: string; |
| } |
|
|
| export interface FileConsentResponse { |
| action: "accept" | "decline"; |
| uploadInfo?: FileConsentUploadInfo; |
| context?: Record<string, unknown>; |
| } |
|
|
| |
| |
| |
| |
| export function parseFileConsentInvoke(activity: { |
| name?: string; |
| value?: unknown; |
| }): FileConsentResponse | null { |
| if (activity.name !== "fileConsent/invoke") { |
| return null; |
| } |
|
|
| const value = activity.value as { |
| type?: string; |
| action?: string; |
| uploadInfo?: FileConsentUploadInfo; |
| context?: Record<string, unknown>; |
| }; |
|
|
| if (value?.type !== "fileUpload") { |
| return null; |
| } |
|
|
| return { |
| action: value.action === "accept" ? "accept" : "decline", |
| uploadInfo: value.uploadInfo, |
| context: value.context, |
| }; |
| } |
|
|
| |
| |
| |
| |
| export async function uploadToConsentUrl(params: { |
| url: string; |
| buffer: Buffer; |
| contentType?: string; |
| fetchFn?: typeof fetch; |
| }): Promise<void> { |
| const fetchFn = params.fetchFn ?? fetch; |
| const res = await fetchFn(params.url, { |
| method: "PUT", |
| headers: { |
| "Content-Type": params.contentType ?? "application/octet-stream", |
| "Content-Range": `bytes 0-${params.buffer.length - 1}/${params.buffer.length}`, |
| }, |
| body: new Uint8Array(params.buffer), |
| }); |
|
|
| if (!res.ok) { |
| throw new Error(`File upload to consent URL failed: ${res.status} ${res.statusText}`); |
| } |
| } |
|
|