AttachmentsClient
Client for uploading file attachments to Comms.
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" |
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
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 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({
file: await readFile('./diagram.png'),
fileName: 'diagram.png',
})
await api.comments.createComment({
threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
content: 'See attached',
attachments: [attachment],
})