@mastra/slack 1.0.0 → 1.0.1

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/src/index.ts ADDED
@@ -0,0 +1,359 @@
1
+ import { Integration, IntegrationCredentialType, IntegrationAuth } from '@mastra/core';
2
+
3
+ // @ts-ignore
4
+ import SlackLogo from './assets/slack.png';
5
+ import { comments } from './client/service-comments';
6
+ import * as integrationClient from './client/services.gen';
7
+ import * as zodSchema from './client/zodSchema';
8
+
9
+ type SlackConfig = {
10
+ CLIENT_ID: string;
11
+ CLIENT_SECRET: string;
12
+
13
+ [key: string]: any;
14
+ };
15
+
16
+ export class SlackIntegration extends Integration {
17
+ categories = ['communications'];
18
+ description = 'Slack is a cloud-based team collaboration tool.';
19
+ availableScopes = [
20
+ {
21
+ key: `admin`,
22
+ description: `admin`,
23
+ },
24
+ {
25
+ key: `admin.apps:read`,
26
+ description: `admin.apps:read`,
27
+ },
28
+ {
29
+ key: `admin.apps:write`,
30
+ description: `admin.apps:write`,
31
+ },
32
+ {
33
+ key: `admin.conversations:read`,
34
+ description: `admin.conversations:read`,
35
+ },
36
+ {
37
+ key: `admin.conversations:write`,
38
+ description: `admin.conversations:write`,
39
+ },
40
+ {
41
+ key: `admin.invites:read`,
42
+ description: `admin.invites:read`,
43
+ },
44
+ {
45
+ key: `admin.invites:write`,
46
+ description: `admin.invites:write`,
47
+ },
48
+ {
49
+ key: `admin.teams:read`,
50
+ description: `admin.teams:read`,
51
+ },
52
+ {
53
+ key: `admin.teams:write`,
54
+ description: `admin.teams:write`,
55
+ },
56
+ {
57
+ key: `admin.usergroups:read`,
58
+ description: `admin.usergroups:read`,
59
+ },
60
+ {
61
+ key: `admin.usergroups:write`,
62
+ description: `admin.usergroups:write`,
63
+ },
64
+ {
65
+ key: `admin.users:read`,
66
+ description: `admin.users:read`,
67
+ },
68
+ {
69
+ key: `admin.users:write`,
70
+ description: `admin.users:write`,
71
+ },
72
+ {
73
+ key: `authorizations:read`,
74
+ description: `authorizations:read`,
75
+ },
76
+ {
77
+ key: `bot`,
78
+ description: `Bot user scope`,
79
+ },
80
+ {
81
+ key: `calls:read`,
82
+ description: `calls:read`,
83
+ },
84
+ {
85
+ key: `calls:write`,
86
+ description: `calls:write`,
87
+ },
88
+ {
89
+ key: `channels:history`,
90
+ description: `channels:history`,
91
+ },
92
+ {
93
+ key: `channels:manage`,
94
+ description: `channels:manage`,
95
+ },
96
+ {
97
+ key: `channels:read`,
98
+ description: `channels:read`,
99
+ },
100
+ {
101
+ key: `channels:write`,
102
+ description: `channels:write`,
103
+ },
104
+ {
105
+ key: `chat:write`,
106
+ description: `chat:write`,
107
+ },
108
+ {
109
+ key: `chat:write:bot`,
110
+ description: `Author messages as a bot`,
111
+ },
112
+ {
113
+ key: `chat:write:user`,
114
+ description: `Author messages as a user`,
115
+ },
116
+ {
117
+ key: `conversations:history`,
118
+ description: `conversations:history`,
119
+ },
120
+ {
121
+ key: `conversations:read`,
122
+ description: `conversations:read`,
123
+ },
124
+ {
125
+ key: `conversations:write`,
126
+ description: `conversations:write`,
127
+ },
128
+ {
129
+ key: `dnd:read`,
130
+ description: `dnd:read`,
131
+ },
132
+ {
133
+ key: `dnd:write`,
134
+ description: `dnd:write`,
135
+ },
136
+ {
137
+ key: `emoji:read`,
138
+ description: `emoji:read`,
139
+ },
140
+ {
141
+ key: `files:read`,
142
+ description: `files:read`,
143
+ },
144
+ {
145
+ key: `files:write:user`,
146
+ description: `files:write:user`,
147
+ },
148
+ {
149
+ key: `groups:history`,
150
+ description: `groups:history`,
151
+ },
152
+ {
153
+ key: `groups:read`,
154
+ description: `groups:read`,
155
+ },
156
+ {
157
+ key: `groups:write`,
158
+ description: `groups:write`,
159
+ },
160
+ {
161
+ key: `identity.basic`,
162
+ description: `identity.basic`,
163
+ },
164
+ {
165
+ key: `im:history`,
166
+ description: `im:history`,
167
+ },
168
+ {
169
+ key: `im:read`,
170
+ description: `im:read`,
171
+ },
172
+ {
173
+ key: `im:write`,
174
+ description: `im:write`,
175
+ },
176
+ {
177
+ key: `links:write`,
178
+ description: `links:write`,
179
+ },
180
+ {
181
+ key: `mpim:history`,
182
+ description: `mpim:history`,
183
+ },
184
+ {
185
+ key: `mpim:read`,
186
+ description: `mpim:read`,
187
+ },
188
+ {
189
+ key: `mpim:write`,
190
+ description: `mpim:write`,
191
+ },
192
+ {
193
+ key: `none`,
194
+ description: `No scope required`,
195
+ },
196
+ {
197
+ key: `pins:read`,
198
+ description: `pins:read`,
199
+ },
200
+ {
201
+ key: `pins:write`,
202
+ description: `pins:write`,
203
+ },
204
+ {
205
+ key: `reactions:read`,
206
+ description: `reactions:read`,
207
+ },
208
+ {
209
+ key: `reactions:write`,
210
+ description: `reactions:write`,
211
+ },
212
+ {
213
+ key: `reminders:read`,
214
+ description: `reminders:read`,
215
+ },
216
+ {
217
+ key: `reminders:write`,
218
+ description: `reminders:write`,
219
+ },
220
+ {
221
+ key: `remote_files:read`,
222
+ description: `remote_files:read`,
223
+ },
224
+ {
225
+ key: `remote_files:share`,
226
+ description: `remote_files:share`,
227
+ },
228
+ {
229
+ key: `remote_files:write`,
230
+ description: `remote_files:write`,
231
+ },
232
+ {
233
+ key: `rtm:stream`,
234
+ description: `rtm:stream`,
235
+ },
236
+ {
237
+ key: `search:read`,
238
+ description: `search:read`,
239
+ },
240
+ {
241
+ key: `stars:read`,
242
+ description: `stars:read`,
243
+ },
244
+ {
245
+ key: `stars:write`,
246
+ description: `stars:write`,
247
+ },
248
+ {
249
+ key: `team:read`,
250
+ description: `team:read`,
251
+ },
252
+ {
253
+ key: `tokens.basic`,
254
+ description: `tokens.basic`,
255
+ },
256
+ {
257
+ key: `usergroups:read`,
258
+ description: `usergroups:read`,
259
+ },
260
+ {
261
+ key: `usergroups:write`,
262
+ description: `usergroups:write`,
263
+ },
264
+ {
265
+ key: `users.profile:read`,
266
+ description: `users.profile:read`,
267
+ },
268
+ {
269
+ key: `users.profile:write`,
270
+ description: `users.profile:write`,
271
+ },
272
+ {
273
+ key: `users:read`,
274
+ description: `users:read`,
275
+ },
276
+ {
277
+ key: `users:read.email`,
278
+ description: `users:read.email`,
279
+ },
280
+ {
281
+ key: `users:write`,
282
+ description: `users:write`,
283
+ },
284
+ {
285
+ key: `workflow.steps:execute`,
286
+ description: `workflow.steps:execute`,
287
+ },
288
+ ];
289
+
290
+ constructor({ config }: { config: SlackConfig }) {
291
+ super({
292
+ ...config,
293
+ authType: IntegrationCredentialType.OAUTH,
294
+ name: 'SLACK',
295
+ logoUrl: SlackLogo,
296
+ });
297
+ }
298
+
299
+ getClientZodSchema() {
300
+ return zodSchema;
301
+ }
302
+
303
+ getCommentsForClientApis() {
304
+ return comments;
305
+ }
306
+
307
+ getBaseClient() {
308
+ integrationClient.client.setConfig({
309
+ baseUrl: 'https://slack.com/api',
310
+ });
311
+ return integrationClient;
312
+ }
313
+
314
+ getApiClient = async ({ connectionId }: { connectionId: string }) => {
315
+ const connection = await this.dataLayer?.getConnection({ name: this.name, connectionId });
316
+
317
+ if (!connection) {
318
+ throw new Error(`Connection not found for connectionId: ${connectionId}`);
319
+ }
320
+
321
+ const authenticator = this.getAuthenticator();
322
+ const { accessToken } = await authenticator.getAuthToken({ k_id: connection.id });
323
+
324
+ const baseClient = this.getBaseClient();
325
+
326
+ baseClient.client.interceptors.request.use((request, options) => {
327
+ request.headers.set('Authorization', `Bearer ${accessToken}`);
328
+ return request;
329
+ });
330
+
331
+ return integrationClient;
332
+ };
333
+
334
+ registerEvents() {
335
+ this.events = {};
336
+ return this.events;
337
+ }
338
+
339
+ getAuthenticator() {
340
+ return new IntegrationAuth({
341
+ dataAccess: this.dataLayer!,
342
+ // @ts-ignore
343
+ onConnectionCreated: () => {
344
+ // TODO
345
+ },
346
+ config: {
347
+ INTEGRATION_NAME: this.name,
348
+ AUTH_TYPE: this.config.authType,
349
+ CLIENT_ID: this.config.CLIENT_ID,
350
+ CLIENT_SECRET: this.config.CLIENT_SECRET,
351
+ REDIRECT_URI: this.config.REDIRECT_URI || this.corePresets.redirectURI,
352
+ SERVER: `https://slack.com/api`,
353
+ AUTHORIZATION_ENDPOINT: `https://slack.com/oauth/v2/authorize`,
354
+ TOKEN_ENDPOINT: `https://slack.com/api/oauth.v2.access`,
355
+ SCOPES: this.config.SCOPES || [],
356
+ },
357
+ });
358
+ }
359
+ }
@@ -1,9 +0,0 @@
1
- import { DataLayer, IntegrationApi } from '@mastra/core';
2
- import { z } from 'zod';
3
- import { CREATE_NEW_CHANNEL_SCHEMA, CREATE_NEW_CHANNEL_OUTPUT_SCHEMA } from '../schemas';
4
- import { MakeClient } from '../types';
5
- export declare const CREATE_NEW_CHANNEL: ({ name, makeClient, }: {
6
- name: string;
7
- dataAccess: DataLayer;
8
- makeClient: MakeClient;
9
- }) => IntegrationApi<z.infer<typeof CREATE_NEW_CHANNEL_SCHEMA>, z.infer<typeof CREATE_NEW_CHANNEL_OUTPUT_SCHEMA>>;
@@ -1,9 +0,0 @@
1
- import { DataLayer, IntegrationApi } from '@mastra/core';
2
- import { z } from 'zod';
3
- import { INVITE_TO_CHANNEL_SCHEMA } from '../schemas';
4
- import { MakeClient } from '../types';
5
- export declare const INVITE_TO_CHANNEL: ({ name, makeClient, }: {
6
- name: string;
7
- dataAccess: DataLayer;
8
- makeClient: MakeClient;
9
- }) => IntegrationApi<z.infer<typeof INVITE_TO_CHANNEL_SCHEMA>>;
@@ -1,9 +0,0 @@
1
- import { DataLayer, IntegrationApi } from '@mastra/core';
2
- import { z } from 'zod';
3
- import { SEND_MESSAGE_TO_CHANNEL_SCHEMA } from '../schemas';
4
- import { MakeClient } from '../types';
5
- export declare const SEND_MESSAGE_TO_CHANNEL: ({ name, dataAccess, makeClient, }: {
6
- name: string;
7
- dataAccess: DataLayer;
8
- makeClient: MakeClient;
9
- }) => IntegrationApi<z.infer<typeof SEND_MESSAGE_TO_CHANNEL_SCHEMA>>;
@@ -1,26 +0,0 @@
1
- export declare class SlackClient {
2
- private token;
3
- private client;
4
- constructor({ token }: {
5
- token: string;
6
- });
7
- getAllChannels(): Promise<import("@slack/web-api/dist/types/response/ConversationsListResponse").Channel[] | undefined>;
8
- channelByName(channelName: string): Promise<import("@slack/web-api/dist/types/response/ConversationsListResponse").Channel | undefined>;
9
- getActiveUsers(): Promise<import("@slack/web-api/dist/types/response/UsersListResponse").Member[] | undefined>;
10
- userIdsByNames(names: string[]): Promise<(string | undefined)[] | undefined>;
11
- sendMessage({ channelId, message }: {
12
- channelId: string;
13
- message: string;
14
- }): Promise<import("@slack/web-api").ChatPostMessageResponse>;
15
- invite({ channelId, users }: {
16
- channelId: string;
17
- users: string[];
18
- }): Promise<import("@slack/web-api").ConversationsInviteResponse>;
19
- createChannel({ name, isPrivate }: {
20
- name: string;
21
- isPrivate: boolean;
22
- }): Promise<import("@slack/web-api").ConversationsCreateResponse>;
23
- joinChannel({ channelId }: {
24
- channelId: string;
25
- }): Promise<import("@slack/web-api").ConversationsJoinResponse>;
26
- }
@@ -1 +0,0 @@
1
- export declare const SLACK_INTEGRATION_NAME = "SLACK";
@@ -1,38 +0,0 @@
1
- import { z } from 'zod';
2
- export declare const SEND_MESSAGE_TO_CHANNEL_SCHEMA: z.ZodObject<{
3
- channelId: z.ZodString;
4
- message: z.ZodString;
5
- }, "strip", z.ZodTypeAny, {
6
- channelId: string;
7
- message: string;
8
- }, {
9
- channelId: string;
10
- message: string;
11
- }>;
12
- export declare const CREATE_NEW_CHANNEL_SCHEMA: z.ZodObject<{
13
- channelName: z.ZodString;
14
- isPrivate: z.ZodEnum<["true", "false"]>;
15
- }, "strip", z.ZodTypeAny, {
16
- channelName: string;
17
- isPrivate: "true" | "false";
18
- }, {
19
- channelName: string;
20
- isPrivate: "true" | "false";
21
- }>;
22
- export declare const CREATE_NEW_CHANNEL_OUTPUT_SCHEMA: z.ZodObject<{
23
- channelId: z.ZodNullable<z.ZodString>;
24
- }, "strip", z.ZodTypeAny, {
25
- channelId: string | null;
26
- }, {
27
- channelId: string | null;
28
- }>;
29
- export declare const INVITE_TO_CHANNEL_SCHEMA: z.ZodObject<{
30
- channelId: z.ZodString;
31
- users: z.ZodArray<z.ZodString, "many">;
32
- }, "strip", z.ZodTypeAny, {
33
- channelId: string;
34
- users: string[];
35
- }, {
36
- channelId: string;
37
- users: string[];
38
- }>;
@@ -1,3 +0,0 @@
1
- import { IntegrationContext } from '@mastra/core';
2
- import { SlackClient } from './client';
3
- export type MakeClient = (context: IntegrationContext) => Promise<SlackClient>;