Skip to content

Commit 6a16611

Browse files
docs: update spectrum-ts documentation for v5.0.0 (#89)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b24c5dd commit 6a16611

8 files changed

Lines changed: 215 additions & 12 deletions

File tree

docs-src/spectrum-ts/content.mdx.vel

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: "Content"
3-
description: "Build text, markdown, attachments, voice, contacts, polls, rich links, groups, replies, edits, unsends, typing indicators, rename, avatar, and platform-specific content for outgoing messages"
3+
description: "Build text, markdown, attachments, voice, contacts, polls, rich links, app link cards, groups, replies, edits, unsends, typing indicators, rename, avatar, and platform-specific content for outgoing messages"
44
---
55

66
import { TypeTooltip } from "/snippets/type-tooltip.mdx";
77

88
{% set ci = symbol("ts:spectrum-ts#ContentInput") %}
99
{% set cb = symbol("ts:spectrum-ts#ContentBuilder") %}
1010

11-
Spectrum exposes a family of content builders — `text`, `markdown`, `attachment`, `voice`, `contact`, `richlink`, `poll`, `group`, `custom`, `reaction`, `reply`, `edit`, `unsend`, `typing`, `rename`, and `avatar` — plus a string shortcut that's equivalent to `text()`. Any API that takes a <TypeTooltip name="ContentInput" type={`{{ ci.signature }}`} /> accepts a plain string or a <TypeTooltip name="ContentBuilder" type={`{{ cb.signature }}`} />.
11+
Spectrum exposes a family of content builders — `text`, `markdown`, `attachment`, `voice`, `contact`, `richlink`, `app`, `poll`, `group`, `custom`, `reaction`, `reply`, `edit`, `unsend`, `typing`, `rename`, and `avatar` — plus a string shortcut that's equivalent to `text()`. Any API that takes a <TypeTooltip name="ContentInput" type={`{{ ci.signature }}`} /> accepts a plain string or a <TypeTooltip name="ContentBuilder" type={`{{ cb.signature }}`} />.
1212

1313
## Text
1414

@@ -229,6 +229,18 @@ await space.send(richlink("https://example.com/article"));
229229
| `cover()` | `() => Promise<{ mimeType?, read(), stream() } \| undefined>` | OG image. |
230230
</Accordion>
231231

232+
## App link cards
233+
234+
Send a URL as an app-style link card. On iMessage, the URL renders as a native mini-app card; on Slack, Telegram, WhatsApp, and terminal, it falls back to the plain URL.
235+
236+
```ts
237+
import { app } from "spectrum-ts";
238+
239+
await space.send(app("https://example.com/deep-link"));
240+
```
241+
242+
Use `app()` when you want to present a link as a tappable card rather than an inline URL. For richer iMessage cards with layout control, see [Mini-app cards](/spectrum-ts/providers/imessage#mini-app-cards).
243+
232244
## Polls
233245

234246
{% set pollChoiceInput = symbol("ts:spectrum-ts#PollChoiceInput") %}

docs-src/spectrum-ts/getting-started.mdx.vel

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { TypeTooltip } from "/snippets/type-tooltip.mdx";
99

1010
## Installation
1111

12+
`spectrum-ts` is the batteries-included package — it bundles the runtime and every official provider.
13+
1214
<CodeGroup>
1315
```bash npm
1416
npm install spectrum-ts
@@ -27,6 +29,14 @@ bun add spectrum-ts
2729
```
2830
</CodeGroup>
2931

32+
For a leaner install, depend on `@spectrum-ts/core` plus only the providers you need:
33+
34+
```bash
35+
bun add @spectrum-ts/core @spectrum-ts/imessage @spectrum-ts/telegram
36+
```
37+
38+
Either way, the `spectrum-ts/providers/<platform>` import paths work as long as the matching provider package is installed.
39+
3040
Requires TypeScript 5 or later (TypeScript 6 is also supported).
3141

3242
## Core concepts
@@ -125,6 +135,21 @@ for await (const [space, message] of app.messages) {
125135

126136
Messages from every provider merge into the single `app.messages` stream. The `message.platform` field identifies the source.
127137

138+
## Logging
139+
140+
Spectrum emits structured logs across the core runtime and providers. Control the verbosity with `logLevel`:
141+
142+
```ts
143+
const app = await Spectrum({
144+
projectId: process.env.PROJECT_ID!,
145+
projectSecret: process.env.PROJECT_SECRET!,
146+
providers: [imessage.config()],
147+
logLevel: "debug",
148+
});
149+
```
150+
151+
Log output is sanitized — sensitive fields like tokens and secrets are redacted from error attributes before they reach any log destination.
152+
128153
## Telemetry
129154

130155
Spectrum has built-in [OpenTelemetry](https://opentelemetry.io/) instrumentation. Enable it by passing `telemetry: true`:

docs-src/spectrum-ts/introduction.mdx.vel

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ A user might message you in iMessage today, WhatsApp tomorrow, and your app next
2323

2424
With Spectrum, you run one agent server and add providers for the interfaces you want to support. Each provider connects a native interface to the same Spectrum API, so your agent can feel consistent everywhere.
2525

26-
Today, Spectrum supports iMessage, WhatsApp Business, Telegram, and terminal development. The same model is built for more interfaces over time: Slack, Discord, websites, apps, phone calls, meetings, and hardware like HomePod.
26+
Today, Spectrum supports iMessage, WhatsApp Business, Telegram, Slack, and terminal development. The same model is built for more interfaces over time: Discord, websites, apps, phone calls, meetings, and hardware like HomePod.
2727

2828
## Supported interfaces today
2929

@@ -39,12 +39,15 @@ Spectrum currently includes official providers for:
3939
<Card title="Telegram" icon="paper-plane" href="/spectrum-ts/providers/telegram">
4040
Build bots on the Telegram Bot API with inbound webhooks through Fusor.
4141
</Card>
42+
<Card title="Slack" icon="hashtag" href="/spectrum-ts/providers/slack">
43+
Connect to Slack workspaces through the Slack API.
44+
</Card>
4245
<Card title="Terminal" icon="terminal" href="/spectrum-ts/providers/terminal">
4346
Build, test, and demo agents from your local terminal.
4447
</Card>
4548
</CardGroup>
4649

47-
You can also build custom providers with `definePlatform`. Use custom providers to bring websites, apps, Slack, Discord, internal tools, or new device interfaces into Spectrum.
50+
You can also build custom providers with `definePlatform`. Use custom providers to bring websites, apps, Discord, internal tools, or new device interfaces into Spectrum.
4851

4952
<Card title="View all providers" icon="plug" href="/spectrum-ts/providers">
5053
See the built-in providers and learn how to combine them.

docs-src/spectrum-ts/providers.mdx.vel

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Providers plug into Spectrum's type system and runtime. Each one exports a calla
2020
<Card title="Telegram" icon="paper-plane" href="/spectrum-ts/providers/telegram">
2121
Telegram Bot API with Fusor webhooks. Text, media, reactions, replies, typing, and edits.
2222
</Card>
23+
<Card title="Slack" icon="hashtag" href="/spectrum-ts/providers/slack">
24+
Slack API with multi-workspace support. Text, media, reactions, replies, typing, and threads.
25+
</Card>
2326
</CardGroup>
2427

2528
## Combining providers
@@ -30,7 +33,7 @@ Drop any combination into `providers`:
3033
<Tab title="Aggregate import">
3134
```ts
3235
import { Spectrum } from "spectrum-ts";
33-
import { imessage, terminal, whatsappBusiness } from "spectrum-ts/providers";
36+
import { imessage, slack, terminal, whatsappBusiness } from "spectrum-ts/providers";
3437

3538
const app = await Spectrum({
3639
projectId: "...",
@@ -42,6 +45,9 @@ Drop any combination into `providers`:
4245
phoneNumberId: process.env.WA_NUMBER_ID!,
4346
appSecret: process.env.WA_SECRET!,
4447
}),
48+
slack.config({
49+
tokens: { TEAM_ID: process.env.SLACK_BOT_TOKEN! },
50+
}),
4551
terminal.config(),
4652
],
4753
});
@@ -51,6 +57,7 @@ Drop any combination into `providers`:
5157
```ts
5258
import { Spectrum } from "spectrum-ts";
5359
import { imessage } from "spectrum-ts/providers/imessage";
60+
import { slack } from "spectrum-ts/providers/slack";
5461
import { terminal } from "spectrum-ts/providers/terminal";
5562
import { whatsappBusiness } from "spectrum-ts/providers/whatsapp-business";
5663

@@ -64,6 +71,9 @@ Drop any combination into `providers`:
6471
phoneNumberId: process.env.WA_NUMBER_ID!,
6572
appSecret: process.env.WA_SECRET!,
6673
}),
74+
slack.config({
75+
tokens: { TEAM_ID: process.env.SLACK_BOT_TOKEN! },
76+
}),
6777
terminal.config(),
6878
],
6979
});

docs-src/spectrum-ts/providers/imessage.mdx.vel

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,34 @@ const sent = await space.send(customizedMiniApp({
318318
Mini-app cards require cloud or dedicated mode. In local mode, `customizedMiniApp()` throws an `UnsupportedError`.
319319
</Note>
320320

321+
## Native contact card sharing
322+
323+
Share the bot account's own iMessage contact card directly in a chat. Use `nativeContactCard()` to build the content, or the `space.shareContactCard()` sugar method on a narrowed iMessage space:
324+
325+
<Tabs>
326+
<Tab title="Sugar (space.shareContactCard)">
327+
```ts
328+
import { imessage } from "spectrum-ts/providers/imessage";
329+
330+
const im = imessage(space);
331+
await im.shareContactCard();
332+
```
333+
</Tab>
334+
<Tab title="Canonical (space.send)">
335+
```ts
336+
import { nativeContactCard, imessage } from "spectrum-ts/providers/imessage";
337+
338+
await space.send(nativeContactCard());
339+
```
340+
</Tab>
341+
</Tabs>
342+
343+
This shares the bot's own contact card as it appears in iMessage — recipients can tap it to save the contact. Useful for onboarding flows where you want users to add your bot to their contacts.
344+
345+
<Note>
346+
Native contact card sharing requires cloud or dedicated mode. In local mode, `nativeContactCard()` throws an `UnsupportedError`.
347+
</Note>
348+
321349
## Fetching attachments
322350

323351
Retrieve an attachment by its iMessage GUID using `getAttachment` on the narrowed platform instance. The returned `Attachment` is lazy — `.read()` and `.stream()` each trigger an independent download, so cache `.read()` if you need the bytes more than once.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
title: "Slack"
3+
description: "Send and receive messages through the Slack API"
4+
---
5+
6+
```ts
7+
import { slack } from "spectrum-ts/providers/slack";
8+
```
9+
10+
The Slack provider connects your agent to Slack workspaces through the Slack API. It supports multi-workspace installations, text and media messaging, reactions, threaded replies, typing indicators, and edits.
11+
12+
## Config
13+
14+
<Tabs>
15+
<Tab title="Single workspace">
16+
```ts
17+
slack.config({
18+
tokens: {
19+
TEAM_ID: "xoxb-your-bot-token",
20+
},
21+
});
22+
```
23+
</Tab>
24+
<Tab title="Multi-workspace">
25+
```ts
26+
slack.config({
27+
tokens: {
28+
TEAM_A: process.env.SLACK_TOKEN_A!,
29+
TEAM_B: process.env.SLACK_TOKEN_B!,
30+
},
31+
teams: {
32+
TEAM_A: {
33+
appId: "A0123456789",
34+
botUserId: "U0123456789",
35+
grantedScopes: ["chat:write", "channels:history"],
36+
teamName: "Team A",
37+
},
38+
TEAM_B: {
39+
appId: "A9876543210",
40+
botUserId: "U9876543210",
41+
grantedScopes: ["chat:write", "channels:history"],
42+
teamName: "Team B",
43+
},
44+
},
45+
});
46+
```
47+
</Tab>
48+
</Tabs>
49+
50+
| Option | Description |
51+
|---|---|
52+
| `tokens` | A map of team ID to bot token (`xoxb-...`). At least one entry is required. |
53+
| `teams` | Optional metadata per team — app ID, bot user ID, granted scopes, and display name. |
54+
| `endpoint` | Optional custom Slack API base URL. |
55+
56+
## Example
57+
58+
```ts
59+
import { Spectrum } from "spectrum-ts";
60+
import { slack } from "spectrum-ts/providers/slack";
61+
62+
const app = await Spectrum({
63+
projectId: process.env.PROJECT_ID!,
64+
projectSecret: process.env.PROJECT_SECRET!,
65+
providers: [
66+
slack.config({
67+
tokens: { TEAM_ID: process.env.SLACK_BOT_TOKEN! },
68+
}),
69+
],
70+
});
71+
72+
for await (const [space, message] of app.messages) {
73+
if (message.content.type === "text") {
74+
await space.send(`Echo: ${message.content.text}`);
75+
}
76+
}
77+
```
78+
79+
## Starting a conversation
80+
81+
Resolve a user by their Slack user ID and open a space. Pass `teamId` as a space parameter to target a specific workspace:
82+
83+
```ts
84+
const sl = slack(app);
85+
const user = await sl.user("U0123456789");
86+
const space = await sl.space.create(user, { teamId: "TEAM_ID" });
87+
88+
await space.send("Hello from Spectrum.");
89+
```
90+
91+
## Space properties
92+
93+
Slack spaces carry a `teamId` field indicating which workspace the conversation belongs to. Access it through narrowing:
94+
95+
```ts
96+
for await (const [space, message] of app.messages) {
97+
if (message.platform !== "Slack") continue;
98+
const slackSpace = slack(space);
99+
console.log(slackSpace.teamId);
100+
}
101+
```
102+
103+
## Message extras
104+
105+
Narrowed Slack messages expose additional fields:
106+
107+
| Field | Type | Description |
108+
|---|---|---|
109+
| `isFromMe` | `boolean` | Whether the message was sent by the bot. |
110+
| `subtype` | `string` (optional) | Slack message subtype (e.g. `"bot_message"`). |
111+
| `threadTs` | `string` (optional) | Thread timestamp if the message is in a thread. |
112+
| `ts` | `string` (optional) | Message timestamp. |
113+
114+
## Supported features
115+
116+
| Feature | Support |
117+
|---|---|
118+
| Text messages | Send and receive |
119+
| Markdown | Send (rendered as Slack mrkdwn) |
120+
| Media (files, images) | Send and receive |
121+
| Reactions | Send and receive |
122+
| Threaded replies | Send and receive |
123+
| Typing indicators | Send |
124+
| Message edits | Send and receive |

docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"spectrum-ts/providers/imessage",
4444
"spectrum-ts/providers/terminal",
4545
"spectrum-ts/providers/whatsapp-business",
46-
"spectrum-ts/providers/telegram"
46+
"spectrum-ts/providers/telegram",
47+
"spectrum-ts/providers/slack"
4748
]
4849
},
4950
{

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)