import type { HttpClient } from '../../http'; import type { CreateMediaUploadPayload, MediaKind, MediaUpload } from '../../types/inbox'; /** What `uploadMedia` needs about a file, when it is not a `File` or `Blob`. */ export interface UploadMediaSource { /** The bytes. A browser `File` or `Blob`, or anything `fetch` accepts as a body. */ body: BodyInit; filename: string; contentType: string; /** Exact byte length. Must match the bytes, because the signature covers it. */ size: number; } export interface UploadMediaOptions { /** Which kind of message this will become. Decides the size and type limits. */ kind: MediaKind; /** Overrides the name taken from a `File`; required for a bare `Blob` or buffer. */ filename?: string; /** Overrides the type taken from a `File`. */ contentType?: string; signal?: AbortSignal; } /** * Chat media. * * Uploads do not pass through the API. A client describes the file, gets a * presigned URL, and sends the bytes straight to object storage -- so a 90 MB * document costs the gateway a signature rather than 90 MB of transfer, and a * stalled upload holds the browser's connection rather than one of ours. */ export declare class InboxMedia { private readonly http; constructor(http: HttpClient); /** * `POST /v1/audience/inbox/media/upload-url` -- one presigned upload. * * Metadata only; no bytes. Prefer `upload()`, which does this and the transfer * together. Reach for this directly when you need the `key`, or when something * other than this SDK will perform the upload. * * `size` and `content_type` are signed into the URL, so the upload that follows * has to match them exactly. They are also checked against the kind's limits * here rather than at send time -- a file rejected now is one the agent can * swap, where one rejected by the provider has already been uploaded and drawn * on screen. * * | Kind | Limit | Accepts | * |---|---|---| * | `image` | 5 MB | jpeg, png, webp | * | `video` | 16 MB | mp4, 3gpp, quicktime | * | `audio` / `voice` | 16 MB | aac, mp4, mpeg, amr, ogg | * | `sticker` | 100 KB | webp | * | `document` | 100 MB | anything a browser will not execute | * * 422 `validation_failed` if the file is too large or the type is not allowed * for the kind. 503 `media_unavailable` if the deployment has no storage * configured. * * Scope: `messages:write`. */ createUpload(payload: CreateMediaUploadPayload): Promise; /** * Uploads a file and answers with its permanent public link. * * Three steps, one call: ask for a ticket, `PUT` the bytes to storage, return * the link. Pass the link straight to `inbox.messages.sendMedia()`, or as the * `link` on media content you build yourself. * * ```ts * const link = await crm.inboxMedia.upload(file, { kind: 'image' }); * await inbox.messages.sendMedia({ channel, contact, kind: 'image', link, caption: 'Your order' }); * ``` * * In Node, where there is no `File`, describe the bytes instead: * * ```ts * const bytes = await readFile('invoice.pdf'); * const link = await crm.inboxMedia.upload( * { body: bytes, filename: 'invoice.pdf', contentType: 'application/pdf', size: bytes.byteLength }, * { kind: 'document' }, * ); * ``` * * The returned link does not expire -- only the upload URL does, and only * before it is used. So the link can be stored against the message and will * still render in the thread months later. * * The `PUT` deliberately does not go through this SDK's request pipeline: it * carries no bearer token, because that would hand our credential to the * storage provider, and it sends exactly the headers the ticket named, because * the signature covers them and one extra header fails the upload. */ upload(file: Blob | UploadMediaSource, options: UploadMediaOptions): Promise; }