@mastra/slack 0.0.0-studio-cli-20260504022012
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/CHANGELOG.md +73 -0
- package/LICENSE.md +30 -0
- package/README.md +146 -0
- package/dist/index.cjs +5593 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +678 -0
- package/dist/index.d.ts +678 -0
- package/dist/index.js +5554 -0
- package/dist/index.js.map +1 -0
- package/package.json +68 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
2
|
+
import { ChannelProvider, ChannelConnectResult, ChannelInstallationInfo, ChannelPlatformInfo } from '@mastra/core/channels';
|
|
3
|
+
import { ApiRoute } from '@mastra/core/server';
|
|
4
|
+
import { SlackAdapter } from '@chat-adapter/slack';
|
|
5
|
+
export { SlackAdapter, createSlackAdapter } from '@chat-adapter/slack';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { ChannelsStorage } from '@mastra/core/storage';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Zod schemas for Slack channel data stored in ChannelsStorage.
|
|
11
|
+
* These define the shape of the `data` JSON blob in ChannelInstallation records.
|
|
12
|
+
*/
|
|
13
|
+
declare const SlashCommandSchema: z.ZodObject<{
|
|
14
|
+
command: z.ZodString;
|
|
15
|
+
description: z.ZodOptional<z.ZodString>;
|
|
16
|
+
usageHint: z.ZodOptional<z.ZodString>;
|
|
17
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
command: string;
|
|
20
|
+
description?: string | undefined;
|
|
21
|
+
usageHint?: string | undefined;
|
|
22
|
+
prompt?: string | undefined;
|
|
23
|
+
}, {
|
|
24
|
+
command: string;
|
|
25
|
+
description?: string | undefined;
|
|
26
|
+
usageHint?: string | undefined;
|
|
27
|
+
prompt?: string | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
declare const SlackInstallationDataSchema: z.ZodObject<{
|
|
30
|
+
appId: z.ZodString;
|
|
31
|
+
clientId: z.ZodString;
|
|
32
|
+
clientSecret: z.ZodString;
|
|
33
|
+
signingSecret: z.ZodString;
|
|
34
|
+
teamId: z.ZodString;
|
|
35
|
+
teamName: z.ZodOptional<z.ZodString>;
|
|
36
|
+
botToken: z.ZodString;
|
|
37
|
+
botUserId: z.ZodString;
|
|
38
|
+
name: z.ZodOptional<z.ZodString>;
|
|
39
|
+
description: z.ZodOptional<z.ZodString>;
|
|
40
|
+
slashCommands: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
41
|
+
command: z.ZodString;
|
|
42
|
+
description: z.ZodOptional<z.ZodString>;
|
|
43
|
+
usageHint: z.ZodOptional<z.ZodString>;
|
|
44
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
command: string;
|
|
47
|
+
description?: string | undefined;
|
|
48
|
+
usageHint?: string | undefined;
|
|
49
|
+
prompt?: string | undefined;
|
|
50
|
+
}, {
|
|
51
|
+
command: string;
|
|
52
|
+
description?: string | undefined;
|
|
53
|
+
usageHint?: string | undefined;
|
|
54
|
+
prompt?: string | undefined;
|
|
55
|
+
}>, "many">>;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
appId: string;
|
|
58
|
+
clientId: string;
|
|
59
|
+
clientSecret: string;
|
|
60
|
+
signingSecret: string;
|
|
61
|
+
teamId: string;
|
|
62
|
+
botToken: string;
|
|
63
|
+
botUserId: string;
|
|
64
|
+
description?: string | undefined;
|
|
65
|
+
teamName?: string | undefined;
|
|
66
|
+
name?: string | undefined;
|
|
67
|
+
slashCommands?: {
|
|
68
|
+
command: string;
|
|
69
|
+
description?: string | undefined;
|
|
70
|
+
usageHint?: string | undefined;
|
|
71
|
+
prompt?: string | undefined;
|
|
72
|
+
}[] | undefined;
|
|
73
|
+
}, {
|
|
74
|
+
appId: string;
|
|
75
|
+
clientId: string;
|
|
76
|
+
clientSecret: string;
|
|
77
|
+
signingSecret: string;
|
|
78
|
+
teamId: string;
|
|
79
|
+
botToken: string;
|
|
80
|
+
botUserId: string;
|
|
81
|
+
description?: string | undefined;
|
|
82
|
+
teamName?: string | undefined;
|
|
83
|
+
name?: string | undefined;
|
|
84
|
+
slashCommands?: {
|
|
85
|
+
command: string;
|
|
86
|
+
description?: string | undefined;
|
|
87
|
+
usageHint?: string | undefined;
|
|
88
|
+
prompt?: string | undefined;
|
|
89
|
+
}[] | undefined;
|
|
90
|
+
}>;
|
|
91
|
+
type SlackInstallationData = z.infer<typeof SlackInstallationDataSchema>;
|
|
92
|
+
declare const SlackPendingDataSchema: z.ZodObject<{
|
|
93
|
+
appId: z.ZodString;
|
|
94
|
+
clientId: z.ZodString;
|
|
95
|
+
clientSecret: z.ZodString;
|
|
96
|
+
signingSecret: z.ZodString;
|
|
97
|
+
authorizationUrl: z.ZodString;
|
|
98
|
+
name: z.ZodOptional<z.ZodString>;
|
|
99
|
+
description: z.ZodOptional<z.ZodString>;
|
|
100
|
+
slashCommands: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
101
|
+
command: z.ZodString;
|
|
102
|
+
description: z.ZodOptional<z.ZodString>;
|
|
103
|
+
usageHint: z.ZodOptional<z.ZodString>;
|
|
104
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
105
|
+
}, "strip", z.ZodTypeAny, {
|
|
106
|
+
command: string;
|
|
107
|
+
description?: string | undefined;
|
|
108
|
+
usageHint?: string | undefined;
|
|
109
|
+
prompt?: string | undefined;
|
|
110
|
+
}, {
|
|
111
|
+
command: string;
|
|
112
|
+
description?: string | undefined;
|
|
113
|
+
usageHint?: string | undefined;
|
|
114
|
+
prompt?: string | undefined;
|
|
115
|
+
}>, "many">>;
|
|
116
|
+
redirectUrl: z.ZodOptional<z.ZodString>;
|
|
117
|
+
}, "strip", z.ZodTypeAny, {
|
|
118
|
+
appId: string;
|
|
119
|
+
clientId: string;
|
|
120
|
+
clientSecret: string;
|
|
121
|
+
signingSecret: string;
|
|
122
|
+
authorizationUrl: string;
|
|
123
|
+
description?: string | undefined;
|
|
124
|
+
name?: string | undefined;
|
|
125
|
+
slashCommands?: {
|
|
126
|
+
command: string;
|
|
127
|
+
description?: string | undefined;
|
|
128
|
+
usageHint?: string | undefined;
|
|
129
|
+
prompt?: string | undefined;
|
|
130
|
+
}[] | undefined;
|
|
131
|
+
redirectUrl?: string | undefined;
|
|
132
|
+
}, {
|
|
133
|
+
appId: string;
|
|
134
|
+
clientId: string;
|
|
135
|
+
clientSecret: string;
|
|
136
|
+
signingSecret: string;
|
|
137
|
+
authorizationUrl: string;
|
|
138
|
+
description?: string | undefined;
|
|
139
|
+
name?: string | undefined;
|
|
140
|
+
slashCommands?: {
|
|
141
|
+
command: string;
|
|
142
|
+
description?: string | undefined;
|
|
143
|
+
usageHint?: string | undefined;
|
|
144
|
+
prompt?: string | undefined;
|
|
145
|
+
}[] | undefined;
|
|
146
|
+
redirectUrl?: string | undefined;
|
|
147
|
+
}>;
|
|
148
|
+
type SlackPendingData = z.infer<typeof SlackPendingDataSchema>;
|
|
149
|
+
declare const SlackConfigDataSchema: z.ZodObject<{
|
|
150
|
+
token: z.ZodOptional<z.ZodString>;
|
|
151
|
+
refreshToken: z.ZodString;
|
|
152
|
+
}, "strip", z.ZodTypeAny, {
|
|
153
|
+
refreshToken: string;
|
|
154
|
+
token?: string | undefined;
|
|
155
|
+
}, {
|
|
156
|
+
refreshToken: string;
|
|
157
|
+
token?: string | undefined;
|
|
158
|
+
}>;
|
|
159
|
+
type SlackConfigData = z.infer<typeof SlackConfigDataSchema>;
|
|
160
|
+
/** Normalized slash command config as stored in installation data. */
|
|
161
|
+
type StoredSlashCommand = z.infer<typeof SlashCommandSchema>;
|
|
162
|
+
interface SlackInstallation {
|
|
163
|
+
id: string;
|
|
164
|
+
agentId: string;
|
|
165
|
+
webhookId: string;
|
|
166
|
+
configHash: string;
|
|
167
|
+
installedAt: Date;
|
|
168
|
+
appId: string;
|
|
169
|
+
clientId: string;
|
|
170
|
+
clientSecret: string;
|
|
171
|
+
signingSecret: string;
|
|
172
|
+
teamId: string;
|
|
173
|
+
teamName?: string;
|
|
174
|
+
botToken: string;
|
|
175
|
+
botUserId: string;
|
|
176
|
+
/** Explicit name passed to connect(), takes priority over agent.name */
|
|
177
|
+
name?: string;
|
|
178
|
+
/** Explicit description passed to connect(), takes priority over agent.getDescription() */
|
|
179
|
+
description?: string;
|
|
180
|
+
slashCommands?: StoredSlashCommand[];
|
|
181
|
+
}
|
|
182
|
+
interface SlackPendingInstallation {
|
|
183
|
+
id: string;
|
|
184
|
+
agentId: string;
|
|
185
|
+
webhookId: string;
|
|
186
|
+
configHash: string;
|
|
187
|
+
createdAt: Date;
|
|
188
|
+
appId: string;
|
|
189
|
+
clientId: string;
|
|
190
|
+
clientSecret: string;
|
|
191
|
+
signingSecret: string;
|
|
192
|
+
authorizationUrl: string;
|
|
193
|
+
/** Explicit name passed to connect(), takes priority over agent.name */
|
|
194
|
+
name?: string;
|
|
195
|
+
/** Explicit description passed to connect(), takes priority over agent.getDescription() */
|
|
196
|
+
description?: string;
|
|
197
|
+
slashCommands?: StoredSlashCommand[];
|
|
198
|
+
redirectUrl?: string;
|
|
199
|
+
}
|
|
200
|
+
interface SlackConfigTokens {
|
|
201
|
+
token?: string;
|
|
202
|
+
refreshToken: string;
|
|
203
|
+
updatedAt: Date;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Configuration for SlackProvider at the Mastra level.
|
|
208
|
+
*/
|
|
209
|
+
interface SlackProviderConfig {
|
|
210
|
+
/**
|
|
211
|
+
* Slack App Configuration access token for programmatic app creation.
|
|
212
|
+
* Generate at: https://api.slack.com/apps > "Your App Configuration Tokens"
|
|
213
|
+
*
|
|
214
|
+
* Optional — will rotate to get a fresh token on startup using `refreshToken`.
|
|
215
|
+
*/
|
|
216
|
+
token?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Slack App Configuration refresh token.
|
|
219
|
+
* Used for automatic token rotation. Single-use; each rotation returns a new pair.
|
|
220
|
+
*
|
|
221
|
+
* Can be provided here or later via `configure({ refreshToken })`.
|
|
222
|
+
* If omitted, the provider starts unconfigured and cannot create apps until
|
|
223
|
+
* `configure()` is called or tokens are loaded from storage.
|
|
224
|
+
*/
|
|
225
|
+
refreshToken?: string;
|
|
226
|
+
/**
|
|
227
|
+
* Base URL for webhook callbacks.
|
|
228
|
+
* Required when calling connect() to create apps.
|
|
229
|
+
* Can also be set later via setBaseUrl() or auto-detected from server config.
|
|
230
|
+
*
|
|
231
|
+
* For local development, use a tunnel like cloudflared:
|
|
232
|
+
* ```
|
|
233
|
+
* baseUrl: 'https://abc123.trycloudflare.com'
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
baseUrl?: string;
|
|
237
|
+
/**
|
|
238
|
+
* Custom storage for installations.
|
|
239
|
+
* Defaults to using Mastra's ChannelsStorage from the global storage.
|
|
240
|
+
* Throws if no persistent storage is available.
|
|
241
|
+
*/
|
|
242
|
+
storage?: ChannelsStorage;
|
|
243
|
+
/**
|
|
244
|
+
* Path to redirect to after OAuth completion.
|
|
245
|
+
* Defaults to "/" (homepage)
|
|
246
|
+
*/
|
|
247
|
+
redirectPath?: string;
|
|
248
|
+
/**
|
|
249
|
+
* Called when a workspace successfully installs the app.
|
|
250
|
+
*/
|
|
251
|
+
onInstall?: (installation: SlackInstallation) => Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Encryption key for sensitive data (clientSecret, signingSecret, botToken).
|
|
254
|
+
* If not provided, secrets are stored in plaintext (not recommended for production).
|
|
255
|
+
*
|
|
256
|
+
* Use a 32+ character random string. Can be set via MASTRA_ENCRYPTION_KEY env var.
|
|
257
|
+
*/
|
|
258
|
+
encryptionKey?: string;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Options for connecting an agent to Slack via `slack.connect(agentId, options)`.
|
|
262
|
+
* This is serializable and can be stored in the database for stored agents.
|
|
263
|
+
*/
|
|
264
|
+
interface SlackConnectOptions {
|
|
265
|
+
/**
|
|
266
|
+
* Display name for the Slack bot.
|
|
267
|
+
* Defaults to agent name, then agent ID.
|
|
268
|
+
*/
|
|
269
|
+
name?: string;
|
|
270
|
+
/**
|
|
271
|
+
* Bot description shown in Slack.
|
|
272
|
+
* Defaults to "{name} - Powered by Mastra".
|
|
273
|
+
*/
|
|
274
|
+
description?: string;
|
|
275
|
+
/**
|
|
276
|
+
* URL to an image for the app icon.
|
|
277
|
+
* Should be a square PNG/JPG, minimum 512x512px.
|
|
278
|
+
* The image will be automatically downloaded and uploaded to Slack.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* iconUrl: 'https://example.com/my-bot-avatar.png'
|
|
282
|
+
*/
|
|
283
|
+
iconUrl?: string;
|
|
284
|
+
/**
|
|
285
|
+
* Slash commands this agent supports.
|
|
286
|
+
*
|
|
287
|
+
* Simple form - command triggers agent.generate() with the input text:
|
|
288
|
+
* ```ts
|
|
289
|
+
* slashCommands: ['/ask']
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* With custom prompt template:
|
|
293
|
+
* ```ts
|
|
294
|
+
* slashCommands: [
|
|
295
|
+
* {
|
|
296
|
+
* command: '/summarize',
|
|
297
|
+
* description: 'Summarize a URL',
|
|
298
|
+
* prompt: 'Fetch and summarize: {{text}}'
|
|
299
|
+
* }
|
|
300
|
+
* ]
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* Use {{text}} as placeholder for user input.
|
|
304
|
+
*/
|
|
305
|
+
slashCommands?: (string | SlashCommandConfig)[];
|
|
306
|
+
/**
|
|
307
|
+
* Customize the Slack app manifest before it's sent to the Manifest API.
|
|
308
|
+
*
|
|
309
|
+
* Receives the default manifest (built from name, description, slashCommands,
|
|
310
|
+
* and internal URLs) and returns the final manifest to use.
|
|
311
|
+
*
|
|
312
|
+
* Use this for any advanced Slack configuration: custom scopes, events,
|
|
313
|
+
* interactivity settings, etc.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* // Add extra scopes
|
|
317
|
+
* manifest: (m) => ({
|
|
318
|
+
* ...m,
|
|
319
|
+
* oauth_config: {
|
|
320
|
+
* ...m.oauth_config,
|
|
321
|
+
* scopes: { bot: [...(m.oauth_config?.scopes?.bot ?? []), 'files:write'] }
|
|
322
|
+
* }
|
|
323
|
+
* })
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* // Subscribe to additional events
|
|
327
|
+
* manifest: (m) => ({
|
|
328
|
+
* ...m,
|
|
329
|
+
* settings: {
|
|
330
|
+
* ...m.settings,
|
|
331
|
+
* event_subscriptions: {
|
|
332
|
+
* ...m.settings?.event_subscriptions,
|
|
333
|
+
* bot_events: [...(m.settings?.event_subscriptions?.bot_events ?? []), 'reaction_added']
|
|
334
|
+
* }
|
|
335
|
+
* }
|
|
336
|
+
* })
|
|
337
|
+
*/
|
|
338
|
+
manifest?: (defaults: SlackAppManifest) => SlackAppManifest;
|
|
339
|
+
/**
|
|
340
|
+
* URL to redirect to after successful OAuth completion.
|
|
341
|
+
* Typically set by the Studio UI to return to the agent page.
|
|
342
|
+
* Defaults to `SlackProviderConfig.redirectPath` or `/`.
|
|
343
|
+
*/
|
|
344
|
+
redirectUrl?: string;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Slash command configuration (fully serializable).
|
|
348
|
+
*
|
|
349
|
+
* A slash command is essentially a prompt template that gets filled with user input
|
|
350
|
+
* and sent to the agent. Like Claude Code's slash commands.
|
|
351
|
+
*/
|
|
352
|
+
interface SlashCommandConfig {
|
|
353
|
+
/** Command name including slash (e.g., "/ask") */
|
|
354
|
+
command: string;
|
|
355
|
+
/** Short description shown in Slack's command picker */
|
|
356
|
+
description?: string;
|
|
357
|
+
/** Usage hint shown in Slack (e.g., "[question]") */
|
|
358
|
+
usageHint?: string;
|
|
359
|
+
/**
|
|
360
|
+
* Prompt template sent to the agent.
|
|
361
|
+
* Use {{text}} as placeholder for user input.
|
|
362
|
+
*
|
|
363
|
+
* Defaults to "{{text}}" (just passes input directly).
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* prompt: 'Summarize the following URL: {{text}}'
|
|
367
|
+
* prompt: 'Write {{text}} in TypeScript'
|
|
368
|
+
*/
|
|
369
|
+
prompt?: string;
|
|
370
|
+
}
|
|
371
|
+
interface SlackMessage {
|
|
372
|
+
text?: string;
|
|
373
|
+
blocks?: SlackBlock[];
|
|
374
|
+
response_type?: 'in_channel' | 'ephemeral';
|
|
375
|
+
replace_original?: boolean;
|
|
376
|
+
delete_original?: boolean;
|
|
377
|
+
}
|
|
378
|
+
interface SlackBlock {
|
|
379
|
+
type: string;
|
|
380
|
+
[key: string]: unknown;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Slack App Manifest for programmatic app creation.
|
|
384
|
+
* @see https://api.slack.com/reference/manifests
|
|
385
|
+
*/
|
|
386
|
+
interface SlackAppManifest {
|
|
387
|
+
display_information: {
|
|
388
|
+
name: string;
|
|
389
|
+
description?: string;
|
|
390
|
+
background_color?: string;
|
|
391
|
+
long_description?: string;
|
|
392
|
+
};
|
|
393
|
+
features?: {
|
|
394
|
+
app_home?: {
|
|
395
|
+
home_tab_enabled?: boolean;
|
|
396
|
+
messages_tab_enabled?: boolean;
|
|
397
|
+
messages_tab_read_only_enabled?: boolean;
|
|
398
|
+
};
|
|
399
|
+
bot_user?: {
|
|
400
|
+
display_name: string;
|
|
401
|
+
always_online?: boolean;
|
|
402
|
+
};
|
|
403
|
+
slash_commands?: Array<{
|
|
404
|
+
command: string;
|
|
405
|
+
description: string;
|
|
406
|
+
url: string;
|
|
407
|
+
usage_hint?: string;
|
|
408
|
+
}>;
|
|
409
|
+
};
|
|
410
|
+
oauth_config?: {
|
|
411
|
+
redirect_urls?: string[];
|
|
412
|
+
scopes?: {
|
|
413
|
+
bot?: string[];
|
|
414
|
+
user?: string[];
|
|
415
|
+
};
|
|
416
|
+
};
|
|
417
|
+
settings?: {
|
|
418
|
+
event_subscriptions?: {
|
|
419
|
+
request_url?: string;
|
|
420
|
+
bot_events?: string[];
|
|
421
|
+
user_events?: string[];
|
|
422
|
+
};
|
|
423
|
+
interactivity?: {
|
|
424
|
+
is_enabled?: boolean;
|
|
425
|
+
request_url?: string;
|
|
426
|
+
message_menu_options_url?: string;
|
|
427
|
+
};
|
|
428
|
+
org_deploy_enabled?: boolean;
|
|
429
|
+
socket_mode_enabled?: boolean;
|
|
430
|
+
token_rotation_enabled?: boolean;
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Credentials returned when creating a Slack app via manifest API.
|
|
435
|
+
*/
|
|
436
|
+
interface SlackAppCredentials {
|
|
437
|
+
appId: string;
|
|
438
|
+
clientId: string;
|
|
439
|
+
clientSecret: string;
|
|
440
|
+
signingSecret: string;
|
|
441
|
+
oauthAuthorizeUrl?: string;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Slack channel integration for Mastra.
|
|
446
|
+
*
|
|
447
|
+
* Handles:
|
|
448
|
+
* - Programmatic Slack app creation via manifest API
|
|
449
|
+
* - OAuth flow for Slack workspace installations
|
|
450
|
+
* - Webhook routing for events and slash commands
|
|
451
|
+
* - Message handling via @chat-adapter/slack
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```ts
|
|
455
|
+
* import { SlackProvider } from '@mastra/slack';
|
|
456
|
+
*
|
|
457
|
+
* // With credentials at construction
|
|
458
|
+
* const slack = new SlackProvider({
|
|
459
|
+
* refreshToken: process.env.SLACK_APP_CONFIG_REFRESH_TOKEN,
|
|
460
|
+
* });
|
|
461
|
+
*
|
|
462
|
+
* // Or configure later (e.g., credentials from UI or vault)
|
|
463
|
+
* const slack = new SlackProvider();
|
|
464
|
+
* await slack.configure({ refreshToken: 'xoxe-1-...' });
|
|
465
|
+
*
|
|
466
|
+
* const mastra = new Mastra({
|
|
467
|
+
* agents: { myAgent },
|
|
468
|
+
* channels: { slack },
|
|
469
|
+
* });
|
|
470
|
+
*
|
|
471
|
+
* // Connect an agent to Slack (creates app, returns OAuth connect result)
|
|
472
|
+
* const result = await slack.connect('my-agent', {
|
|
473
|
+
* name: 'My Bot',
|
|
474
|
+
* slashCommands: ['/ask', '/help'],
|
|
475
|
+
* });
|
|
476
|
+
* if (result.type === 'oauth') {
|
|
477
|
+
* // Redirect user to result.authorizationUrl
|
|
478
|
+
* }
|
|
479
|
+
* ```
|
|
480
|
+
*/
|
|
481
|
+
declare class SlackProvider implements ChannelProvider {
|
|
482
|
+
#private;
|
|
483
|
+
readonly id = "slack";
|
|
484
|
+
constructor(config?: SlackProviderConfig);
|
|
485
|
+
/**
|
|
486
|
+
* Provide or clear Slack App Configuration credentials at runtime.
|
|
487
|
+
*
|
|
488
|
+
* Use this when credentials aren't available at construction time — for example,
|
|
489
|
+
* when they're entered through the Editor UI or loaded from a vault.
|
|
490
|
+
*
|
|
491
|
+
* Pass `null` to clear credentials and delete stored tokens.
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```ts
|
|
495
|
+
* const slack = new SlackProvider();
|
|
496
|
+
* // Provide credentials (persists to storage immediately):
|
|
497
|
+
* await slack.configure({ refreshToken: 'xoxe-1-...' });
|
|
498
|
+
* // Clear credentials and stored tokens:
|
|
499
|
+
* await slack.configure(null);
|
|
500
|
+
* ```
|
|
501
|
+
*/
|
|
502
|
+
configure(credentials: {
|
|
503
|
+
refreshToken: string;
|
|
504
|
+
token?: string;
|
|
505
|
+
} | null): Promise<void>;
|
|
506
|
+
/**
|
|
507
|
+
* Called by Mastra when this channel is registered.
|
|
508
|
+
* @internal
|
|
509
|
+
*/
|
|
510
|
+
__attach(mastra: Mastra): void;
|
|
511
|
+
/**
|
|
512
|
+
* Set the base URL for webhook callbacks.
|
|
513
|
+
* Only needed if not using Mastra server config.
|
|
514
|
+
*/
|
|
515
|
+
setBaseUrl(baseUrl: string): void;
|
|
516
|
+
/**
|
|
517
|
+
* Restore active Slack installations from storage.
|
|
518
|
+
*
|
|
519
|
+
* For each active installation in the database, this creates a SlackAdapter
|
|
520
|
+
* and injects AgentChannels into the corresponding Agent so it can receive
|
|
521
|
+
* Slack events immediately on startup.
|
|
522
|
+
*
|
|
523
|
+
* Does NOT auto-provision new apps. Use `connect(agentId, options)` to
|
|
524
|
+
* create a new Slack app for an agent.
|
|
525
|
+
*/
|
|
526
|
+
initialize(): Promise<void>;
|
|
527
|
+
/**
|
|
528
|
+
* Get API routes for the Mastra server.
|
|
529
|
+
* Add these to your Mastra config via `server.apiRoutes`.
|
|
530
|
+
*
|
|
531
|
+
* The mastra instance is automatically injected via createHandler.
|
|
532
|
+
* On first request, auto-initializes any agents with slack configs.
|
|
533
|
+
*/
|
|
534
|
+
getRoutes(): ApiRoute[];
|
|
535
|
+
/**
|
|
536
|
+
* Connect an agent to Slack by creating a new Slack app.
|
|
537
|
+
*
|
|
538
|
+
* @returns OAuth connect result with authorization URL for user redirect
|
|
539
|
+
*/
|
|
540
|
+
connect(agentId: string, options?: SlackConnectOptions): Promise<ChannelConnectResult>;
|
|
541
|
+
/**
|
|
542
|
+
* Disconnect an agent from Slack by deleting its app.
|
|
543
|
+
*/
|
|
544
|
+
disconnect(agentId: string): Promise<void>;
|
|
545
|
+
/**
|
|
546
|
+
* Get the Slack installation for an agent.
|
|
547
|
+
*/
|
|
548
|
+
getInstallation(agentId: string): Promise<SlackInstallation | null>;
|
|
549
|
+
/**
|
|
550
|
+
* List all Slack installations (public info only).
|
|
551
|
+
* Includes both active and pending installations.
|
|
552
|
+
*/
|
|
553
|
+
listInstallations(): Promise<ChannelInstallationInfo[]>;
|
|
554
|
+
/**
|
|
555
|
+
* Discovery metadata for the editor UI.
|
|
556
|
+
*/
|
|
557
|
+
getInfo(): ChannelPlatformInfo;
|
|
558
|
+
/**
|
|
559
|
+
* Check if the provider has credentials and can create/manage Slack apps.
|
|
560
|
+
* Returns false if no refresh token has been provided via constructor, `configure()`, or storage.
|
|
561
|
+
*/
|
|
562
|
+
isConfigured(): boolean;
|
|
563
|
+
/**
|
|
564
|
+
* Get the SlackAdapter for an installation.
|
|
565
|
+
* Used internally for message formatting and posting.
|
|
566
|
+
*/
|
|
567
|
+
getAdapter(installationId: string): SlackAdapter | undefined;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
interface SlackManifestClientConfig {
|
|
571
|
+
token: string;
|
|
572
|
+
refreshToken: string;
|
|
573
|
+
onTokenRotation?: (tokens: {
|
|
574
|
+
token: string;
|
|
575
|
+
refreshToken: string;
|
|
576
|
+
}) => Promise<void>;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Client for Slack's App Manifest API.
|
|
580
|
+
* Handles programmatic app creation, deletion, and token rotation.
|
|
581
|
+
*/
|
|
582
|
+
declare class SlackManifestClient {
|
|
583
|
+
#private;
|
|
584
|
+
constructor(config: SlackManifestClientConfig);
|
|
585
|
+
/**
|
|
586
|
+
* Get current tokens (after potential rotation).
|
|
587
|
+
*/
|
|
588
|
+
getTokens(): {
|
|
589
|
+
token: string;
|
|
590
|
+
refreshToken: string;
|
|
591
|
+
};
|
|
592
|
+
/**
|
|
593
|
+
* Update tokens (e.g., from storage on startup).
|
|
594
|
+
*/
|
|
595
|
+
setTokens(tokens: {
|
|
596
|
+
token: string;
|
|
597
|
+
refreshToken: string;
|
|
598
|
+
}): void;
|
|
599
|
+
/**
|
|
600
|
+
* Rotate the configuration tokens.
|
|
601
|
+
* Slack config access tokens expire after 12 hours; the refresh token is single-use
|
|
602
|
+
* and each rotation returns a new access token + refresh token pair.
|
|
603
|
+
*
|
|
604
|
+
* Concurrent callers share the same in-flight rotation to avoid burning
|
|
605
|
+
* single-use refresh tokens.
|
|
606
|
+
*/
|
|
607
|
+
rotateToken(): Promise<void>;
|
|
608
|
+
/**
|
|
609
|
+
* Create a new Slack app from a manifest.
|
|
610
|
+
*/
|
|
611
|
+
createApp(manifest: SlackAppManifest): Promise<SlackAppCredentials>;
|
|
612
|
+
/**
|
|
613
|
+
* Delete a Slack app.
|
|
614
|
+
*/
|
|
615
|
+
deleteApp(appId: string): Promise<void>;
|
|
616
|
+
/**
|
|
617
|
+
* Update an existing Slack app's manifest.
|
|
618
|
+
*/
|
|
619
|
+
updateApp(appId: string, manifest: SlackAppManifest): Promise<void>;
|
|
620
|
+
/**
|
|
621
|
+
* Set the app icon via undocumented apps.icon.set API.
|
|
622
|
+
*/
|
|
623
|
+
setAppIcon(appId: string, imageData: ArrayBuffer): Promise<void>;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Verify a Slack request signature.
|
|
628
|
+
* @see https://api.slack.com/authentication/verifying-requests-from-slack
|
|
629
|
+
*/
|
|
630
|
+
declare function verifySlackRequest(params: {
|
|
631
|
+
signingSecret: string;
|
|
632
|
+
timestamp: string;
|
|
633
|
+
body: string;
|
|
634
|
+
signature: string;
|
|
635
|
+
}): boolean;
|
|
636
|
+
/**
|
|
637
|
+
* Parse URL-encoded form body from Slack slash commands.
|
|
638
|
+
* Uses URLSearchParams which correctly handles `+` as space.
|
|
639
|
+
*/
|
|
640
|
+
declare function parseSlackFormBody(body: string): Record<string, string>;
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Slash command for manifest building.
|
|
644
|
+
* Simplified version of SlashCommandConfig for manifest generation.
|
|
645
|
+
*/
|
|
646
|
+
interface SlashCommand {
|
|
647
|
+
command: string;
|
|
648
|
+
description?: string;
|
|
649
|
+
usageHint?: string;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Default bot scopes required for agent functionality.
|
|
653
|
+
*/
|
|
654
|
+
declare const DEFAULT_BOT_SCOPES: readonly ["chat:write", "chat:write.public", "im:write", "channels:history", "channels:read", "groups:history", "groups:read", "im:history", "im:read", "mpim:history", "mpim:read", "app_mentions:read", "users:read", "reactions:write", "files:read"];
|
|
655
|
+
/**
|
|
656
|
+
* Default bot events to subscribe to.
|
|
657
|
+
*/
|
|
658
|
+
declare const DEFAULT_BOT_EVENTS: readonly ["app_mention", "message.channels", "message.groups", "message.im", "message.mpim"];
|
|
659
|
+
interface BuildManifestOptions {
|
|
660
|
+
/** Display name for the Slack app */
|
|
661
|
+
name: string;
|
|
662
|
+
/** Description shown in Slack */
|
|
663
|
+
description?: string;
|
|
664
|
+
/** URL for event webhooks */
|
|
665
|
+
webhookUrl: string;
|
|
666
|
+
/** URL for OAuth redirect */
|
|
667
|
+
oauthRedirectUrl: string;
|
|
668
|
+
/** URL for slash command webhooks (defaults to webhookUrl) */
|
|
669
|
+
commandsUrl?: string;
|
|
670
|
+
/** Slash commands to register */
|
|
671
|
+
slashCommands?: SlashCommand[];
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Build a Slack app manifest for an agent.
|
|
675
|
+
*/
|
|
676
|
+
declare function buildManifest(options: BuildManifestOptions): SlackAppManifest;
|
|
677
|
+
|
|
678
|
+
export { DEFAULT_BOT_EVENTS, DEFAULT_BOT_SCOPES, type SlackAppManifest, type SlackBlock, type SlackConfigData, SlackConfigDataSchema, type SlackConfigTokens, type SlackConnectOptions, type SlackInstallation, type SlackInstallationData, SlackInstallationDataSchema, SlackManifestClient, type SlackMessage, type SlackPendingData, SlackPendingDataSchema, type SlackPendingInstallation, SlackProvider, type SlackProviderConfig, type SlashCommandConfig, buildManifest, parseSlackFormBody, verifySlackRequest };
|