Skip to content
SegmentStream/ Docs

Loading documentation…

↑ ↓ to navigate  ↵ to open  Esc to close
Website Console
Section menu

@segmentstream/ontology/slack

28 public exports from @segmentstream/ontology/slack.

Public exports

CHANNEL_FILE_FRAME_BYTES

The most bytes a call sends before, and the most after, the stored file it carries.

const CHANNEL_FILE_FRAME_BYTES: number
ChannelAnswerError

The provider's answer to a call that did not prove its message sent, kept whole for operators: its status and its body, such as Telegram's `description` or Meta's error. Whoever logs it redacts it.

class ChannelAnswerError extends Error {
    readonly status: number;
    readonly name = "ChannelAnswerError";
    readonly answer: unknown;
    constructor(message: string, status: number, reply: Pick<ChannelReply, "body">);
}
ChannelCall

One HTTP request through a connection: one of its APIs, a path relative to its base URL.

interface ChannelCall {
    readonly api: string;
    readonly method: "GET" | "POST" | "PUT";
    readonly path: string;
    readonly headers: ReadonlyArray<readonly [
        string,
        string
    ]>;
    readonly body: Uint8Array;
    readonly file?: ChannelCallFile;
}
ChannelCallFile

The body of a call that carries a stored file: `prefix`, the file's bytes from `start` to `end` inclusive, read by the connection by the file's signed read, then `suffix`, such as a multipart form's fields and its closing boundary around the file's part. Each of `prefix` and `suffix` is at most {@link CHANNEL_FILE_FRAME_BYTES}.

interface ChannelCallFile extends ChannelFileRead {
    readonly start: number;
    readonly end: number;
    readonly prefix?: Uint8Array;
    readonly suffix?: Uint8Array;
}
ChannelDeliverFile

A file the ontology hands an agent's channel to deliver with a message: by a short-lived link to the workspace's file storage, granted just before the message is handed over, which the channel reads it by. `size` is the revision's the ontology checked: bytes of another size are not it.

interface ChannelDeliverFile {
    readonly filename: string;
    readonly content_type: string;
    readonly size: number;
    readonly url: string;
}
ChannelDeliveredFile

What became of one file of a delivery, by its index among the files the request named.

interface ChannelDeliveredFile {
    readonly index: number;
    readonly status: "sent" | "uncertain" | "failed";
    readonly message_id: string | null;
}
ChannelFile

A file read from storage, which the channel uploads.

interface ChannelFile {
    readonly filename: string;
    readonly contentType: string;
    readonly bytes: Uint8Array;
}
ChannelFileRead

A signed read of a file in the workspace's file storage, valid for about a minute.

interface ChannelFileRead {
    readonly url: string;
    readonly headers: ReadonlyArray<readonly [
        string,
        string
    ]>;
}
ChannelPart

What became of one visible message, or one step before any, a sender attempted: - `sent`: the provider's answer proves it; - `failed`: nothing of it reached the person; - `uncertain`: it may have.

interface ChannelPart {
    readonly files: ReadonlyArray<number>;
    readonly text: boolean;
    readonly status: "sent" | "failed" | "uncertain";
    readonly messageIds: ReadonlyArray<string>;
    readonly code?: string;
    readonly cause?: unknown;
}
ChannelReply

The provider's answer, as the connection relayed it.

interface ChannelReply {
    readonly status: number;
    readonly headers: ReadonlyArray<readonly [
        string,
        string
    ]>;
    readonly body: Uint8Array;
}
ChannelRequest

Sends one call. It rejects when the connection could not relay it; whether that proves the provider never saw it is for the caller's `definite` to say.

type ChannelRequest = (call: ChannelCall) => Promise<ChannelReply>;
ChannelStoredFile

A file the channel sends without its bytes passing through the sender: they stay in the workspace's file storage, which the provider's request reads by a signed read asked for just before it. A file too large for a request's own body goes this way.

interface ChannelStoredFile {
    readonly filename: string;
    readonly contentType: string;
    readonly size: number;
    readonly read: () => Promise<ChannelFileRead>;
}
DefiniteFailure

Whether a request the connection did not relay proves the provider never saw it.

type DefiniteFailure = (error: unknown) => boolean;
SLACK_FILES_PER_MESSAGE

The most files one `files.completeUploadExternal` shares.

const SLACK_FILES_PER_MESSAGE = 10
SLACK_FILE_BYTES

The most bytes of one file a single connection request carries to Slack.

const SLACK_FILE_BYTES: number
SLACK_MESSAGE_LIMIT

The most characters Slack accepts in `chat.postMessage`'s `markdown_text`.

const SLACK_MESSAGE_LIMIT = 12000
SLACK_POSSIBLY_POSTED

Slack's `ok: false` codes that do not prove a message or a share was not posted: Slack says some of the operation may have succeeded before the error. Every other code proves nothing was.

const SLACK_POSSIBLY_POSTED: ReadonlySet<string>
SLACK_UPLOAD_BYTES

The most bytes Slack takes of one file, as an upload straight to its address may send.

const SLACK_UPLOAD_BYTES: number
SlackDeliver

One message for the agent's Slack channel to send (`POST` {@link slackDeliverRoute}).

interface SlackDeliver {
    readonly operation_id: string;
    readonly connection: string;
    readonly channel: string;
    readonly thread_ts: string | null;
    readonly message?: SlackDeliverMessage;
    readonly initial_comment?: string;
    readonly files?: ReadonlyArray<ChannelDeliverFile>;
}
SlackDeliverMessage

One message as `chat.postMessage` takes it, without where it goes: the Markdown as `markdown_text`, or, with buttons, the text for notifications and the `blocks` that show the Markdown and each row of buttons.

type SlackDeliverMessage = {
    readonly markdown_text: string;
} | {
    readonly text: string;
    readonly blocks: ReadonlyArray<Readonly<Record<string, unknown>>>;
};
SlackDeliverRefused

Why the agent sent nothing (`4xx`): `channel_unknown` when it has no Slack channel of the name on the connection, so the ontology sends the message itself; `provider_refused` when Slack refused it, or refused a file, so that nothing was shared; `connection_refused` when SegmentStream's connection refused the call; or the request's own fault, such as `invalid_request` or `file_too_large`.

interface SlackDeliverRefused {
    readonly error: string;
    readonly reference?: string;
}
SlackDelivered

The agent's answer once it sent something: `sent` when Slack's answer proves the message, or the share of the files, posted; `uncertain` when it may have, with what became of each file. A `4xx` with {@link SlackDeliverRefused} sent nothing (`404` alone: an agent without the route); anything else may have sent it.

interface SlackDelivered {
    readonly status: "sent" | "uncertain";
    readonly message_id: string | null;
    readonly files?: ReadonlyArray<ChannelDeliveredFile>;
    readonly reference?: string;
}
SlackFilesResult

What Slack's upload of the files and its share became.

interface SlackFilesResult {
    readonly uploads: ReadonlyArray<{
        readonly index: number;
        readonly slackFileId: string;
    } | {
        readonly index: number;
        readonly code: string;
        readonly cause: unknown;
    }>;
    readonly share?: ChannelPart;
}
escapeSlackMarkdown

Text that Slack's Markdown shows as it is: every character it could read as syntax escaped.

function escapeSlackMarkdown(text: string): string;
renderSlack

The member's exact Markdown, which Slack renders, then the separator and the attribution as literal text, the attribution in italics. Neither can open or close a construct of the member's Markdown.

function renderSlack(markdown: string, attribution: string, separator?: string): string;
sendSlackFiles

Uploads `files`, then shares those that uploaded in `channel`, in `threadTs` when given, with `text` as the message's text. The share is `sent` when Slack confirms it, `failed` when Slack refused it with a code that proves nothing was posted, otherwise `uncertain`. Nothing is retried. A stored file uploads only straight to Slack, with `fetch`; without it, it is not uploaded (`unsupported`).

function sendSlackFiles(options: {
    readonly request: ChannelRequest;
    readonly fetch?: typeof fetch;
    readonly channel: string;
    readonly threadTs?: string;
    readonly files: ReadonlyArray<(ChannelFile | ChannelStoredFile) & {
        readonly index?: number;
    }>;
    readonly text?: string;
    readonly requireAll?: boolean;
    readonly definite?: DefiniteFailure;
}): Promise<SlackFilesResult>;
slackDeliverRoute

Where the agent's Slack channel `name` delivers a message the ontology sends: a draft a member approved, a reply its review let go, a member's or a service's post. The ontology decides and renders it, its exact Markdown with its attribution and its buttons; the channel sends it through its app as given, in one operation. Only the deployment's own functions may call it.

function slackDeliverRoute(name: string): string;
slackFileRefusal

Why Slack cannot take this file through one connection request, or, uploaded straight to its address (`direct`), at all; undefined when it can.

function slackFileRefusal(file: {
    readonly size: number;
}, options?: {
    readonly direct?: boolean;
}): {
    readonly code: "too_large" | "empty";
    readonly message: string;
} | undefined;