/**
* Attachment parsing and download utilities for Teams messages.
*
* Handles two types of attachments:
* - Inline images (AMS) — embedded as `
` tags in message HTML
* - File attachments (SharePoint) — referenced in `properties.files` JSON
*/
import type { TeamsToken, ImageAttachment, FileAttachment } from "../types.js";
/**
* Authorization header for AMS reads (images, transcripts).
*
* Uses the skype token when available. Newer Teams web clients don't issue
* one; AMS also accepts a Bearer token with the ic3.teams.office.com audience
* (the AMS token, or the chat Bearer token which has the same audience).
*/
export declare function amsReadAuthorization(token: TeamsToken): string;
/**
* Extract inline image attachments from message HTML content.
*
* Parses `
` tags with `itemtype="http://schema.skype.com/AMSImage"` and
* extracts the AMS object ID, URL, and dimensions from the tag attributes.
*/
export declare function parseInlineImages(content: string): ImageAttachment[];
/**
* Parse file attachments from the raw `properties.files` JSON string.
*
* File attachments are SharePoint-hosted documents, videos, and other files
* shared through Teams. They have a separate schema from inline images.
*/
export declare function parseFileAttachments(rawFiles: unknown): FileAttachment[];
/**
* Fetch an image from the AMS (Async Media Service).
*
* Returns the raw binary data and content type. Authenticates with the skype
* token, or a Bearer token when no skype token is available.
*
* @param view - AMS view name: "imgo" (compressed), "imgpsh_fullsize_anim" (full-size)
*/
export declare function fetchAmsImage(token: TeamsToken, amsObjectId: string, view?: "imgo" | "imgpsh_fullsize_anim"): Promise<{
data: Buffer;
contentType: string;
size: number;
}>;
/**
* Upload an image to the AMS (Async Media Service).
*
* Creates a new AMS object with permissions for the target conversation,
* uploads the image data, and returns the object ID that can be referenced
* in message HTML via `
` tags.
*
* Requires the AMS/IC3 Bearer token (audience: ic3.teams.office.com), not the
* middle-tier bearer or skype token.
*/
export declare function uploadAmsImage(token: TeamsToken, imageData: Buffer, fileName: string, conversationId: string): Promise<{
amsObjectId: string;
}>;
/** Response from SharePoint file upload. */
export interface SharePointUploadResult {
/** SharePoint item unique ID. */
itemId: string;
/** SharePoint site ID. */
siteId: string;
/** File name (may differ from input if conflict-renamed). */
fileName: string;
/** File extension without dot. */
fileType: string;
/** Direct SharePoint file URL. */
fileUrl: string;
/** WebDAV URL for the file. */
webDavUrl: string;
/** SharePoint site base URL. */
siteBaseUrl: string;
/** SharePoint personal site path segment (e.g. "/personal/user_domain_com/"). */
personalPath: string;
/** Sharing link URL (empty string if sharing scope is "none"). */
shareUrl: string;
/** Sharing link ID returned by the createLink API (empty string if sharing scope is "none"). */
shareId: string;
/** SharePoint drive item ID (used for the createLink API call). */
driveItemId: string;
}
/** Response from the SharePoint createLink API. */
interface SharePointSharingLink {
/** The sharing link URL that recipients can use to access the file. */
shareUrl: string;
/** The opaque sharing link ID. */
shareId: string;
}
/**
* Sharing options for the createLink API.
*
* - `{ scope: "organization" }` — anyone in the org with the link can edit.
* - `{ scope: "users", emails: [...] }` — only the named recipients can edit.
*/
export type SharingLinkOptions = {
scope: "organization";
} | {
scope: "users";
emails: string[];
};
/**
* Create a sharing link for a SharePoint file.
*
* Without this step, files uploaded to the sender's OneDrive are private —
* chat participants would see a "Request Access" prompt instead of the file.
*
* Uses the SharePoint REST API v2.0 `createLink` endpoint.
*
* @param options - Sharing scope: "organization" (anyone in the org) or
* "users" with specific recipient emails.
*/
export declare function createSharePointSharingLink(token: TeamsToken, siteBaseUrl: string, personalPath: string, driveItemId: string, options?: SharingLinkOptions): Promise;
/**
* Upload a file to SharePoint OneDrive for Business (Teams Chat Files folder).
*
* Files shared in Teams conversations are stored in the sender's OneDrive
* under "Microsoft Teams Chat Files". This function uploads a file there
* using the SharePoint REST API, matching the same flow the Teams web client uses.
*
* After uploading, a sharing link is created according to the provided
* sharing options so that chat participants can access the file.
*
* @param email - The sender's corporate email (used to derive the personal site path)
* @param sharingOptions - Controls who gets access. Pass `null` for no sharing link.
*/
export declare function uploadSharePointFile(token: TeamsToken, fileData: Buffer, fileName: string, email: string, sharingOptions?: SharingLinkOptions | null): Promise;
/**
* Build the `properties.files` JSON string for a message with file attachments.
*
* This JSON is included in the message body when sending messages with
* SharePoint-hosted file attachments.
*/
export declare function buildFilesPropertyJson(uploadResults: SharePointUploadResult[]): string;
/**
* Build an HTML `
` tag for an AMS-hosted image.
*
* This produces the same markup that the Teams web client generates.
*/
export declare function buildAmsImageTag(amsObjectId: string, width?: number, height?: number): string;
/**
* Download a file attachment from SharePoint.
*
* File attachments in Teams are hosted on SharePoint (OneDrive for Business).
* This function downloads the file content using the SharePoint REST API
* and the captured SharePoint bearer token.
*
* @param fileUrl - Direct SharePoint URL from `FileAttachment.fileUrl`
*/
export declare function fetchSharePointFile(token: TeamsToken, fileUrl: string, itemId: string): Promise<{
data: Buffer;
contentType: string;
size: number;
fileName: string;
}>;
export {};
//# sourceMappingURL=attachments.d.ts.map