Skip to main content

AttachmentsClient

Client for uploading attachments and reading thread and conversation images.

Attachments are uploaded independently, then referenced by passing the returned Attachment into the attachments array of comments.createComment, conversationMessages.createMessage, and similar calls.

Extends​

  • BaseClient

Constructors​

Constructor​

new AttachmentsClient(config: ClientConfig): AttachmentsClient;

Parameters​

ParameterType
configClientConfig

Returns​

AttachmentsClient

Inherited from​

BaseClient.constructor

Properties​

PropertyModifierType
apiTokenreadonlystring
baseUrl?readonlystring
customFetch?readonlyCustomFetch
defaultVersionreadonly"v1.0"
headers?readonlyCustomHeaders

Methods​

getBaseUri()​

protected getBaseUri(): string;

Returns the base URI for an API request, with a guaranteed trailing slash so relative paths resolve cleanly through URL.

Returns​

string

Inherited from​

BaseClient.getBaseUri

getLinkBaseUrl()​

protected getLinkBaseUrl(): string | undefined;

Base URL for entity web links, or undefined to use getFullCommsURL's default web app. Trailing-slash normalization happens in getFullCommsURL, so the configured value is returned verbatim.

Returns​

string | undefined

Inherited from​

BaseClient.getLinkBaseUrl

readConversationImage()​

readConversationImage(uploadId: string, conversationId: string): Promise<{
byteLength: number;
dataBase64: string;
mimeType: "image/png" | "image/jpeg" | "image/webp";
}>;

Read one image sent in a conversation, under the caller's messages scope.

The caller must be a member of the conversation, and the upload must belong to it.

Parameters​

ParameterTypeDescription
uploadIdstringThe upload ID of the image.
conversationIdstringThe conversation the image was sent in.

Returns​

Promise<{ byteLength: number; dataBase64: string; mimeType: "image/png" | "image/jpeg" | "image/webp"; }>

The image as base64, with its media type and size in bytes.


readImage()​

readImage(uploadId: string, threadId: string): Promise<{
byteLength: number;
dataBase64: string;
mimeType: "image/png" | "image/jpeg" | "image/webp";
}>;

Read one thread image under the caller's content scope.

Parameters​

ParameterType
uploadIdstring
threadIdstring

Returns​

Promise<{ byteLength: number; dataBase64: string; mimeType: "image/png" | "image/jpeg" | "image/webp"; }>


upload()​

upload(args: UploadAttachmentArgs): Promise<{
[key: string]: unknown;
attachmentId: string;
description?: string | null;
duration?: string | null;
fileName?: string | null;
fileSize?: number | null;
image?: string | null;
imageHeight?: number | null;
imageWidth?: number | null;
title?: string | null;
underlyingType?: string | null;
uploadState?: string | null;
url?: string | null;
urlType: string;
video?: string | null;
videoAutoPlay?: boolean | null;
videoType?: string | null;
}>;

Uploads a file and returns the created Attachment.

Mirrors the canonical multipart upload: POST /attachments/upload with the file binary plus workspace_id, file_name, file_size, attachment_id, and underlying_type form fields.

Parameters​

ParameterTypeDescription
argsUploadAttachmentArgsThe file to upload and optional metadata.

Returns​

Promise<{ [key: string]: unknown; attachmentId: string; description?: string | null; duration?: string | null; fileName?: string | null; fileSize?: number | null; image?: string | null; imageHeight?: number | null; imageWidth?: number | null; title?: string | null; underlyingType?: string | null; uploadState?: string | null; url?: string | null; urlType: string; video?: string | null; videoAutoPlay?: boolean | null; videoType?: string | null; }>

The created attachment, ready to attach to a comment or message.

Example​

import { readFile } from 'node:fs/promises'

const attachment = await api.attachments.upload({
workspaceId: 12345,
file: await readFile('./diagram.png'),
fileName: 'diagram.png',
})

await api.comments.createComment({
threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
content: 'See attached',
attachments: [attachment],
})