chat 4.13.0 → 4.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +19 -31
  2. package/dist/{chunk-WKJEG4FE.js → chunk-THM4ACIE.js} +12 -4
  3. package/dist/chunk-THM4ACIE.js.map +1 -0
  4. package/dist/index.d.ts +409 -415
  5. package/dist/index.js +63 -29
  6. package/dist/index.js.map +1 -1
  7. package/dist/{jsx-runtime-COVsDskT.d.ts → jsx-runtime-Bdt1Dwzf.d.ts} +71 -71
  8. package/dist/jsx-runtime.d.ts +1 -1
  9. package/dist/jsx-runtime.js +1 -1
  10. package/docs/actions.mdx +98 -0
  11. package/docs/adapters/discord.mdx +217 -0
  12. package/docs/adapters/gchat.mdx +232 -0
  13. package/docs/adapters/github.mdx +225 -0
  14. package/docs/adapters/index.mdx +110 -0
  15. package/docs/adapters/linear.mdx +207 -0
  16. package/docs/adapters/meta.json +12 -0
  17. package/docs/adapters/slack.mdx +293 -0
  18. package/docs/adapters/teams.mdx +225 -0
  19. package/docs/api/cards.mdx +217 -0
  20. package/docs/api/channel.mdx +176 -0
  21. package/docs/api/chat.mdx +469 -0
  22. package/docs/api/index.mdx +29 -0
  23. package/docs/api/markdown.mdx +235 -0
  24. package/docs/api/message.mdx +163 -0
  25. package/docs/api/meta.json +14 -0
  26. package/docs/api/modals.mdx +222 -0
  27. package/docs/api/postable-message.mdx +166 -0
  28. package/docs/api/thread.mdx +186 -0
  29. package/docs/cards.mdx +213 -0
  30. package/docs/direct-messages.mdx +56 -0
  31. package/docs/emoji.mdx +77 -0
  32. package/docs/ephemeral-messages.mdx +77 -0
  33. package/docs/error-handling.mdx +147 -0
  34. package/docs/files.mdx +77 -0
  35. package/docs/getting-started.mdx +12 -0
  36. package/docs/guides/code-review-hono.mdx +248 -0
  37. package/docs/guides/discord-nuxt.mdx +237 -0
  38. package/docs/guides/meta.json +4 -0
  39. package/docs/guides/slack-nextjs.mdx +245 -0
  40. package/docs/index.mdx +92 -0
  41. package/docs/meta.json +20 -0
  42. package/docs/modals.mdx +208 -0
  43. package/docs/posting-messages.mdx +177 -0
  44. package/docs/slash-commands.mdx +110 -0
  45. package/docs/state/index.mdx +31 -0
  46. package/docs/state/ioredis.mdx +81 -0
  47. package/docs/state/memory.mdx +52 -0
  48. package/docs/state/meta.json +9 -0
  49. package/docs/state/redis.mdx +93 -0
  50. package/docs/streaming.mdx +99 -0
  51. package/docs/usage.mdx +338 -0
  52. package/package.json +10 -10
  53. package/dist/chunk-WKJEG4FE.js.map +0 -1
@@ -0,0 +1,469 @@
1
+ ---
2
+ title: Chat
3
+ description: The main entry point for creating a multi-platform chat bot.
4
+ type: reference
5
+ ---
6
+
7
+ The `Chat` class coordinates adapters, state, and event handlers. Create one instance and register handlers for different event types.
8
+
9
+ ```typescript
10
+ import { Chat } from "chat";
11
+ ```
12
+
13
+ ## Constructor
14
+
15
+ ```typescript
16
+ const bot = new Chat(config);
17
+ ```
18
+
19
+ <TypeTable
20
+ type={{
21
+ userName: {
22
+ description: 'Default bot username across all adapters.',
23
+ type: 'string',
24
+ },
25
+ adapters: {
26
+ description: 'Map of adapter name to adapter instance.',
27
+ type: 'Record<string, Adapter>',
28
+ },
29
+ state: {
30
+ description: 'State adapter for subscriptions, locking, and caching.',
31
+ type: 'StateAdapter',
32
+ },
33
+ logger: {
34
+ description: 'Logger instance or log level.',
35
+ type: 'Logger | "debug" | "info" | "warn" | "error" | "silent"',
36
+ },
37
+ streamingUpdateIntervalMs: {
38
+ description: 'Throttle interval for fallback streaming (post + edit) in milliseconds.',
39
+ type: 'number',
40
+ default: '500',
41
+ },
42
+ }}
43
+ />
44
+
45
+ ## Event handlers
46
+
47
+ ### onNewMention
48
+
49
+ Fires when the bot is @-mentioned in a thread it has **not** subscribed to. This is the primary entry point for new conversations.
50
+
51
+ ```typescript
52
+ bot.onNewMention(async (thread, message) => {
53
+ await thread.subscribe();
54
+ await thread.post("Hello!");
55
+ });
56
+ ```
57
+
58
+ <TypeTable
59
+ type={{
60
+ thread: {
61
+ description: 'The thread where the mention occurred.',
62
+ type: 'Thread',
63
+ },
64
+ message: {
65
+ description: 'The message that contains the @-mention.',
66
+ type: 'Message',
67
+ },
68
+ }}
69
+ />
70
+
71
+ ### onSubscribedMessage
72
+
73
+ Fires for every new message in a subscribed thread. Once subscribed, all messages (including @-mentions) route here instead of `onNewMention`.
74
+
75
+ ```typescript
76
+ bot.onSubscribedMessage(async (thread, message) => {
77
+ if (message.isMention) {
78
+ // User @-mentioned us in a thread we're already watching
79
+ }
80
+ await thread.post(`Got: ${message.text}`);
81
+ });
82
+ ```
83
+
84
+ ### onNewMessage
85
+
86
+ Fires for messages matching a regex pattern in **unsubscribed** threads.
87
+
88
+ ```typescript
89
+ bot.onNewMessage(/^!help/i, async (thread, message) => {
90
+ await thread.post("Available commands: !help, !status");
91
+ });
92
+ ```
93
+
94
+ <TypeTable
95
+ type={{
96
+ pattern: {
97
+ description: 'Regular expression to match against message text.',
98
+ type: 'RegExp',
99
+ },
100
+ handler: {
101
+ description: 'Handler called when the pattern matches.',
102
+ type: '(thread: Thread, message: Message) => Promise<void>',
103
+ },
104
+ }}
105
+ />
106
+
107
+ ### onReaction
108
+
109
+ Fires when a user adds or removes an emoji reaction.
110
+
111
+ ```typescript
112
+ import { emoji } from "chat";
113
+
114
+ // Filter to specific emoji
115
+ bot.onReaction([emoji.thumbs_up, emoji.heart], async (event) => {
116
+ if (event.added) {
117
+ await event.thread.post(`Thanks for the ${event.emoji}!`);
118
+ }
119
+ });
120
+
121
+ // Handle all reactions
122
+ bot.onReaction(async (event) => { /* ... */ });
123
+ ```
124
+
125
+ <TypeTable
126
+ type={{
127
+ 'event.emoji': {
128
+ description: 'Normalized emoji value (supports === comparison).',
129
+ type: 'EmojiValue',
130
+ },
131
+ 'event.rawEmoji': {
132
+ description: 'Platform-specific emoji string.',
133
+ type: 'string',
134
+ },
135
+ 'event.added': {
136
+ description: 'true if added, false if removed.',
137
+ type: 'boolean',
138
+ },
139
+ 'event.user': {
140
+ description: 'The user who reacted.',
141
+ type: 'Author',
142
+ },
143
+ 'event.thread': {
144
+ description: 'The thread where the reaction occurred.',
145
+ type: 'Thread',
146
+ },
147
+ 'event.message': {
148
+ description: 'The message that was reacted to (if available).',
149
+ type: 'Message | undefined',
150
+ },
151
+ 'event.messageId': {
152
+ description: 'The message ID that was reacted to.',
153
+ type: 'string',
154
+ },
155
+ }}
156
+ />
157
+
158
+ ### onAction
159
+
160
+ Fires when a user clicks a button or selects an option in a card.
161
+
162
+ ```typescript
163
+ // Single action
164
+ bot.onAction("approve", async (event) => {
165
+ await event.thread.post("Approved!");
166
+ });
167
+
168
+ // Multiple actions
169
+ bot.onAction(["approve", "reject"], async (event) => { /* ... */ });
170
+
171
+ // All actions
172
+ bot.onAction(async (event) => { /* ... */ });
173
+ ```
174
+
175
+ <TypeTable
176
+ type={{
177
+ 'event.actionId': {
178
+ description: 'Action ID from the button or select.',
179
+ type: 'string',
180
+ },
181
+ 'event.value': {
182
+ description: 'Optional payload value from the button.',
183
+ type: 'string | undefined',
184
+ },
185
+ 'event.user': {
186
+ description: 'User who triggered the action.',
187
+ type: 'Author',
188
+ },
189
+ 'event.thread': {
190
+ description: 'The thread containing the card.',
191
+ type: 'Thread',
192
+ },
193
+ 'event.triggerId': {
194
+ description: 'Trigger ID for opening modals (platform-specific, may expire quickly).',
195
+ type: 'string | undefined',
196
+ },
197
+ 'event.openModal': {
198
+ description: 'Open a modal form in response to this action.',
199
+ type: '(modal: ModalElement | CardJSXElement) => Promise<{ viewId: string } | undefined>',
200
+ },
201
+ }}
202
+ />
203
+
204
+ ### onModalSubmit
205
+
206
+ Fires when a user submits a modal form.
207
+
208
+ ```typescript
209
+ bot.onModalSubmit("feedback", async (event) => {
210
+ const comment = event.values.comment;
211
+ if (event.relatedThread) {
212
+ await event.relatedThread.post(`Feedback: ${comment}`);
213
+ }
214
+ });
215
+ ```
216
+
217
+ <TypeTable
218
+ type={{
219
+ 'event.callbackId': {
220
+ description: 'The callback ID specified when the modal was created.',
221
+ type: 'string',
222
+ },
223
+ 'event.values': {
224
+ description: 'Form field values keyed by input ID.',
225
+ type: 'Record<string, string>',
226
+ },
227
+ 'event.user': {
228
+ description: 'User who submitted the modal.',
229
+ type: 'Author',
230
+ },
231
+ 'event.relatedThread': {
232
+ description: 'The thread where the modal was triggered from (if available).',
233
+ type: 'Thread | undefined',
234
+ },
235
+ 'event.relatedMessage': {
236
+ description: 'The message containing the action that opened the modal.',
237
+ type: 'SentMessage | undefined',
238
+ },
239
+ 'event.relatedChannel': {
240
+ description: 'The channel where the modal was triggered from (available when opened via slash commands).',
241
+ type: 'Channel | undefined',
242
+ },
243
+ 'event.privateMetadata': {
244
+ description: 'Arbitrary string passed through the modal lifecycle.',
245
+ type: 'string | undefined',
246
+ },
247
+ }}
248
+ />
249
+
250
+ Returns `ModalResponse | undefined` to control the modal after submission:
251
+
252
+ - `{ action: "close" }` — close the modal
253
+ - `{ action: "errors", errors: { fieldId: "message" } }` — show validation errors
254
+ - `{ action: "update", modal: ModalElement }` — replace the modal content
255
+ - `{ action: "push", modal: ModalElement }` — push a new modal view onto the stack
256
+
257
+ ### onSlashCommand
258
+
259
+ Fires when a user invokes a `/command` in the message composer. Currently supported on Slack.
260
+
261
+ ```typescript
262
+ // Specific command
263
+ bot.onSlashCommand("/status", async (event) => {
264
+ await event.channel.post("All systems operational!");
265
+ });
266
+
267
+ // Multiple commands
268
+ bot.onSlashCommand(["/help", "/info"], async (event) => {
269
+ await event.channel.post(`You invoked ${event.command}`);
270
+ });
271
+
272
+ // Catch-all
273
+ bot.onSlashCommand(async (event) => {
274
+ console.log(`${event.command} ${event.text}`);
275
+ });
276
+ ```
277
+
278
+ <TypeTable
279
+ type={{
280
+ 'event.command': {
281
+ description: 'The command name (e.g., "/status").',
282
+ type: 'string',
283
+ },
284
+ 'event.text': {
285
+ description: 'Arguments after the command.',
286
+ type: 'string',
287
+ },
288
+ 'event.user': {
289
+ description: 'The user who invoked the command.',
290
+ type: 'Author',
291
+ },
292
+ 'event.channel': {
293
+ description: 'The channel where the command was invoked.',
294
+ type: 'Channel',
295
+ },
296
+ 'event.triggerId': {
297
+ description: 'Trigger ID for opening modals (time-limited).',
298
+ type: 'string | undefined',
299
+ },
300
+ 'event.openModal': {
301
+ description: 'Open a modal form in response to this command.',
302
+ type: '(modal: ModalElement | CardJSXElement) => Promise<{ viewId: string } | undefined>',
303
+ },
304
+ 'event.adapter': {
305
+ description: 'The platform adapter.',
306
+ type: 'Adapter',
307
+ },
308
+ 'event.raw': {
309
+ description: 'Platform-specific raw payload.',
310
+ type: 'unknown',
311
+ },
312
+ }}
313
+ />
314
+
315
+ ### onModalClose
316
+
317
+ Fires when a user closes a modal (requires `notifyOnClose: true` on the modal).
318
+
319
+ ```typescript
320
+ bot.onModalClose("feedback", async (event) => { /* ... */ });
321
+ ```
322
+
323
+ ### onAssistantThreadStarted
324
+
325
+ Fires when a user opens a new assistant thread (Slack Assistants API). Use this to set suggested prompts, show a status indicator, or send an initial greeting.
326
+
327
+ ```typescript
328
+ bot.onAssistantThreadStarted(async (event) => {
329
+ const slack = bot.getAdapter("slack") as SlackAdapter;
330
+ await slack.setSuggestedPrompts(event.channelId, event.threadTs, [
331
+ { title: "Get started", message: "What can you help me with?" },
332
+ ]);
333
+ });
334
+ ```
335
+
336
+ <TypeTable
337
+ type={{
338
+ 'event.threadId': {
339
+ description: 'Encoded thread ID.',
340
+ type: 'string',
341
+ },
342
+ 'event.userId': {
343
+ description: 'The user who opened the thread.',
344
+ type: 'string',
345
+ },
346
+ 'event.channelId': {
347
+ description: 'The DM channel ID.',
348
+ type: 'string',
349
+ },
350
+ 'event.threadTs': {
351
+ description: 'Thread timestamp.',
352
+ type: 'string',
353
+ },
354
+ 'event.context': {
355
+ description: 'Context about where the thread was opened (channel, team, enterprise, entry point).',
356
+ type: 'AssistantThreadContext',
357
+ },
358
+ 'event.adapter': {
359
+ description: 'The platform adapter.',
360
+ type: 'Adapter',
361
+ },
362
+ }}
363
+ />
364
+
365
+ ### onAssistantContextChanged
366
+
367
+ Fires when a user navigates to a different channel while the assistant panel is open (Slack Assistants API). Use this to update suggested prompts or context based on the new channel.
368
+
369
+ ```typescript
370
+ bot.onAssistantContextChanged(async (event) => {
371
+ const slack = bot.getAdapter("slack") as SlackAdapter;
372
+ await slack.setAssistantStatus(event.channelId, event.threadTs, "Updating context...");
373
+ });
374
+ ```
375
+
376
+ The event shape is identical to `onAssistantThreadStarted`.
377
+
378
+ ### onAppHomeOpened
379
+
380
+ Fires when a user opens the bot's Home tab in Slack. Use this to publish a dynamic Home tab view.
381
+
382
+ ```typescript
383
+ bot.onAppHomeOpened(async (event) => {
384
+ const slack = bot.getAdapter("slack") as SlackAdapter;
385
+ await slack.publishHomeView(event.userId, {
386
+ type: "home",
387
+ blocks: [{ type: "section", text: { type: "mrkdwn", text: "Welcome!" } }],
388
+ });
389
+ });
390
+ ```
391
+
392
+ <TypeTable
393
+ type={{
394
+ 'event.userId': {
395
+ description: 'The user who opened the Home tab.',
396
+ type: 'string',
397
+ },
398
+ 'event.channelId': {
399
+ description: 'The channel ID associated with the Home tab.',
400
+ type: 'string',
401
+ },
402
+ 'event.adapter': {
403
+ description: 'The platform adapter.',
404
+ type: 'Adapter',
405
+ },
406
+ }}
407
+ />
408
+
409
+ ## Utility methods
410
+
411
+ ### webhooks
412
+
413
+ Type-safe webhook handlers keyed by adapter name. Pass these to your HTTP route handler.
414
+
415
+ ```typescript
416
+ bot.webhooks.slack(request, { waitUntil });
417
+ bot.webhooks.teams(request, { waitUntil });
418
+ ```
419
+
420
+ ### getAdapter
421
+
422
+ Get an adapter instance by name.
423
+
424
+ ```typescript
425
+ const slack = bot.getAdapter("slack");
426
+ ```
427
+
428
+ ### openDM
429
+
430
+ Open a direct message thread with a user.
431
+
432
+ ```typescript
433
+ const dm = await bot.openDM("U123456");
434
+ await dm.post("Hello via DM!");
435
+
436
+ // Or with an Author object
437
+ const dm = await bot.openDM(message.author);
438
+ ```
439
+
440
+ ### channel
441
+
442
+ Get a Channel by its channel ID.
443
+
444
+ ```typescript
445
+ const channel = bot.channel("slack:C123ABC");
446
+
447
+ for await (const msg of channel.messages) {
448
+ console.log(msg.text);
449
+ }
450
+ ```
451
+
452
+ ### initialize / shutdown
453
+
454
+ Manually manage the lifecycle. Initialization happens automatically on the first webhook, but you can call it explicitly for non-webhook use cases.
455
+
456
+ ```typescript
457
+ await bot.initialize();
458
+ // ... do work ...
459
+ await bot.shutdown();
460
+ ```
461
+
462
+ ### reviver
463
+
464
+ Get a `JSON.parse` reviver that deserializes `Thread` and `Message` objects from workflow payloads.
465
+
466
+ ```typescript
467
+ const data = JSON.parse(payload, bot.reviver());
468
+ await data.thread.post("Hello from workflow!");
469
+ ```
@@ -0,0 +1,29 @@
1
+ ---
2
+ title: Overview
3
+ description: API reference for the Chat SDK core package.
4
+ type: overview
5
+ ---
6
+
7
+ Complete API reference for the `chat` package. All exports are available from the top-level import:
8
+
9
+ ```typescript
10
+ import { Chat, root, paragraph, text, Card, Button, emoji } from "chat";
11
+ ```
12
+
13
+ ## Core
14
+
15
+ | Export | Description |
16
+ |--------|-------------|
17
+ | [`Chat`](/docs/api/chat) | Main class — registers adapters, event handlers, and webhook routing |
18
+ | [`Thread`](/docs/api/thread) | Conversation thread with methods for posting, subscribing, and state |
19
+ | [`Channel`](/docs/api/channel) | Channel/conversation container that holds threads |
20
+ | [`Message`](/docs/api/message) | Normalized message with text, AST, author, and metadata |
21
+
22
+ ## Message formats
23
+
24
+ | Export | Description |
25
+ |--------|-------------|
26
+ | [`PostableMessage`](/docs/api/postable-message) | Union type accepted by `thread.post()` |
27
+ | [`Cards`](/docs/api/cards) | Rich card components — `Card`, `Text`, `Button`, `Actions`, etc. |
28
+ | [`Markdown`](/docs/api/markdown) | AST builder functions — `root`, `paragraph`, `text`, `strong`, etc. |
29
+ | [`Modals`](/docs/api/modals) | Modal form components — `Modal`, `TextInput`, `Select`, etc. |