@mastra/slack 1.0.2 → 1.1.0-alpha.0

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 DELETED
@@ -1,359 +0,0 @@
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
- }