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
| Parameter | Type |
|---|---|
config | ClientConfig |
Returns
AttachmentsClient
Inherited from
BaseClient.constructor
Properties
| Property | Modifier | Type |
|---|---|---|
apiToken | readonly | string |
baseUrl? | readonly | string |
customFetch? | readonly | CustomFetch |
defaultVersion | readonly | "v1.0" |
headers? | readonly | CustomHeaders |
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
| Parameter | Type | Description |
|---|---|---|
uploadId | string | The upload ID of the image. |
conversationId | string | The 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
| Parameter | Type |
|---|---|
uploadId | string |
threadId | string |
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
| Parameter | Type | Description |
|---|---|---|
args | UploadAttachmentArgs | The 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],
})