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.
- package/README.md +19 -31
- package/dist/{chunk-WKJEG4FE.js → chunk-THM4ACIE.js} +12 -4
- package/dist/chunk-THM4ACIE.js.map +1 -0
- package/dist/index.d.ts +409 -415
- package/dist/index.js +63 -29
- package/dist/index.js.map +1 -1
- package/dist/{jsx-runtime-COVsDskT.d.ts → jsx-runtime-Bdt1Dwzf.d.ts} +71 -71
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/docs/actions.mdx +98 -0
- package/docs/adapters/discord.mdx +217 -0
- package/docs/adapters/gchat.mdx +232 -0
- package/docs/adapters/github.mdx +225 -0
- package/docs/adapters/index.mdx +110 -0
- package/docs/adapters/linear.mdx +207 -0
- package/docs/adapters/meta.json +12 -0
- package/docs/adapters/slack.mdx +293 -0
- package/docs/adapters/teams.mdx +225 -0
- package/docs/api/cards.mdx +217 -0
- package/docs/api/channel.mdx +176 -0
- package/docs/api/chat.mdx +469 -0
- package/docs/api/index.mdx +29 -0
- package/docs/api/markdown.mdx +235 -0
- package/docs/api/message.mdx +163 -0
- package/docs/api/meta.json +14 -0
- package/docs/api/modals.mdx +222 -0
- package/docs/api/postable-message.mdx +166 -0
- package/docs/api/thread.mdx +186 -0
- package/docs/cards.mdx +213 -0
- package/docs/direct-messages.mdx +56 -0
- package/docs/emoji.mdx +77 -0
- package/docs/ephemeral-messages.mdx +77 -0
- package/docs/error-handling.mdx +147 -0
- package/docs/files.mdx +77 -0
- package/docs/getting-started.mdx +12 -0
- package/docs/guides/code-review-hono.mdx +248 -0
- package/docs/guides/discord-nuxt.mdx +237 -0
- package/docs/guides/meta.json +4 -0
- package/docs/guides/slack-nextjs.mdx +245 -0
- package/docs/index.mdx +92 -0
- package/docs/meta.json +20 -0
- package/docs/modals.mdx +208 -0
- package/docs/posting-messages.mdx +177 -0
- package/docs/slash-commands.mdx +110 -0
- package/docs/state/index.mdx +31 -0
- package/docs/state/ioredis.mdx +81 -0
- package/docs/state/memory.mdx +52 -0
- package/docs/state/meta.json +9 -0
- package/docs/state/redis.mdx +93 -0
- package/docs/streaming.mdx +99 -0
- package/docs/usage.mdx +338 -0
- package/package.json +10 -10
- package/dist/chunk-WKJEG4FE.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CardElement,
|
|
2
|
-
export {
|
|
1
|
+
import { C as CardElement, M as ModalElement, a as CardJSXElement, b as CardChild, A as Actions$1, B as Button$1, c as Card$1, T as Text$1, D as Divider$1, F as Field$1, d as Fields$1, f as fromReactElement$1, I as Image$1, i as isCardElement$1, e as isJSX$1, L as LinkButton$1, S as Section$1, t as toCardElement$1, g as toModalElement$1, h as fromReactModalElement$1, j as isModalElement$1, k as Modal$1, R as RadioSelect$1, l as Select$1, m as SelectOption$1, n as TextInput$1 } from './jsx-runtime-Bdt1Dwzf.js';
|
|
2
|
+
export { o as ActionsElement, p as ButtonElement, q as ButtonOptions, J as ButtonProps, r as ButtonStyle, K as CardJSXProps, s as CardOptions, N as CardProps, O as ContainerProps, u as DividerElement, P as DividerProps, v as FieldElement, Q as FieldProps, w as FieldsElement, x as ImageElement, U as ImageProps, y as LinkButtonElement, z as LinkButtonOptions, V as LinkButtonProps, X as ModalChild, Y as ModalOptions, Z as RadioSelectElement, _ as RadioSelectOptions, E as SectionElement, $ as SelectElement, a0 as SelectOptionElement, a1 as SelectOptions, G as TextElement, a2 as TextInputElement, a3 as TextInputOptions, W as TextProps, H as TextStyle } from './jsx-runtime-Bdt1Dwzf.js';
|
|
3
3
|
import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@workflow/serde';
|
|
4
4
|
import { Root, Content, Blockquote, Code, Emphasis, InlineCode, Delete, Link, ListItem, List, Paragraph, Strong, Text } from 'mdast';
|
|
5
5
|
export { Blockquote, Code, Content, Delete, Emphasis, InlineCode, Link, List, ListItem, Paragraph, Root, Strong, Text } from 'mdast';
|
|
@@ -9,19 +9,19 @@ export { Blockquote, Code, Content, Delete, Emphasis, InlineCode, Link, List, Li
|
|
|
9
9
|
*/
|
|
10
10
|
type LogLevel = "debug" | "info" | "warn" | "error" | "silent";
|
|
11
11
|
interface Logger {
|
|
12
|
+
/** Create a sub-logger with a prefix */
|
|
13
|
+
child(prefix: string): Logger;
|
|
12
14
|
debug(message: string, ...args: unknown[]): void;
|
|
15
|
+
error(message: string, ...args: unknown[]): void;
|
|
13
16
|
info(message: string, ...args: unknown[]): void;
|
|
14
17
|
warn(message: string, ...args: unknown[]): void;
|
|
15
|
-
error(message: string, ...args: unknown[]): void;
|
|
16
|
-
/** Create a sub-logger with a prefix */
|
|
17
|
-
child(prefix: string): Logger;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Default console logger implementation.
|
|
21
21
|
*/
|
|
22
22
|
declare class ConsoleLogger implements Logger {
|
|
23
|
-
private
|
|
24
|
-
private
|
|
23
|
+
private readonly prefix;
|
|
24
|
+
private readonly level;
|
|
25
25
|
constructor(level?: LogLevel, prefix?: string);
|
|
26
26
|
private shouldLog;
|
|
27
27
|
child(prefix: string): Logger;
|
|
@@ -36,19 +36,19 @@ declare class ConsoleLogger implements Logger {
|
|
|
36
36
|
*/
|
|
37
37
|
declare class ChatError extends Error {
|
|
38
38
|
readonly code: string;
|
|
39
|
-
readonly cause?: unknown
|
|
40
|
-
constructor(message: string, code: string, cause?: unknown
|
|
39
|
+
readonly cause?: unknown;
|
|
40
|
+
constructor(message: string, code: string, cause?: unknown);
|
|
41
41
|
}
|
|
42
42
|
declare class RateLimitError extends ChatError {
|
|
43
|
-
readonly retryAfterMs?: number
|
|
44
|
-
constructor(message: string, retryAfterMs?: number
|
|
43
|
+
readonly retryAfterMs?: number;
|
|
44
|
+
constructor(message: string, retryAfterMs?: number, cause?: unknown);
|
|
45
45
|
}
|
|
46
46
|
declare class LockError extends ChatError {
|
|
47
47
|
constructor(message: string, cause?: unknown);
|
|
48
48
|
}
|
|
49
49
|
declare class NotImplementedError extends ChatError {
|
|
50
|
-
readonly feature?: string
|
|
51
|
-
constructor(message: string, feature?: string
|
|
50
|
+
readonly feature?: string;
|
|
51
|
+
constructor(message: string, feature?: string, cause?: unknown);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -56,22 +56,22 @@ declare class NotImplementedError extends ChatError {
|
|
|
56
56
|
* @template TAdapters - Record of adapter name to adapter instance
|
|
57
57
|
*/
|
|
58
58
|
interface ChatConfig<TAdapters extends Record<string, Adapter> = Record<string, Adapter>> {
|
|
59
|
-
/** Default bot username across all adapters */
|
|
60
|
-
userName: string;
|
|
61
59
|
/** Map of adapter name to adapter instance */
|
|
62
60
|
adapters: TAdapters;
|
|
63
|
-
/** State adapter for subscriptions and locking */
|
|
64
|
-
state: StateAdapter;
|
|
65
61
|
/**
|
|
66
62
|
* Logger instance or log level.
|
|
67
63
|
* Pass "silent" to disable all logging.
|
|
68
64
|
*/
|
|
69
65
|
logger: Logger | LogLevel;
|
|
66
|
+
/** State adapter for subscriptions and locking */
|
|
67
|
+
state: StateAdapter;
|
|
70
68
|
/**
|
|
71
69
|
* Update interval for fallback streaming (post + edit) in milliseconds.
|
|
72
70
|
* Defaults to 500ms. Lower values provide smoother updates but may hit rate limits.
|
|
73
71
|
*/
|
|
74
72
|
streamingUpdateIntervalMs?: number;
|
|
73
|
+
/** Default bot username across all adapters */
|
|
74
|
+
userName: string;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Options for webhook handling.
|
|
@@ -99,28 +99,42 @@ interface WebhookOptions {
|
|
|
99
99
|
* @template TRawMessage - Platform-specific raw message type
|
|
100
100
|
*/
|
|
101
101
|
interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
/** Bot username (can override global userName) */
|
|
105
|
-
readonly userName: string;
|
|
102
|
+
/** Add a reaction to a message */
|
|
103
|
+
addReaction(threadId: string, messageId: string, emoji: EmojiValue | string): Promise<void>;
|
|
106
104
|
/** Bot user ID for platforms that use IDs in mentions (e.g., Slack's <@U123>) */
|
|
107
105
|
readonly botUserId?: string;
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Derive channel ID from a thread ID.
|
|
108
|
+
* Default fallback: first two colon-separated parts (e.g., "slack:C123").
|
|
109
|
+
* Adapters with different structures should override this.
|
|
110
|
+
*/
|
|
111
|
+
channelIdFromThreadId?(threadId: string): string;
|
|
112
|
+
/** Decode thread ID string back to platform-specific data */
|
|
113
|
+
decodeThreadId(threadId: string): TThreadId;
|
|
116
114
|
/** Delete a message */
|
|
117
115
|
deleteMessage(threadId: string, messageId: string): Promise<void>;
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
|
|
116
|
+
/** Edit an existing message */
|
|
117
|
+
editMessage(threadId: string, messageId: string, message: AdapterPostableMessage): Promise<RawMessage<TRawMessage>>;
|
|
118
|
+
/** Encode platform-specific data into a thread ID string */
|
|
119
|
+
encodeThreadId(platformData: TThreadId): string;
|
|
120
|
+
/**
|
|
121
|
+
* Fetch channel info/metadata.
|
|
122
|
+
*/
|
|
123
|
+
fetchChannelInfo?(channelId: string): Promise<ChannelInfo>;
|
|
124
|
+
/**
|
|
125
|
+
* Fetch channel-level messages (top-level, not thread replies).
|
|
126
|
+
* For example, Slack's conversations.history vs conversations.replies.
|
|
127
|
+
*/
|
|
128
|
+
fetchChannelMessages?(channelId: string, options?: FetchOptions): Promise<FetchResult<TRawMessage>>;
|
|
129
|
+
/**
|
|
130
|
+
* Fetch a single message by ID.
|
|
131
|
+
* Optional - adapters that don't implement this will return null.
|
|
132
|
+
*
|
|
133
|
+
* @param threadId - The thread ID containing the message
|
|
134
|
+
* @param messageId - The platform-specific message ID
|
|
135
|
+
* @returns The message, or null if not found/not supported
|
|
136
|
+
*/
|
|
137
|
+
fetchMessage?(threadId: string, messageId: string): Promise<Message<TRawMessage> | null>;
|
|
124
138
|
/**
|
|
125
139
|
* Fetch messages from a thread.
|
|
126
140
|
*
|
|
@@ -156,23 +170,23 @@ interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
|
|
|
156
170
|
fetchMessages(threadId: string, options?: FetchOptions): Promise<FetchResult<TRawMessage>>;
|
|
157
171
|
/** Fetch thread metadata */
|
|
158
172
|
fetchThread(threadId: string): Promise<ThreadInfo>;
|
|
173
|
+
/** Handle incoming webhook request */
|
|
174
|
+
handleWebhook(request: Request, options?: WebhookOptions): Promise<Response>;
|
|
175
|
+
/** Called when Chat instance is created (internal use) */
|
|
176
|
+
initialize(chat: ChatInstance): Promise<void>;
|
|
159
177
|
/**
|
|
160
|
-
*
|
|
161
|
-
* Optional - adapters that don't implement this will return null.
|
|
178
|
+
* Check if a thread is a direct message conversation.
|
|
162
179
|
*
|
|
163
|
-
* @param threadId - The thread ID
|
|
164
|
-
* @
|
|
165
|
-
* @returns The message, or null if not found/not supported
|
|
180
|
+
* @param threadId - The thread ID to check
|
|
181
|
+
* @returns True if the thread is a DM, false otherwise
|
|
166
182
|
*/
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
|
|
174
|
-
/** Render formatted content to platform-specific string */
|
|
175
|
-
renderFormatted(content: FormattedContent): string;
|
|
183
|
+
isDM?(threadId: string): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* List threads in a channel.
|
|
186
|
+
*/
|
|
187
|
+
listThreads?(channelId: string, options?: ListThreadsOptions): Promise<ListThreadsResult<TRawMessage>>;
|
|
188
|
+
/** Unique name for this adapter (e.g., "slack", "teams") */
|
|
189
|
+
readonly name: string;
|
|
176
190
|
/**
|
|
177
191
|
* Optional hook called when a thread is subscribed to.
|
|
178
192
|
* Adapters can use this to set up platform-specific subscriptions
|
|
@@ -192,6 +206,23 @@ interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
|
|
|
192
206
|
* ```
|
|
193
207
|
*/
|
|
194
208
|
openDM?(userId: string): Promise<string>;
|
|
209
|
+
/**
|
|
210
|
+
* Open a modal/dialog form.
|
|
211
|
+
*
|
|
212
|
+
* @param triggerId - Platform-specific trigger ID from the action event
|
|
213
|
+
* @param modal - The modal element to display
|
|
214
|
+
* @param contextId - Optional context ID for server-side stored thread/message context
|
|
215
|
+
* @returns The view/dialog ID
|
|
216
|
+
*/
|
|
217
|
+
openModal?(triggerId: string, modal: ModalElement, contextId?: string): Promise<{
|
|
218
|
+
viewId: string;
|
|
219
|
+
}>;
|
|
220
|
+
/** Parse platform message format to normalized format */
|
|
221
|
+
parseMessage(raw: TRawMessage): Message<TRawMessage>;
|
|
222
|
+
/**
|
|
223
|
+
* Post a message to channel top-level (not in a thread).
|
|
224
|
+
*/
|
|
225
|
+
postChannelMessage?(channelId: string, message: AdapterPostableMessage): Promise<RawMessage<TRawMessage>>;
|
|
195
226
|
/**
|
|
196
227
|
* Post an ephemeral message visible only to a specific user.
|
|
197
228
|
*
|
|
@@ -204,24 +235,14 @@ interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
|
|
|
204
235
|
* @returns EphemeralMessage with usedFallback: false
|
|
205
236
|
*/
|
|
206
237
|
postEphemeral?(threadId: string, userId: string, message: AdapterPostableMessage): Promise<EphemeralMessage>;
|
|
207
|
-
/**
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
* Open a modal/dialog form.
|
|
216
|
-
*
|
|
217
|
-
* @param triggerId - Platform-specific trigger ID from the action event
|
|
218
|
-
* @param modal - The modal element to display
|
|
219
|
-
* @param contextId - Optional context ID for server-side stored thread/message context
|
|
220
|
-
* @returns The view/dialog ID
|
|
221
|
-
*/
|
|
222
|
-
openModal?(triggerId: string, modal: ModalElement, contextId?: string): Promise<{
|
|
223
|
-
viewId: string;
|
|
224
|
-
}>;
|
|
238
|
+
/** Post a message to a thread */
|
|
239
|
+
postMessage(threadId: string, message: AdapterPostableMessage): Promise<RawMessage<TRawMessage>>;
|
|
240
|
+
/** Remove a reaction from a message */
|
|
241
|
+
removeReaction(threadId: string, messageId: string, emoji: EmojiValue | string): Promise<void>;
|
|
242
|
+
/** Render formatted content to platform-specific string */
|
|
243
|
+
renderFormatted(content: FormattedContent): string;
|
|
244
|
+
/** Show typing indicator */
|
|
245
|
+
startTyping(threadId: string): Promise<void>;
|
|
225
246
|
/**
|
|
226
247
|
* Stream a message using platform-native streaming APIs.
|
|
227
248
|
*
|
|
@@ -234,80 +255,64 @@ interface Adapter<TThreadId = unknown, TRawMessage = unknown> {
|
|
|
234
255
|
* @returns The raw message after streaming completes
|
|
235
256
|
*/
|
|
236
257
|
stream?(threadId: string, textStream: AsyncIterable<string>, options?: StreamOptions): Promise<RawMessage<TRawMessage>>;
|
|
237
|
-
/**
|
|
238
|
-
|
|
239
|
-
* Default fallback: first two colon-separated parts (e.g., "slack:C123").
|
|
240
|
-
* Adapters with different structures should override this.
|
|
241
|
-
*/
|
|
242
|
-
channelIdFromThreadId?(threadId: string): string;
|
|
243
|
-
/**
|
|
244
|
-
* Fetch channel-level messages (top-level, not thread replies).
|
|
245
|
-
* For example, Slack's conversations.history vs conversations.replies.
|
|
246
|
-
*/
|
|
247
|
-
fetchChannelMessages?(channelId: string, options?: FetchOptions): Promise<FetchResult<TRawMessage>>;
|
|
248
|
-
/**
|
|
249
|
-
* List threads in a channel.
|
|
250
|
-
*/
|
|
251
|
-
listThreads?(channelId: string, options?: ListThreadsOptions): Promise<ListThreadsResult<TRawMessage>>;
|
|
252
|
-
/**
|
|
253
|
-
* Fetch channel info/metadata.
|
|
254
|
-
*/
|
|
255
|
-
fetchChannelInfo?(channelId: string): Promise<ChannelInfo>;
|
|
256
|
-
/**
|
|
257
|
-
* Post a message to channel top-level (not in a thread).
|
|
258
|
-
*/
|
|
259
|
-
postChannelMessage?(channelId: string, message: AdapterPostableMessage): Promise<RawMessage<TRawMessage>>;
|
|
258
|
+
/** Bot username (can override global userName) */
|
|
259
|
+
readonly userName: string;
|
|
260
260
|
}
|
|
261
261
|
/**
|
|
262
262
|
* Options for streaming messages.
|
|
263
263
|
* Platform-specific options are passed through to the adapter.
|
|
264
264
|
*/
|
|
265
265
|
interface StreamOptions {
|
|
266
|
-
/** Slack: The user ID to stream to (for AI assistant context) */
|
|
267
|
-
recipientUserId?: string;
|
|
268
266
|
/** Slack: The team/workspace ID */
|
|
269
267
|
recipientTeamId?: string;
|
|
270
|
-
/**
|
|
271
|
-
|
|
268
|
+
/** Slack: The user ID to stream to (for AI assistant context) */
|
|
269
|
+
recipientUserId?: string;
|
|
272
270
|
/** Block Kit elements to attach when stopping the stream (Slack only, via chat.stopStream) */
|
|
273
271
|
stopBlocks?: unknown[];
|
|
272
|
+
/** Minimum interval between updates in ms (default: 1000). Used for fallback mode (GChat/Teams). */
|
|
273
|
+
updateIntervalMs?: number;
|
|
274
274
|
}
|
|
275
275
|
/** Internal interface for Chat instance passed to adapters */
|
|
276
276
|
interface ChatInstance {
|
|
277
|
-
/**
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
* @param adapter - The adapter that received the message
|
|
282
|
-
* @param threadId - The thread ID
|
|
283
|
-
* @param message - Either a parsed message, or a factory function for lazy async parsing
|
|
284
|
-
* @param options - Webhook options including waitUntil
|
|
285
|
-
*/
|
|
286
|
-
processMessage(adapter: Adapter, threadId: string, message: Message | (() => Promise<Message>), options?: WebhookOptions): void;
|
|
277
|
+
/** Get the configured logger, optionally with a child prefix */
|
|
278
|
+
getLogger(prefix?: string): Logger;
|
|
279
|
+
getState(): StateAdapter;
|
|
280
|
+
getUserName(): string;
|
|
287
281
|
/**
|
|
288
282
|
* @deprecated Use processMessage instead. This method is for internal use.
|
|
289
283
|
*/
|
|
290
284
|
handleIncomingMessage(adapter: Adapter, threadId: string, message: Message): Promise<void>;
|
|
291
285
|
/**
|
|
292
|
-
* Process an incoming
|
|
286
|
+
* Process an incoming action event (button click) from an adapter.
|
|
293
287
|
* Handles waitUntil registration and error catching internally.
|
|
294
288
|
*
|
|
295
|
-
* @param event - The
|
|
289
|
+
* @param event - The action event (without thread field, will be added)
|
|
296
290
|
* @param options - Webhook options including waitUntil
|
|
297
291
|
*/
|
|
298
|
-
|
|
299
|
-
adapter
|
|
292
|
+
processAction(event: Omit<ActionEvent, "thread" | "openModal"> & {
|
|
293
|
+
adapter: Adapter;
|
|
300
294
|
}, options?: WebhookOptions): void;
|
|
295
|
+
processAppHomeOpened(event: AppHomeOpenedEvent, options?: WebhookOptions): void;
|
|
296
|
+
processAssistantContextChanged(event: AssistantContextChangedEvent, options?: WebhookOptions): void;
|
|
297
|
+
processAssistantThreadStarted(event: AssistantThreadStartedEvent, options?: WebhookOptions): void;
|
|
301
298
|
/**
|
|
302
|
-
* Process an incoming
|
|
299
|
+
* Process an incoming message from an adapter.
|
|
303
300
|
* Handles waitUntil registration and error catching internally.
|
|
304
301
|
*
|
|
305
|
-
* @param
|
|
302
|
+
* @param adapter - The adapter that received the message
|
|
303
|
+
* @param threadId - The thread ID
|
|
304
|
+
* @param message - Either a parsed message, or a factory function for lazy async parsing
|
|
306
305
|
* @param options - Webhook options including waitUntil
|
|
307
306
|
*/
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
307
|
+
processMessage(adapter: Adapter, threadId: string, message: Message | (() => Promise<Message>), options?: WebhookOptions): void;
|
|
308
|
+
/**
|
|
309
|
+
* Process a modal close event from an adapter.
|
|
310
|
+
*
|
|
311
|
+
* @param event - The modal close event (without relatedThread/relatedMessage/relatedChannel)
|
|
312
|
+
* @param contextId - Context ID for retrieving stored thread/message/channel context
|
|
313
|
+
* @param options - Webhook options
|
|
314
|
+
*/
|
|
315
|
+
processModalClose(event: Omit<ModalCloseEvent, "relatedThread" | "relatedMessage" | "relatedChannel">, contextId?: string, options?: WebhookOptions): void;
|
|
311
316
|
/**
|
|
312
317
|
* Process a modal submit event from an adapter.
|
|
313
318
|
*
|
|
@@ -317,13 +322,15 @@ interface ChatInstance {
|
|
|
317
322
|
*/
|
|
318
323
|
processModalSubmit(event: Omit<ModalSubmitEvent, "relatedThread" | "relatedMessage" | "relatedChannel">, contextId?: string, options?: WebhookOptions): Promise<ModalResponse | undefined>;
|
|
319
324
|
/**
|
|
320
|
-
* Process
|
|
325
|
+
* Process an incoming reaction event from an adapter.
|
|
326
|
+
* Handles waitUntil registration and error catching internally.
|
|
321
327
|
*
|
|
322
|
-
* @param event - The
|
|
323
|
-
* @param
|
|
324
|
-
* @param options - Webhook options
|
|
328
|
+
* @param event - The reaction event (without adapter field, will be added)
|
|
329
|
+
* @param options - Webhook options including waitUntil
|
|
325
330
|
*/
|
|
326
|
-
|
|
331
|
+
processReaction(event: Omit<ReactionEvent, "adapter" | "thread"> & {
|
|
332
|
+
adapter?: Adapter;
|
|
333
|
+
}, options?: WebhookOptions): void;
|
|
327
334
|
/**
|
|
328
335
|
* Process an incoming slash command from an adapter.
|
|
329
336
|
* Handles waitUntil registration and error catching internally.
|
|
@@ -335,44 +342,35 @@ interface ChatInstance {
|
|
|
335
342
|
adapter: Adapter;
|
|
336
343
|
channelId: string;
|
|
337
344
|
}, options?: WebhookOptions): void;
|
|
338
|
-
processAssistantThreadStarted(event: AssistantThreadStartedEvent, options?: WebhookOptions): void;
|
|
339
|
-
processAssistantContextChanged(event: AssistantContextChangedEvent, options?: WebhookOptions): void;
|
|
340
|
-
processAppHomeOpened(event: AppHomeOpenedEvent, options?: WebhookOptions): void;
|
|
341
|
-
getState(): StateAdapter;
|
|
342
|
-
getUserName(): string;
|
|
343
|
-
/** Get the configured logger, optionally with a child prefix */
|
|
344
|
-
getLogger(prefix?: string): Logger;
|
|
345
345
|
}
|
|
346
346
|
interface StateAdapter {
|
|
347
|
+
/** Acquire a lock on a thread (returns null if already locked) */
|
|
348
|
+
acquireLock(threadId: string, ttlMs: number): Promise<Lock | null>;
|
|
347
349
|
/** Connect to the state backend */
|
|
348
350
|
connect(): Promise<void>;
|
|
351
|
+
/** Delete a cached value */
|
|
352
|
+
delete(key: string): Promise<void>;
|
|
349
353
|
/** Disconnect from the state backend */
|
|
350
354
|
disconnect(): Promise<void>;
|
|
351
|
-
/** Subscribe to a thread (persists across restarts) */
|
|
352
|
-
subscribe(threadId: string): Promise<void>;
|
|
353
|
-
/** Unsubscribe from a thread */
|
|
354
|
-
unsubscribe(threadId: string): Promise<void>;
|
|
355
|
-
/** Check if subscribed to a thread */
|
|
356
|
-
isSubscribed(threadId: string): Promise<boolean>;
|
|
357
|
-
/** List all subscriptions, optionally filtered by adapter */
|
|
358
|
-
listSubscriptions(adapterName?: string): AsyncIterable<string>;
|
|
359
|
-
/** Acquire a lock on a thread (returns null if already locked) */
|
|
360
|
-
acquireLock(threadId: string, ttlMs: number): Promise<Lock | null>;
|
|
361
|
-
/** Release a lock */
|
|
362
|
-
releaseLock(lock: Lock): Promise<void>;
|
|
363
355
|
/** Extend a lock's TTL */
|
|
364
356
|
extendLock(lock: Lock, ttlMs: number): Promise<boolean>;
|
|
365
357
|
/** Get a cached value by key */
|
|
366
358
|
get<T = unknown>(key: string): Promise<T | null>;
|
|
359
|
+
/** Check if subscribed to a thread */
|
|
360
|
+
isSubscribed(threadId: string): Promise<boolean>;
|
|
361
|
+
/** Release a lock */
|
|
362
|
+
releaseLock(lock: Lock): Promise<void>;
|
|
367
363
|
/** Set a cached value with optional TTL in milliseconds */
|
|
368
364
|
set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void>;
|
|
369
|
-
/**
|
|
370
|
-
|
|
365
|
+
/** Subscribe to a thread (persists across restarts) */
|
|
366
|
+
subscribe(threadId: string): Promise<void>;
|
|
367
|
+
/** Unsubscribe from a thread */
|
|
368
|
+
unsubscribe(threadId: string): Promise<void>;
|
|
371
369
|
}
|
|
372
370
|
interface Lock {
|
|
371
|
+
expiresAt: number;
|
|
373
372
|
threadId: string;
|
|
374
373
|
token: string;
|
|
375
|
-
expiresAt: number;
|
|
376
374
|
}
|
|
377
375
|
/**
|
|
378
376
|
* Base interface for entities that can receive messages.
|
|
@@ -382,23 +380,16 @@ interface Lock {
|
|
|
382
380
|
* @template TRawMessage - Platform-specific raw message type
|
|
383
381
|
*/
|
|
384
382
|
interface Postable<TState = Record<string, unknown>, TRawMessage = unknown> {
|
|
385
|
-
/** Unique ID */
|
|
386
|
-
readonly id: string;
|
|
387
383
|
/** The adapter this entity belongs to */
|
|
388
384
|
readonly adapter: Adapter;
|
|
385
|
+
/** Unique ID */
|
|
386
|
+
readonly id: string;
|
|
389
387
|
/** Whether this is a direct message conversation */
|
|
390
388
|
readonly isDM: boolean;
|
|
391
389
|
/**
|
|
392
|
-
* Get
|
|
393
|
-
* Returns null if no state has been set.
|
|
394
|
-
*/
|
|
395
|
-
readonly state: Promise<TState | null>;
|
|
396
|
-
/**
|
|
397
|
-
* Set the state. Merges with existing state by default.
|
|
390
|
+
* Get a platform-specific mention string for a user.
|
|
398
391
|
*/
|
|
399
|
-
|
|
400
|
-
replace?: boolean;
|
|
401
|
-
}): Promise<void>;
|
|
392
|
+
mentionUser(userId: string): string;
|
|
402
393
|
/**
|
|
403
394
|
* Iterate messages newest first (backward from most recent).
|
|
404
395
|
* Auto-paginates lazily — only fetches pages as consumed.
|
|
@@ -412,12 +403,19 @@ interface Postable<TState = Record<string, unknown>, TRawMessage = unknown> {
|
|
|
412
403
|
* Post an ephemeral message visible only to a specific user.
|
|
413
404
|
*/
|
|
414
405
|
postEphemeral(user: string | Author, message: AdapterPostableMessage | CardJSXElement, options: PostEphemeralOptions): Promise<EphemeralMessage | null>;
|
|
406
|
+
/**
|
|
407
|
+
* Set the state. Merges with existing state by default.
|
|
408
|
+
*/
|
|
409
|
+
setState(state: Partial<TState>, options?: {
|
|
410
|
+
replace?: boolean;
|
|
411
|
+
}): Promise<void>;
|
|
415
412
|
/** Show typing indicator */
|
|
416
413
|
startTyping(): Promise<void>;
|
|
417
414
|
/**
|
|
418
|
-
* Get
|
|
415
|
+
* Get the current state.
|
|
416
|
+
* Returns null if no state has been set.
|
|
419
417
|
*/
|
|
420
|
-
|
|
418
|
+
readonly state: Promise<TState | null>;
|
|
421
419
|
}
|
|
422
420
|
/**
|
|
423
421
|
* Represents a channel/conversation container that holds threads.
|
|
@@ -427,6 +425,8 @@ interface Postable<TState = Record<string, unknown>, TRawMessage = unknown> {
|
|
|
427
425
|
* @template TRawMessage - Platform-specific raw message type
|
|
428
426
|
*/
|
|
429
427
|
interface Channel<TState = Record<string, unknown>, TRawMessage = unknown> extends Postable<TState, TRawMessage> {
|
|
428
|
+
/** Fetch channel metadata from the platform */
|
|
429
|
+
fetchMetadata(): Promise<ChannelInfo>;
|
|
430
430
|
/** Channel name (e.g., "#general"). Null until fetchInfo() is called. */
|
|
431
431
|
readonly name: string | null;
|
|
432
432
|
/**
|
|
@@ -435,8 +435,6 @@ interface Channel<TState = Record<string, unknown>, TRawMessage = unknown> exten
|
|
|
435
435
|
* Empty iterable on threadless platforms.
|
|
436
436
|
*/
|
|
437
437
|
threads(): AsyncIterable<ThreadSummary<TRawMessage>>;
|
|
438
|
-
/** Fetch channel metadata from the platform */
|
|
439
|
-
fetchMetadata(): Promise<ChannelInfo>;
|
|
440
438
|
}
|
|
441
439
|
/**
|
|
442
440
|
* Lightweight summary of a thread within a channel.
|
|
@@ -444,36 +442,36 @@ interface Channel<TState = Record<string, unknown>, TRawMessage = unknown> exten
|
|
|
444
442
|
interface ThreadSummary<TRawMessage = unknown> {
|
|
445
443
|
/** Full thread ID */
|
|
446
444
|
id: string;
|
|
447
|
-
/** Root/first message of the thread */
|
|
448
|
-
rootMessage: Message<TRawMessage>;
|
|
449
|
-
/** Reply count (if available) */
|
|
450
|
-
replyCount?: number;
|
|
451
445
|
/** Timestamp of most recent reply */
|
|
452
446
|
lastReplyAt?: Date;
|
|
447
|
+
/** Reply count (if available) */
|
|
448
|
+
replyCount?: number;
|
|
449
|
+
/** Root/first message of the thread */
|
|
450
|
+
rootMessage: Message<TRawMessage>;
|
|
453
451
|
}
|
|
454
452
|
/**
|
|
455
453
|
* Channel metadata returned by fetchInfo().
|
|
456
454
|
*/
|
|
457
455
|
interface ChannelInfo {
|
|
458
456
|
id: string;
|
|
459
|
-
name?: string;
|
|
460
457
|
isDM?: boolean;
|
|
461
458
|
memberCount?: number;
|
|
462
459
|
metadata: Record<string, unknown>;
|
|
460
|
+
name?: string;
|
|
463
461
|
}
|
|
464
462
|
/**
|
|
465
463
|
* Options for listing threads in a channel.
|
|
466
464
|
*/
|
|
467
465
|
interface ListThreadsOptions {
|
|
468
|
-
limit?: number;
|
|
469
466
|
cursor?: string;
|
|
467
|
+
limit?: number;
|
|
470
468
|
}
|
|
471
469
|
/**
|
|
472
470
|
* Result of listing threads in a channel.
|
|
473
471
|
*/
|
|
474
472
|
interface ListThreadsResult<TRawMessage = unknown> {
|
|
475
|
-
threads: ThreadSummary<TRawMessage>[];
|
|
476
473
|
nextCursor?: string;
|
|
474
|
+
threads: ThreadSummary<TRawMessage>[];
|
|
477
475
|
}
|
|
478
476
|
/** Default TTL for thread state (30 days in milliseconds) */
|
|
479
477
|
declare const THREAD_STATE_TTL_MS: number;
|
|
@@ -485,18 +483,21 @@ declare const THREAD_STATE_TTL_MS: number;
|
|
|
485
483
|
* @template TRawMessage - Platform-specific raw message type
|
|
486
484
|
*/
|
|
487
485
|
interface Thread<TState = Record<string, unknown>, TRawMessage = unknown> extends Postable<TState, TRawMessage> {
|
|
488
|
-
/** Channel/conversation ID */
|
|
489
|
-
readonly channelId: string;
|
|
490
|
-
/** Get the Channel containing this thread */
|
|
491
|
-
readonly channel: Channel<TState, TRawMessage>;
|
|
492
|
-
/** Recently fetched messages (cached) */
|
|
493
|
-
recentMessages: Message<TRawMessage>[];
|
|
494
486
|
/**
|
|
495
487
|
* Async iterator for all messages in the thread.
|
|
496
488
|
* Messages are yielded in chronological order (oldest first).
|
|
497
489
|
* Automatically handles pagination.
|
|
498
490
|
*/
|
|
499
491
|
allMessages: AsyncIterable<Message<TRawMessage>>;
|
|
492
|
+
/** Get the Channel containing this thread */
|
|
493
|
+
readonly channel: Channel<TState, TRawMessage>;
|
|
494
|
+
/** Channel/conversation ID */
|
|
495
|
+
readonly channelId: string;
|
|
496
|
+
/**
|
|
497
|
+
* Wrap a Message object as a SentMessage with edit/delete capabilities.
|
|
498
|
+
* Used internally for reconstructing messages from serialized data.
|
|
499
|
+
*/
|
|
500
|
+
createSentMessageFromMessage(message: Message<TRawMessage>): SentMessage<TRawMessage>;
|
|
500
501
|
/**
|
|
501
502
|
* Check if this thread is currently subscribed.
|
|
502
503
|
*
|
|
@@ -507,26 +508,12 @@ interface Thread<TState = Record<string, unknown>, TRawMessage = unknown> extend
|
|
|
507
508
|
*/
|
|
508
509
|
isSubscribed(): Promise<boolean>;
|
|
509
510
|
/**
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* Once subscribed, all messages in this thread will trigger `onSubscribedMessage` handlers.
|
|
513
|
-
* The initial message that triggered subscription will NOT fire the handler.
|
|
514
|
-
*
|
|
511
|
+
* Get a platform-specific mention string for a user.
|
|
512
|
+
* Use this to @-mention a user in a message.
|
|
515
513
|
* @example
|
|
516
|
-
*
|
|
517
|
-
* chat.onNewMention(async (thread, message) => {
|
|
518
|
-
* await thread.subscribe(); // Subscribe to follow-up messages
|
|
519
|
-
* await thread.post("I'm now watching this thread!");
|
|
520
|
-
* });
|
|
521
|
-
* ```
|
|
522
|
-
*/
|
|
523
|
-
subscribe(): Promise<void>;
|
|
524
|
-
/**
|
|
525
|
-
* Unsubscribe from this thread.
|
|
526
|
-
*
|
|
527
|
-
* Future messages will no longer trigger `onSubscribedMessage` handlers.
|
|
514
|
+
* await thread.post(`Hey ${thread.mentionUser(userId)}, check this out!`);
|
|
528
515
|
*/
|
|
529
|
-
|
|
516
|
+
mentionUser(userId: string): string;
|
|
530
517
|
/**
|
|
531
518
|
* Post a message to this thread.
|
|
532
519
|
*
|
|
@@ -590,12 +577,8 @@ interface Thread<TState = Record<string, unknown>, TRawMessage = unknown> extend
|
|
|
590
577
|
* ```
|
|
591
578
|
*/
|
|
592
579
|
postEphemeral(user: string | Author, message: AdapterPostableMessage | CardJSXElement, options: PostEphemeralOptions): Promise<EphemeralMessage | null>;
|
|
593
|
-
/**
|
|
594
|
-
|
|
595
|
-
*
|
|
596
|
-
* Some platforms support persistent typing indicators, others just send once.
|
|
597
|
-
*/
|
|
598
|
-
startTyping(): Promise<void>;
|
|
580
|
+
/** Recently fetched messages (cached) */
|
|
581
|
+
recentMessages: Message<TRawMessage>[];
|
|
599
582
|
/**
|
|
600
583
|
* Refresh `recentMessages` from the API.
|
|
601
584
|
*
|
|
@@ -603,22 +586,37 @@ interface Thread<TState = Record<string, unknown>, TRawMessage = unknown> extend
|
|
|
603
586
|
*/
|
|
604
587
|
refresh(): Promise<void>;
|
|
605
588
|
/**
|
|
606
|
-
*
|
|
607
|
-
*
|
|
589
|
+
* Show typing indicator in the thread.
|
|
590
|
+
*
|
|
591
|
+
* Some platforms support persistent typing indicators, others just send once.
|
|
608
592
|
*/
|
|
609
|
-
|
|
593
|
+
startTyping(): Promise<void>;
|
|
610
594
|
/**
|
|
611
|
-
*
|
|
612
|
-
*
|
|
595
|
+
* Subscribe to future messages in this thread.
|
|
596
|
+
*
|
|
597
|
+
* Once subscribed, all messages in this thread will trigger `onSubscribedMessage` handlers.
|
|
598
|
+
* The initial message that triggered subscription will NOT fire the handler.
|
|
599
|
+
*
|
|
613
600
|
* @example
|
|
614
|
-
*
|
|
601
|
+
* ```typescript
|
|
602
|
+
* chat.onNewMention(async (thread, message) => {
|
|
603
|
+
* await thread.subscribe(); // Subscribe to follow-up messages
|
|
604
|
+
* await thread.post("I'm now watching this thread!");
|
|
605
|
+
* });
|
|
606
|
+
* ```
|
|
615
607
|
*/
|
|
616
|
-
|
|
608
|
+
subscribe(): Promise<void>;
|
|
609
|
+
/**
|
|
610
|
+
* Unsubscribe from this thread.
|
|
611
|
+
*
|
|
612
|
+
* Future messages will no longer trigger `onSubscribedMessage` handlers.
|
|
613
|
+
*/
|
|
614
|
+
unsubscribe(): Promise<void>;
|
|
617
615
|
}
|
|
618
616
|
interface ThreadInfo {
|
|
619
|
-
id: string;
|
|
620
617
|
channelId: string;
|
|
621
618
|
channelName?: string;
|
|
619
|
+
id: string;
|
|
622
620
|
/** Whether this is a direct message conversation */
|
|
623
621
|
isDM?: boolean;
|
|
624
622
|
/** Platform-specific metadata */
|
|
@@ -657,8 +655,6 @@ type FetchDirection = "forward" | "backward";
|
|
|
657
655
|
* Options for fetching messages from a thread.
|
|
658
656
|
*/
|
|
659
657
|
interface FetchOptions {
|
|
660
|
-
/** Maximum number of messages to fetch. Default varies by adapter (50-100). */
|
|
661
|
-
limit?: number;
|
|
662
658
|
/**
|
|
663
659
|
* Pagination cursor for fetching the next page of messages.
|
|
664
660
|
* Pass the `nextCursor` from a previous `FetchResult`.
|
|
@@ -673,6 +669,8 @@ interface FetchOptions {
|
|
|
673
669
|
* Messages within each page are always returned in chronological order (oldest first).
|
|
674
670
|
*/
|
|
675
671
|
direction?: FetchDirection;
|
|
672
|
+
/** Maximum number of messages to fetch. Default varies by adapter (50-100). */
|
|
673
|
+
limit?: number;
|
|
676
674
|
}
|
|
677
675
|
/**
|
|
678
676
|
* Result of fetching messages from a thread.
|
|
@@ -704,20 +702,20 @@ type FormattedContent = Root;
|
|
|
704
702
|
/** Raw message returned from adapter (before wrapping as SentMessage) */
|
|
705
703
|
interface RawMessage<TRawMessage = unknown> {
|
|
706
704
|
id: string;
|
|
707
|
-
threadId: string;
|
|
708
705
|
raw: TRawMessage;
|
|
706
|
+
threadId: string;
|
|
709
707
|
}
|
|
710
708
|
interface Author {
|
|
711
|
-
/** Unique user ID */
|
|
712
|
-
userId: string;
|
|
713
|
-
/** Username/handle for @-mentions */
|
|
714
|
-
userName: string;
|
|
715
709
|
/** Display name */
|
|
716
710
|
fullName: string;
|
|
717
711
|
/** Whether the author is a bot */
|
|
718
712
|
isBot: boolean | "unknown";
|
|
719
713
|
/** Whether the author is this bot */
|
|
720
714
|
isMe: boolean;
|
|
715
|
+
/** Unique user ID */
|
|
716
|
+
userId: string;
|
|
717
|
+
/** Username/handle for @-mentions */
|
|
718
|
+
userName: string;
|
|
721
719
|
}
|
|
722
720
|
interface MessageMetadata {
|
|
723
721
|
/** When the message was sent */
|
|
@@ -728,12 +726,12 @@ interface MessageMetadata {
|
|
|
728
726
|
editedAt?: Date;
|
|
729
727
|
}
|
|
730
728
|
interface SentMessage<TRawMessage = unknown> extends Message<TRawMessage> {
|
|
731
|
-
/** Edit this message with text, a PostableMessage, or a JSX Card element */
|
|
732
|
-
edit(newContent: string | PostableMessage | CardJSXElement): Promise<SentMessage<TRawMessage>>;
|
|
733
|
-
/** Delete this message */
|
|
734
|
-
delete(): Promise<void>;
|
|
735
729
|
/** Add a reaction to this message */
|
|
736
730
|
addReaction(emoji: EmojiValue | string): Promise<void>;
|
|
731
|
+
/** Delete this message */
|
|
732
|
+
delete(): Promise<void>;
|
|
733
|
+
/** Edit this message with text, a PostableMessage, or a JSX Card element */
|
|
734
|
+
edit(newContent: string | PostableMessage | CardJSXElement): Promise<SentMessage<TRawMessage>>;
|
|
737
735
|
/** Remove a reaction from this message */
|
|
738
736
|
removeReaction(emoji: EmojiValue | string): Promise<void>;
|
|
739
737
|
}
|
|
@@ -746,12 +744,12 @@ interface SentMessage<TRawMessage = unknown> extends Message<TRawMessage> {
|
|
|
746
744
|
interface EphemeralMessage {
|
|
747
745
|
/** Message ID (may be empty for some platforms) */
|
|
748
746
|
id: string;
|
|
747
|
+
/** Platform-specific raw response */
|
|
748
|
+
raw: unknown;
|
|
749
749
|
/** Thread ID where message was sent (or DM thread if fallback was used) */
|
|
750
750
|
threadId: string;
|
|
751
751
|
/** Whether this used native ephemeral or fell back to DM */
|
|
752
752
|
usedFallback: boolean;
|
|
753
|
-
/** Platform-specific raw response */
|
|
754
|
-
raw: unknown;
|
|
755
753
|
}
|
|
756
754
|
/**
|
|
757
755
|
* Options for posting ephemeral messages.
|
|
@@ -783,20 +781,20 @@ type AdapterPostableMessage = string | PostableRaw | PostableMarkdown | Postable
|
|
|
783
781
|
*/
|
|
784
782
|
type PostableMessage = AdapterPostableMessage | AsyncIterable<string>;
|
|
785
783
|
interface PostableRaw {
|
|
786
|
-
/** Raw text passed through as-is to the platform */
|
|
787
|
-
raw: string;
|
|
788
784
|
/** File/image attachments */
|
|
789
785
|
attachments?: Attachment[];
|
|
790
786
|
/** Files to upload */
|
|
791
787
|
files?: FileUpload[];
|
|
788
|
+
/** Raw text passed through as-is to the platform */
|
|
789
|
+
raw: string;
|
|
792
790
|
}
|
|
793
791
|
interface PostableMarkdown {
|
|
794
|
-
/** Markdown text, converted to platform format */
|
|
795
|
-
markdown: string;
|
|
796
792
|
/** File/image attachments */
|
|
797
793
|
attachments?: Attachment[];
|
|
798
794
|
/** Files to upload */
|
|
799
795
|
files?: FileUpload[];
|
|
796
|
+
/** Markdown text, converted to platform format */
|
|
797
|
+
markdown: string;
|
|
800
798
|
}
|
|
801
799
|
interface PostableAst {
|
|
802
800
|
/** mdast AST, converted to platform format */
|
|
@@ -815,28 +813,28 @@ interface PostableCard {
|
|
|
815
813
|
files?: FileUpload[];
|
|
816
814
|
}
|
|
817
815
|
interface Attachment {
|
|
818
|
-
/** Type of attachment */
|
|
819
|
-
type: "image" | "file" | "video" | "audio";
|
|
820
|
-
/** URL to the file (for linking/downloading) */
|
|
821
|
-
url?: string;
|
|
822
816
|
/** Binary data (for uploading or if already fetched) */
|
|
823
817
|
data?: Buffer | Blob;
|
|
824
|
-
/** Filename */
|
|
825
|
-
name?: string;
|
|
826
|
-
/** MIME type */
|
|
827
|
-
mimeType?: string;
|
|
828
|
-
/** File size in bytes */
|
|
829
|
-
size?: number;
|
|
830
|
-
/** Image/video width (if applicable) */
|
|
831
|
-
width?: number;
|
|
832
|
-
/** Image/video height (if applicable) */
|
|
833
|
-
height?: number;
|
|
834
818
|
/**
|
|
835
819
|
* Fetch the attachment data.
|
|
836
820
|
* For platforms that require authentication (like Slack private URLs),
|
|
837
821
|
* this method handles the auth automatically.
|
|
838
822
|
*/
|
|
839
823
|
fetchData?: () => Promise<Buffer>;
|
|
824
|
+
/** Image/video height (if applicable) */
|
|
825
|
+
height?: number;
|
|
826
|
+
/** MIME type */
|
|
827
|
+
mimeType?: string;
|
|
828
|
+
/** Filename */
|
|
829
|
+
name?: string;
|
|
830
|
+
/** File size in bytes */
|
|
831
|
+
size?: number;
|
|
832
|
+
/** Type of attachment */
|
|
833
|
+
type: "image" | "file" | "video" | "audio";
|
|
834
|
+
/** URL to the file (for linking/downloading) */
|
|
835
|
+
url?: string;
|
|
836
|
+
/** Image/video width (if applicable) */
|
|
837
|
+
width?: number;
|
|
840
838
|
}
|
|
841
839
|
/**
|
|
842
840
|
* File to upload with a message.
|
|
@@ -875,14 +873,14 @@ interface FileUpload {
|
|
|
875
873
|
* });
|
|
876
874
|
* ```
|
|
877
875
|
*/
|
|
878
|
-
type MentionHandler<TState = Record<string, unknown>> = (thread: Thread<TState>, message: Message) => Promise<void>;
|
|
876
|
+
type MentionHandler<TState = Record<string, unknown>> = (thread: Thread<TState>, message: Message) => void | Promise<void>;
|
|
879
877
|
/**
|
|
880
878
|
* Handler for messages matching a regex pattern.
|
|
881
879
|
*
|
|
882
880
|
* Registered via `chat.onNewMessage(pattern, handler)`. Called when a message
|
|
883
881
|
* matches the pattern in an unsubscribed thread.
|
|
884
882
|
*/
|
|
885
|
-
type MessageHandler<TState = Record<string, unknown>> = (thread: Thread<TState>, message: Message) => Promise<void>;
|
|
883
|
+
type MessageHandler<TState = Record<string, unknown>> = (thread: Thread<TState>, message: Message) => void | Promise<void>;
|
|
886
884
|
/**
|
|
887
885
|
* Handler for messages in subscribed threads.
|
|
888
886
|
*
|
|
@@ -906,7 +904,7 @@ type MessageHandler<TState = Record<string, unknown>> = (thread: Thread<TState>,
|
|
|
906
904
|
* });
|
|
907
905
|
* ```
|
|
908
906
|
*/
|
|
909
|
-
type SubscribedMessageHandler<TState = Record<string, unknown>> = (thread: Thread<TState>, message: Message) => Promise<void>;
|
|
907
|
+
type SubscribedMessageHandler<TState = Record<string, unknown>> = (thread: Thread<TState>, message: Message) => void | Promise<void>;
|
|
910
908
|
/**
|
|
911
909
|
* Well-known emoji that work across platforms (Slack and Google Chat).
|
|
912
910
|
* These are normalized to a common format regardless of platform.
|
|
@@ -916,10 +914,10 @@ type WellKnownEmoji = "thumbs_up" | "thumbs_down" | "clap" | "wave" | "pray" | "
|
|
|
916
914
|
* Platform-specific emoji formats for a single emoji.
|
|
917
915
|
*/
|
|
918
916
|
interface EmojiFormats {
|
|
919
|
-
/** Slack emoji name (without colons), e.g., "+1", "heart" */
|
|
920
|
-
slack: string | string[];
|
|
921
917
|
/** Google Chat unicode emoji, e.g., "👍", "❤️" */
|
|
922
918
|
gchat: string | string[];
|
|
919
|
+
/** Slack emoji name (without colons), e.g., "+1", "heart" */
|
|
920
|
+
slack: string | string[];
|
|
923
921
|
}
|
|
924
922
|
/**
|
|
925
923
|
* Emoji map type - can be extended by users to add custom emoji.
|
|
@@ -968,29 +966,29 @@ type EmojiMapConfig = Partial<Record<Emoji, EmojiFormats>>;
|
|
|
968
966
|
interface EmojiValue {
|
|
969
967
|
/** The normalized emoji name (e.g., "thumbs_up") */
|
|
970
968
|
readonly name: string;
|
|
971
|
-
/** Returns the placeholder string for message formatting */
|
|
972
|
-
toString(): string;
|
|
973
969
|
/** Returns the placeholder string (for JSON.stringify) */
|
|
974
970
|
toJSON(): string;
|
|
971
|
+
/** Returns the placeholder string for message formatting */
|
|
972
|
+
toString(): string;
|
|
975
973
|
}
|
|
976
974
|
/**
|
|
977
975
|
* Reaction event fired when a user adds or removes a reaction.
|
|
978
|
-
*/
|
|
979
|
-
interface ReactionEvent<TRawMessage = unknown> {
|
|
980
|
-
/** The
|
|
981
|
-
|
|
982
|
-
/** The raw platform-specific emoji (e.g., "+1" for Slack, "👍" for GChat) */
|
|
983
|
-
rawEmoji: string;
|
|
976
|
+
*/
|
|
977
|
+
interface ReactionEvent<TRawMessage = unknown> {
|
|
978
|
+
/** The adapter that received the event */
|
|
979
|
+
adapter: Adapter;
|
|
984
980
|
/** Whether the reaction was added (true) or removed (false) */
|
|
985
981
|
added: boolean;
|
|
986
|
-
/** The
|
|
987
|
-
|
|
982
|
+
/** The normalized emoji as an EmojiValue singleton (enables `===` comparison) */
|
|
983
|
+
emoji: EmojiValue;
|
|
988
984
|
/** The message that was reacted to (if available) */
|
|
989
985
|
message?: Message<TRawMessage>;
|
|
990
986
|
/** The message ID that was reacted to */
|
|
991
987
|
messageId: string;
|
|
992
|
-
/**
|
|
993
|
-
|
|
988
|
+
/** Platform-specific raw event data */
|
|
989
|
+
raw: unknown;
|
|
990
|
+
/** The raw platform-specific emoji (e.g., "+1" for Slack, "👍" for GChat) */
|
|
991
|
+
rawEmoji: string;
|
|
994
992
|
/**
|
|
995
993
|
* The thread where the reaction occurred.
|
|
996
994
|
* Use this to post replies or check subscription status.
|
|
@@ -1003,10 +1001,10 @@ interface ReactionEvent<TRawMessage = unknown> {
|
|
|
1003
1001
|
* ```
|
|
1004
1002
|
*/
|
|
1005
1003
|
thread: Thread<TRawMessage>;
|
|
1006
|
-
/** The
|
|
1007
|
-
|
|
1008
|
-
/**
|
|
1009
|
-
|
|
1004
|
+
/** The thread ID */
|
|
1005
|
+
threadId: string;
|
|
1006
|
+
/** The user who added/removed the reaction */
|
|
1007
|
+
user: Author;
|
|
1010
1008
|
}
|
|
1011
1009
|
/**
|
|
1012
1010
|
* Handler for reaction events.
|
|
@@ -1024,7 +1022,7 @@ interface ReactionEvent<TRawMessage = unknown> {
|
|
|
1024
1022
|
* });
|
|
1025
1023
|
* ```
|
|
1026
1024
|
*/
|
|
1027
|
-
type ReactionHandler = (event: ReactionEvent) => Promise<void>;
|
|
1025
|
+
type ReactionHandler = (event: ReactionEvent) => void | Promise<void>;
|
|
1028
1026
|
/**
|
|
1029
1027
|
* Action event fired when a user clicks a button in a card.
|
|
1030
1028
|
*
|
|
@@ -1038,22 +1036,10 @@ type ReactionHandler = (event: ReactionEvent) => Promise<void>;
|
|
|
1038
1036
|
interface ActionEvent<TRawMessage = unknown> {
|
|
1039
1037
|
/** The action ID from the button (matches Button's `id` prop) */
|
|
1040
1038
|
actionId: string;
|
|
1041
|
-
/** Optional value/payload from the button */
|
|
1042
|
-
value?: string;
|
|
1043
|
-
/** User who clicked the button */
|
|
1044
|
-
user: Author;
|
|
1045
|
-
/** The thread where the action occurred */
|
|
1046
|
-
thread: Thread<TRawMessage>;
|
|
1047
|
-
/** The message ID containing the card */
|
|
1048
|
-
messageId: string;
|
|
1049
|
-
/** The thread ID */
|
|
1050
|
-
threadId: string;
|
|
1051
1039
|
/** The adapter that received the event */
|
|
1052
1040
|
adapter: Adapter;
|
|
1053
|
-
/**
|
|
1054
|
-
|
|
1055
|
-
/** Trigger ID for opening modals (required by some platforms, may expire quickly) */
|
|
1056
|
-
triggerId?: string;
|
|
1041
|
+
/** The message ID containing the card */
|
|
1042
|
+
messageId: string;
|
|
1057
1043
|
/**
|
|
1058
1044
|
* Open a modal/dialog form in response to this action.
|
|
1059
1045
|
*
|
|
@@ -1063,6 +1049,18 @@ interface ActionEvent<TRawMessage = unknown> {
|
|
|
1063
1049
|
openModal(modal: ModalElement | CardJSXElement): Promise<{
|
|
1064
1050
|
viewId: string;
|
|
1065
1051
|
} | undefined>;
|
|
1052
|
+
/** Platform-specific raw event data */
|
|
1053
|
+
raw: unknown;
|
|
1054
|
+
/** The thread where the action occurred */
|
|
1055
|
+
thread: Thread<TRawMessage>;
|
|
1056
|
+
/** The thread ID */
|
|
1057
|
+
threadId: string;
|
|
1058
|
+
/** Trigger ID for opening modals (required by some platforms, may expire quickly) */
|
|
1059
|
+
triggerId?: string;
|
|
1060
|
+
/** User who clicked the button */
|
|
1061
|
+
user: Author;
|
|
1062
|
+
/** Optional value/payload from the button */
|
|
1063
|
+
value?: string;
|
|
1066
1064
|
}
|
|
1067
1065
|
/**
|
|
1068
1066
|
* Handler for action events (button clicks in cards).
|
|
@@ -1087,33 +1085,27 @@ interface ActionEvent<TRawMessage = unknown> {
|
|
|
1087
1085
|
* });
|
|
1088
1086
|
* ```
|
|
1089
1087
|
*/
|
|
1090
|
-
type ActionHandler = (event: ActionEvent) => Promise<void>;
|
|
1088
|
+
type ActionHandler = (event: ActionEvent) => void | Promise<void>;
|
|
1091
1089
|
/**
|
|
1092
1090
|
* Event emitted when a user submits a modal form.
|
|
1093
1091
|
*/
|
|
1094
1092
|
interface ModalSubmitEvent<TRawMessage = unknown> {
|
|
1095
|
-
/** The callback ID specified when creating the modal */
|
|
1096
|
-
callbackId: string;
|
|
1097
|
-
/** Platform-specific view/dialog ID */
|
|
1098
|
-
viewId: string;
|
|
1099
|
-
/** Form field values keyed by input ID */
|
|
1100
|
-
values: Record<string, string>;
|
|
1101
|
-
/** The user who submitted the modal */
|
|
1102
|
-
user: Author;
|
|
1103
1093
|
/** The adapter that received this event */
|
|
1104
1094
|
adapter: Adapter;
|
|
1105
|
-
/**
|
|
1106
|
-
|
|
1095
|
+
/** The callback ID specified when creating the modal */
|
|
1096
|
+
callbackId: string;
|
|
1107
1097
|
/**
|
|
1108
1098
|
* The private metadata string set when the modal was created.
|
|
1109
1099
|
* Use this to pass arbitrary context (e.g., JSON) through the modal lifecycle.
|
|
1110
1100
|
*/
|
|
1111
1101
|
privateMetadata?: string;
|
|
1102
|
+
/** Raw platform-specific payload */
|
|
1103
|
+
raw: unknown;
|
|
1112
1104
|
/**
|
|
1113
|
-
* The
|
|
1114
|
-
* Available when the modal was opened via
|
|
1105
|
+
* The channel where the modal was originally triggered from.
|
|
1106
|
+
* Available when the modal was opened via SlashCommandEvent.openModal().
|
|
1115
1107
|
*/
|
|
1116
|
-
|
|
1108
|
+
relatedChannel?: Channel<Record<string, unknown>, TRawMessage>;
|
|
1117
1109
|
/**
|
|
1118
1110
|
* The message that contained the action which opened the modal.
|
|
1119
1111
|
* Available when the modal was opened from a message action via ActionEvent.openModal().
|
|
@@ -1121,35 +1113,37 @@ interface ModalSubmitEvent<TRawMessage = unknown> {
|
|
|
1121
1113
|
*/
|
|
1122
1114
|
relatedMessage?: SentMessage<TRawMessage>;
|
|
1123
1115
|
/**
|
|
1124
|
-
* The
|
|
1125
|
-
* Available when the modal was opened via
|
|
1116
|
+
* The thread where the modal was originally triggered from.
|
|
1117
|
+
* Available when the modal was opened via ActionEvent.openModal().
|
|
1126
1118
|
*/
|
|
1127
|
-
|
|
1119
|
+
relatedThread?: Thread<Record<string, unknown>, TRawMessage>;
|
|
1120
|
+
/** The user who submitted the modal */
|
|
1121
|
+
user: Author;
|
|
1122
|
+
/** Form field values keyed by input ID */
|
|
1123
|
+
values: Record<string, string>;
|
|
1124
|
+
/** Platform-specific view/dialog ID */
|
|
1125
|
+
viewId: string;
|
|
1128
1126
|
}
|
|
1129
1127
|
/**
|
|
1130
1128
|
* Event emitted when a user closes/cancels a modal (requires notifyOnClose).
|
|
1131
1129
|
*/
|
|
1132
1130
|
interface ModalCloseEvent<TRawMessage = unknown> {
|
|
1133
|
-
/** The callback ID specified when creating the modal */
|
|
1134
|
-
callbackId: string;
|
|
1135
|
-
/** Platform-specific view/dialog ID */
|
|
1136
|
-
viewId: string;
|
|
1137
|
-
/** The user who closed the modal */
|
|
1138
|
-
user: Author;
|
|
1139
1131
|
/** The adapter that received this event */
|
|
1140
1132
|
adapter: Adapter;
|
|
1141
|
-
/**
|
|
1142
|
-
|
|
1133
|
+
/** The callback ID specified when creating the modal */
|
|
1134
|
+
callbackId: string;
|
|
1143
1135
|
/**
|
|
1144
1136
|
* The private metadata string set when the modal was created.
|
|
1145
1137
|
* Use this to pass arbitrary context (e.g., JSON) through the modal lifecycle.
|
|
1146
1138
|
*/
|
|
1147
1139
|
privateMetadata?: string;
|
|
1140
|
+
/** Raw platform-specific payload */
|
|
1141
|
+
raw: unknown;
|
|
1148
1142
|
/**
|
|
1149
|
-
* The
|
|
1150
|
-
* Available when the modal was opened via
|
|
1143
|
+
* The channel where the modal was originally triggered from.
|
|
1144
|
+
* Available when the modal was opened via SlashCommandEvent.openModal().
|
|
1151
1145
|
*/
|
|
1152
|
-
|
|
1146
|
+
relatedChannel?: Channel<Record<string, unknown>, TRawMessage>;
|
|
1153
1147
|
/**
|
|
1154
1148
|
* The message that contained the action which opened the modal.
|
|
1155
1149
|
* Available when the modal was opened from a message action via ActionEvent.openModal().
|
|
@@ -1157,29 +1151,33 @@ interface ModalCloseEvent<TRawMessage = unknown> {
|
|
|
1157
1151
|
*/
|
|
1158
1152
|
relatedMessage?: SentMessage<TRawMessage>;
|
|
1159
1153
|
/**
|
|
1160
|
-
* The
|
|
1161
|
-
* Available when the modal was opened via
|
|
1154
|
+
* The thread where the modal was originally triggered from.
|
|
1155
|
+
* Available when the modal was opened via ActionEvent.openModal().
|
|
1162
1156
|
*/
|
|
1163
|
-
|
|
1157
|
+
relatedThread?: Thread<Record<string, unknown>, TRawMessage>;
|
|
1158
|
+
/** The user who closed the modal */
|
|
1159
|
+
user: Author;
|
|
1160
|
+
/** Platform-specific view/dialog ID */
|
|
1161
|
+
viewId: string;
|
|
1164
1162
|
}
|
|
1165
|
-
|
|
1163
|
+
interface ModalErrorsResponse {
|
|
1166
1164
|
action: "errors";
|
|
1167
1165
|
errors: Record<string, string>;
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1166
|
+
}
|
|
1167
|
+
interface ModalUpdateResponse {
|
|
1170
1168
|
action: "update";
|
|
1171
1169
|
modal: ModalElement;
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1170
|
+
}
|
|
1171
|
+
interface ModalPushResponse {
|
|
1174
1172
|
action: "push";
|
|
1175
1173
|
modal: ModalElement;
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1174
|
+
}
|
|
1175
|
+
interface ModalCloseResponse {
|
|
1178
1176
|
action: "close";
|
|
1179
|
-
}
|
|
1177
|
+
}
|
|
1180
1178
|
type ModalResponse = ModalCloseResponse | ModalErrorsResponse | ModalUpdateResponse | ModalPushResponse;
|
|
1181
|
-
type ModalSubmitHandler = (event: ModalSubmitEvent) => Promise<ModalResponse | undefined>;
|
|
1182
|
-
type ModalCloseHandler = (event: ModalCloseEvent) => Promise<void>;
|
|
1179
|
+
type ModalSubmitHandler = (event: ModalSubmitEvent) => void | Promise<ModalResponse | undefined>;
|
|
1180
|
+
type ModalCloseHandler = (event: ModalCloseEvent) => void | Promise<void>;
|
|
1183
1181
|
/**
|
|
1184
1182
|
* Event emitted when a user invokes a slash command.
|
|
1185
1183
|
*
|
|
@@ -1215,20 +1213,12 @@ type ModalCloseHandler = (event: ModalCloseEvent) => Promise<void>;
|
|
|
1215
1213
|
* ```
|
|
1216
1214
|
*/
|
|
1217
1215
|
interface SlashCommandEvent<TState = Record<string, unknown>> {
|
|
1218
|
-
/** The slash command name (e.g., "/help") */
|
|
1219
|
-
command: string;
|
|
1220
|
-
/** Arguments text after the command (e.g., "topic search" from "/help topic search") */
|
|
1221
|
-
text: string;
|
|
1222
|
-
/** The user who invoked the command */
|
|
1223
|
-
user: Author;
|
|
1224
|
-
/** The channel where the command was invoked */
|
|
1225
|
-
channel: Channel<TState>;
|
|
1226
1216
|
/** The adapter that received this event */
|
|
1227
1217
|
adapter: Adapter;
|
|
1228
|
-
/**
|
|
1229
|
-
|
|
1230
|
-
/**
|
|
1231
|
-
|
|
1218
|
+
/** The channel where the command was invoked */
|
|
1219
|
+
channel: Channel<TState>;
|
|
1220
|
+
/** The slash command name (e.g., "/help") */
|
|
1221
|
+
command: string;
|
|
1232
1222
|
/**
|
|
1233
1223
|
* Open a modal/dialog form in response to this slash command.
|
|
1234
1224
|
*
|
|
@@ -1238,6 +1228,14 @@ interface SlashCommandEvent<TState = Record<string, unknown>> {
|
|
|
1238
1228
|
openModal(modal: ModalElement | CardJSXElement): Promise<{
|
|
1239
1229
|
viewId: string;
|
|
1240
1230
|
} | undefined>;
|
|
1231
|
+
/** Platform-specific raw payload */
|
|
1232
|
+
raw: unknown;
|
|
1233
|
+
/** Arguments text after the command (e.g., "topic search" from "/help topic search") */
|
|
1234
|
+
text: string;
|
|
1235
|
+
/** Trigger ID for opening modals (time-limited, typically ~3 seconds) */
|
|
1236
|
+
triggerId?: string;
|
|
1237
|
+
/** The user who invoked the command */
|
|
1238
|
+
user: Author;
|
|
1241
1239
|
}
|
|
1242
1240
|
/**
|
|
1243
1241
|
* Handler for slash command events.
|
|
@@ -1260,12 +1258,10 @@ interface SlashCommandEvent<TState = Record<string, unknown>> {
|
|
|
1260
1258
|
* });
|
|
1261
1259
|
* ```
|
|
1262
1260
|
*/
|
|
1263
|
-
type SlashCommandHandler<TState = Record<string, unknown>> = (event: SlashCommandEvent<TState>) => Promise<void>;
|
|
1261
|
+
type SlashCommandHandler<TState = Record<string, unknown>> = (event: SlashCommandEvent<TState>) => void | Promise<void>;
|
|
1264
1262
|
interface AssistantThreadStartedEvent {
|
|
1265
|
-
|
|
1266
|
-
userId: string;
|
|
1263
|
+
adapter: Adapter;
|
|
1267
1264
|
channelId: string;
|
|
1268
|
-
threadTs: string;
|
|
1269
1265
|
context: {
|
|
1270
1266
|
channelId?: string;
|
|
1271
1267
|
teamId?: string;
|
|
@@ -1273,14 +1269,14 @@ interface AssistantThreadStartedEvent {
|
|
|
1273
1269
|
threadEntryPoint?: string;
|
|
1274
1270
|
forceSearch?: boolean;
|
|
1275
1271
|
};
|
|
1276
|
-
adapter: Adapter;
|
|
1277
|
-
}
|
|
1278
|
-
type AssistantThreadStartedHandler = (event: AssistantThreadStartedEvent) => Promise<void>;
|
|
1279
|
-
interface AssistantContextChangedEvent {
|
|
1280
1272
|
threadId: string;
|
|
1273
|
+
threadTs: string;
|
|
1281
1274
|
userId: string;
|
|
1275
|
+
}
|
|
1276
|
+
type AssistantThreadStartedHandler = (event: AssistantThreadStartedEvent) => void | Promise<void>;
|
|
1277
|
+
interface AssistantContextChangedEvent {
|
|
1278
|
+
adapter: Adapter;
|
|
1282
1279
|
channelId: string;
|
|
1283
|
-
threadTs: string;
|
|
1284
1280
|
context: {
|
|
1285
1281
|
channelId?: string;
|
|
1286
1282
|
teamId?: string;
|
|
@@ -1288,15 +1284,17 @@ interface AssistantContextChangedEvent {
|
|
|
1288
1284
|
threadEntryPoint?: string;
|
|
1289
1285
|
forceSearch?: boolean;
|
|
1290
1286
|
};
|
|
1291
|
-
|
|
1287
|
+
threadId: string;
|
|
1288
|
+
threadTs: string;
|
|
1289
|
+
userId: string;
|
|
1292
1290
|
}
|
|
1293
|
-
type AssistantContextChangedHandler = (event: AssistantContextChangedEvent) => Promise<void>;
|
|
1291
|
+
type AssistantContextChangedHandler = (event: AssistantContextChangedEvent) => void | Promise<void>;
|
|
1294
1292
|
interface AppHomeOpenedEvent {
|
|
1295
|
-
userId: string;
|
|
1296
|
-
channelId: string;
|
|
1297
1293
|
adapter: Adapter;
|
|
1294
|
+
channelId: string;
|
|
1295
|
+
userId: string;
|
|
1298
1296
|
}
|
|
1299
|
-
type AppHomeOpenedHandler = (event: AppHomeOpenedEvent) => Promise<void>;
|
|
1297
|
+
type AppHomeOpenedHandler = (event: AppHomeOpenedEvent) => void | Promise<void>;
|
|
1300
1298
|
|
|
1301
1299
|
/**
|
|
1302
1300
|
* Message class with serialization support for workflow engines.
|
|
@@ -1307,24 +1305,24 @@ type AppHomeOpenedHandler = (event: AppHomeOpenedEvent) => Promise<void>;
|
|
|
1307
1305
|
* Use this interface when constructing Message objects.
|
|
1308
1306
|
*/
|
|
1309
1307
|
interface MessageData<TRawMessage = unknown> {
|
|
1310
|
-
/** Unique message ID */
|
|
1311
|
-
id: string;
|
|
1312
|
-
/** Thread this message belongs to */
|
|
1313
|
-
threadId: string;
|
|
1314
|
-
/** Plain text content (all formatting stripped) */
|
|
1315
|
-
text: string;
|
|
1316
|
-
/** Structured formatting as an AST (mdast Root) */
|
|
1317
|
-
formatted: FormattedContent;
|
|
1318
|
-
/** Platform-specific raw payload (escape hatch) */
|
|
1319
|
-
raw: TRawMessage;
|
|
1320
|
-
/** Message author */
|
|
1321
|
-
author: Author;
|
|
1322
|
-
/** Message metadata */
|
|
1323
|
-
metadata: MessageMetadata;
|
|
1324
1308
|
/** Attachments */
|
|
1325
1309
|
attachments: Attachment[];
|
|
1310
|
+
/** Message author */
|
|
1311
|
+
author: Author;
|
|
1312
|
+
/** Structured formatting as an AST (mdast Root) */
|
|
1313
|
+
formatted: FormattedContent;
|
|
1314
|
+
/** Unique message ID */
|
|
1315
|
+
id: string;
|
|
1326
1316
|
/** Whether the bot is @-mentioned in this message */
|
|
1327
1317
|
isMention?: boolean;
|
|
1318
|
+
/** Message metadata */
|
|
1319
|
+
metadata: MessageMetadata;
|
|
1320
|
+
/** Platform-specific raw payload (escape hatch) */
|
|
1321
|
+
raw: TRawMessage;
|
|
1322
|
+
/** Plain text content (all formatting stripped) */
|
|
1323
|
+
text: string;
|
|
1324
|
+
/** Thread this message belongs to */
|
|
1325
|
+
threadId: string;
|
|
1328
1326
|
}
|
|
1329
1327
|
/**
|
|
1330
1328
|
* Serialized message data for passing to external systems (e.g., workflow engines).
|
|
@@ -1332,11 +1330,15 @@ interface MessageData<TRawMessage = unknown> {
|
|
|
1332
1330
|
*/
|
|
1333
1331
|
interface SerializedMessage {
|
|
1334
1332
|
_type: "chat:Message";
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1333
|
+
attachments: Array<{
|
|
1334
|
+
type: "image" | "file" | "video" | "audio";
|
|
1335
|
+
url?: string;
|
|
1336
|
+
name?: string;
|
|
1337
|
+
mimeType?: string;
|
|
1338
|
+
size?: number;
|
|
1339
|
+
width?: number;
|
|
1340
|
+
height?: number;
|
|
1341
|
+
}>;
|
|
1340
1342
|
author: {
|
|
1341
1343
|
userId: string;
|
|
1342
1344
|
userName: string;
|
|
@@ -1344,21 +1346,17 @@ interface SerializedMessage {
|
|
|
1344
1346
|
isBot: boolean | "unknown";
|
|
1345
1347
|
isMe: boolean;
|
|
1346
1348
|
};
|
|
1349
|
+
formatted: Root;
|
|
1350
|
+
id: string;
|
|
1351
|
+
isMention?: boolean;
|
|
1347
1352
|
metadata: {
|
|
1348
1353
|
dateSent: string;
|
|
1349
1354
|
edited: boolean;
|
|
1350
1355
|
editedAt?: string;
|
|
1351
1356
|
};
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
name?: string;
|
|
1356
|
-
mimeType?: string;
|
|
1357
|
-
size?: number;
|
|
1358
|
-
width?: number;
|
|
1359
|
-
height?: number;
|
|
1360
|
-
}>;
|
|
1361
|
-
isMention?: boolean;
|
|
1357
|
+
raw: unknown;
|
|
1358
|
+
text: string;
|
|
1359
|
+
threadId: string;
|
|
1362
1360
|
}
|
|
1363
1361
|
/**
|
|
1364
1362
|
* A chat message with serialization support for workflow engines.
|
|
@@ -1450,25 +1448,25 @@ declare class Message<TRawMessage = unknown> {
|
|
|
1450
1448
|
*/
|
|
1451
1449
|
interface SerializedChannel {
|
|
1452
1450
|
_type: "chat:Channel";
|
|
1453
|
-
id: string;
|
|
1454
1451
|
adapterName: string;
|
|
1452
|
+
id: string;
|
|
1455
1453
|
isDM: boolean;
|
|
1456
1454
|
}
|
|
1457
1455
|
/**
|
|
1458
1456
|
* Config for creating a ChannelImpl with explicit adapter/state instances.
|
|
1459
1457
|
*/
|
|
1460
1458
|
interface ChannelImplConfigWithAdapter {
|
|
1461
|
-
id: string;
|
|
1462
1459
|
adapter: Adapter;
|
|
1463
|
-
|
|
1460
|
+
id: string;
|
|
1464
1461
|
isDM?: boolean;
|
|
1462
|
+
stateAdapter: StateAdapter;
|
|
1465
1463
|
}
|
|
1466
1464
|
/**
|
|
1467
1465
|
* Config for creating a ChannelImpl with lazy adapter resolution.
|
|
1468
1466
|
*/
|
|
1469
1467
|
interface ChannelImplConfigLazy {
|
|
1470
|
-
id: string;
|
|
1471
1468
|
adapterName: string;
|
|
1469
|
+
id: string;
|
|
1472
1470
|
isDM?: boolean;
|
|
1473
1471
|
}
|
|
1474
1472
|
type ChannelImplConfig = ChannelImplConfigWithAdapter | ChannelImplConfigLazy;
|
|
@@ -1476,7 +1474,7 @@ declare class ChannelImpl<TState = Record<string, unknown>> implements Channel<T
|
|
|
1476
1474
|
readonly id: string;
|
|
1477
1475
|
readonly isDM: boolean;
|
|
1478
1476
|
private _adapter?;
|
|
1479
|
-
private _adapterName?;
|
|
1477
|
+
private readonly _adapterName?;
|
|
1480
1478
|
private _stateAdapterInstance?;
|
|
1481
1479
|
private _name;
|
|
1482
1480
|
constructor(config: ChannelImplConfig);
|
|
@@ -1580,22 +1578,22 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
|
|
|
1580
1578
|
* Check if a singleton has been registered.
|
|
1581
1579
|
*/
|
|
1582
1580
|
static hasSingleton(): boolean;
|
|
1583
|
-
private adapters;
|
|
1584
|
-
private _stateAdapter;
|
|
1585
|
-
private userName;
|
|
1586
|
-
private logger;
|
|
1587
|
-
private _streamingUpdateIntervalMs;
|
|
1588
|
-
private mentionHandlers;
|
|
1589
|
-
private messagePatterns;
|
|
1590
|
-
private subscribedMessageHandlers;
|
|
1591
|
-
private reactionHandlers;
|
|
1592
|
-
private actionHandlers;
|
|
1593
|
-
private modalSubmitHandlers;
|
|
1594
|
-
private modalCloseHandlers;
|
|
1595
|
-
private slashCommandHandlers;
|
|
1596
|
-
private assistantThreadStartedHandlers;
|
|
1597
|
-
private assistantContextChangedHandlers;
|
|
1598
|
-
private appHomeOpenedHandlers;
|
|
1581
|
+
private readonly adapters;
|
|
1582
|
+
private readonly _stateAdapter;
|
|
1583
|
+
private readonly userName;
|
|
1584
|
+
private readonly logger;
|
|
1585
|
+
private readonly _streamingUpdateIntervalMs;
|
|
1586
|
+
private readonly mentionHandlers;
|
|
1587
|
+
private readonly messagePatterns;
|
|
1588
|
+
private readonly subscribedMessageHandlers;
|
|
1589
|
+
private readonly reactionHandlers;
|
|
1590
|
+
private readonly actionHandlers;
|
|
1591
|
+
private readonly modalSubmitHandlers;
|
|
1592
|
+
private readonly modalCloseHandlers;
|
|
1593
|
+
private readonly slashCommandHandlers;
|
|
1594
|
+
private readonly assistantThreadStartedHandlers;
|
|
1595
|
+
private readonly assistantContextChangedHandlers;
|
|
1596
|
+
private readonly appHomeOpenedHandlers;
|
|
1599
1597
|
/** Initialization state */
|
|
1600
1598
|
private initPromise;
|
|
1601
1599
|
private initialized;
|
|
@@ -1745,14 +1743,11 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
|
|
|
1745
1743
|
* @param handler - The handler (if action ID filter is provided)
|
|
1746
1744
|
*/
|
|
1747
1745
|
onAction(handler: ActionHandler): void;
|
|
1748
|
-
onAction(
|
|
1749
|
-
onAction(actionIds: string[], handler: ActionHandler): void;
|
|
1746
|
+
onAction(actionIds: string[] | string, handler: ActionHandler): void;
|
|
1750
1747
|
onModalSubmit(handler: ModalSubmitHandler): void;
|
|
1751
|
-
onModalSubmit(
|
|
1752
|
-
onModalSubmit(callbackIds: string[], handler: ModalSubmitHandler): void;
|
|
1748
|
+
onModalSubmit(callbackIds: string[] | string, handler: ModalSubmitHandler): void;
|
|
1753
1749
|
onModalClose(handler: ModalCloseHandler): void;
|
|
1754
|
-
onModalClose(
|
|
1755
|
-
onModalClose(callbackIds: string[], handler: ModalCloseHandler): void;
|
|
1750
|
+
onModalClose(callbackIds: string[] | string, handler: ModalCloseHandler): void;
|
|
1756
1751
|
/**
|
|
1757
1752
|
* Register a handler for slash command events.
|
|
1758
1753
|
*
|
|
@@ -1790,8 +1785,7 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
|
|
|
1790
1785
|
* @param handler - The handler (if command filter is provided)
|
|
1791
1786
|
*/
|
|
1792
1787
|
onSlashCommand(handler: SlashCommandHandler<TState>): void;
|
|
1793
|
-
onSlashCommand(
|
|
1794
|
-
onSlashCommand(commands: string[], handler: SlashCommandHandler<TState>): void;
|
|
1788
|
+
onSlashCommand(commands: string[] | string, handler: SlashCommandHandler<TState>): void;
|
|
1795
1789
|
onAssistantThreadStarted(handler: AssistantThreadStartedHandler): void;
|
|
1796
1790
|
onAssistantContextChanged(handler: AssistantContextChangedHandler): void;
|
|
1797
1791
|
onAppHomeOpened(handler: AppHomeOpenedHandler): void;
|
|
@@ -1883,9 +1877,9 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
|
|
|
1883
1877
|
* Accepts either a user ID string or an Author object (from message.author or event.user).
|
|
1884
1878
|
*
|
|
1885
1879
|
* The adapter is automatically inferred from the userId format:
|
|
1886
|
-
* - Slack: `U...` (e.g., "
|
|
1880
|
+
* - Slack: `U...` (e.g., "U00FAKEUSER1")
|
|
1887
1881
|
* - Teams: `29:...` (e.g., "29:198PbJuw...")
|
|
1888
|
-
* - Google Chat: `users/...` (e.g., "users/
|
|
1882
|
+
* - Google Chat: `users/...` (e.g., "users/100000000000000000001")
|
|
1889
1883
|
* - Discord: numeric snowflake (e.g., "1033044521375764530")
|
|
1890
1884
|
*
|
|
1891
1885
|
* @param user - Platform-specific user ID string, or an Author object
|
|
@@ -1962,23 +1956,23 @@ declare class Chat<TAdapters extends Record<string, Adapter> = Record<string, Ad
|
|
|
1962
1956
|
*/
|
|
1963
1957
|
interface SerializedThread {
|
|
1964
1958
|
_type: "chat:Thread";
|
|
1965
|
-
|
|
1959
|
+
adapterName: string;
|
|
1966
1960
|
channelId: string;
|
|
1961
|
+
id: string;
|
|
1967
1962
|
isDM: boolean;
|
|
1968
|
-
adapterName: string;
|
|
1969
1963
|
}
|
|
1970
1964
|
/**
|
|
1971
1965
|
* Config for creating a ThreadImpl with explicit adapter/state instances.
|
|
1972
1966
|
*/
|
|
1973
1967
|
interface ThreadImplConfigWithAdapter {
|
|
1974
|
-
id: string;
|
|
1975
1968
|
adapter: Adapter;
|
|
1976
1969
|
channelId: string;
|
|
1977
|
-
|
|
1970
|
+
currentMessage?: Message;
|
|
1971
|
+
id: string;
|
|
1978
1972
|
initialMessage?: Message;
|
|
1979
|
-
isSubscribedContext?: boolean;
|
|
1980
1973
|
isDM?: boolean;
|
|
1981
|
-
|
|
1974
|
+
isSubscribedContext?: boolean;
|
|
1975
|
+
stateAdapter: StateAdapter;
|
|
1982
1976
|
streamingUpdateIntervalMs?: number;
|
|
1983
1977
|
}
|
|
1984
1978
|
/**
|
|
@@ -1986,13 +1980,13 @@ interface ThreadImplConfigWithAdapter {
|
|
|
1986
1980
|
* The adapter will be looked up from the Chat singleton on first access.
|
|
1987
1981
|
*/
|
|
1988
1982
|
interface ThreadImplConfigLazy {
|
|
1989
|
-
id: string;
|
|
1990
1983
|
adapterName: string;
|
|
1991
1984
|
channelId: string;
|
|
1985
|
+
currentMessage?: Message;
|
|
1986
|
+
id: string;
|
|
1992
1987
|
initialMessage?: Message;
|
|
1993
|
-
isSubscribedContext?: boolean;
|
|
1994
1988
|
isDM?: boolean;
|
|
1995
|
-
|
|
1989
|
+
isSubscribedContext?: boolean;
|
|
1996
1990
|
streamingUpdateIntervalMs?: number;
|
|
1997
1991
|
}
|
|
1998
1992
|
type ThreadImplConfig = ThreadImplConfigWithAdapter | ThreadImplConfigLazy;
|
|
@@ -2003,15 +1997,15 @@ declare class ThreadImpl<TState = Record<string, unknown>> implements Thread<TSt
|
|
|
2003
1997
|
/** Direct adapter instance (if provided) */
|
|
2004
1998
|
private _adapter?;
|
|
2005
1999
|
/** Adapter name for lazy resolution */
|
|
2006
|
-
private _adapterName?;
|
|
2000
|
+
private readonly _adapterName?;
|
|
2007
2001
|
/** Direct state adapter instance (if provided) */
|
|
2008
2002
|
private _stateAdapterInstance?;
|
|
2009
2003
|
private _recentMessages;
|
|
2010
|
-
private _isSubscribedContext;
|
|
2004
|
+
private readonly _isSubscribedContext;
|
|
2011
2005
|
/** Current message context for streaming - provides userId/teamId */
|
|
2012
|
-
private _currentMessage?;
|
|
2006
|
+
private readonly _currentMessage?;
|
|
2013
2007
|
/** Update interval for fallback streaming */
|
|
2014
|
-
private _streamingUpdateIntervalMs;
|
|
2008
|
+
private readonly _streamingUpdateIntervalMs;
|
|
2015
2009
|
/** Cached channel instance */
|
|
2016
2010
|
private _channel?;
|
|
2017
2011
|
constructor(config: ThreadImplConfig);
|
|
@@ -2137,9 +2131,9 @@ declare const DEFAULT_EMOJI_MAP: Record<string, EmojiFormats>;
|
|
|
2137
2131
|
* Emoji resolver that handles conversion between platform formats and normalized names.
|
|
2138
2132
|
*/
|
|
2139
2133
|
declare class EmojiResolver {
|
|
2140
|
-
private emojiMap;
|
|
2141
|
-
private slackToNormalized;
|
|
2142
|
-
private gchatToNormalized;
|
|
2134
|
+
private readonly emojiMap;
|
|
2135
|
+
private readonly slackToNormalized;
|
|
2136
|
+
private readonly gchatToNormalized;
|
|
2143
2137
|
constructor(customMap?: EmojiMapConfig);
|
|
2144
2138
|
private buildReverseMaps;
|
|
2145
2139
|
/**
|
|
@@ -2414,6 +2408,11 @@ declare function root(children: Content[]): Root;
|
|
|
2414
2408
|
* their platform-specific format and the standard AST.
|
|
2415
2409
|
*/
|
|
2416
2410
|
interface FormatConverter {
|
|
2411
|
+
/**
|
|
2412
|
+
* Extract plain text from platform format.
|
|
2413
|
+
* Convenience method - default implementation uses toAst + toPlainText.
|
|
2414
|
+
*/
|
|
2415
|
+
extractPlainText(platformText: string): string;
|
|
2417
2416
|
/**
|
|
2418
2417
|
* Render an AST to the platform's native format.
|
|
2419
2418
|
* This is the primary method used when sending messages.
|
|
@@ -2424,11 +2423,6 @@ interface FormatConverter {
|
|
|
2424
2423
|
* This is the primary method used when receiving messages.
|
|
2425
2424
|
*/
|
|
2426
2425
|
toAst(platformText: string): Root;
|
|
2427
|
-
/**
|
|
2428
|
-
* Extract plain text from platform format.
|
|
2429
|
-
* Convenience method - default implementation uses toAst + toPlainText.
|
|
2430
|
-
*/
|
|
2431
|
-
extractPlainText(platformText: string): string;
|
|
2432
2426
|
}
|
|
2433
2427
|
/**
|
|
2434
2428
|
* @deprecated Use FormatConverter instead
|