digital-tools 2.0.2 → 2.1.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/CHANGELOG.md +17 -0
- package/package.json +3 -4
- package/src/define.js +267 -0
- package/src/entities/advertising.js +999 -0
- package/src/entities/ai.js +756 -0
- package/src/entities/analytics.js +1588 -0
- package/src/entities/automation.js +601 -0
- package/src/entities/communication.js +1150 -0
- package/src/entities/crm.js +1386 -0
- package/src/entities/design.js +546 -0
- package/src/entities/development.js +2212 -0
- package/src/entities/document.js +874 -0
- package/src/entities/ecommerce.js +1429 -0
- package/src/entities/experiment.js +1039 -0
- package/src/entities/finance.js +3478 -0
- package/src/entities/forms.js +1892 -0
- package/src/entities/hr.js +661 -0
- package/src/entities/identity.js +997 -0
- package/src/entities/index.js +282 -0
- package/src/entities/infrastructure.js +1153 -0
- package/src/entities/knowledge.js +1438 -0
- package/src/entities/marketing.js +1610 -0
- package/src/entities/media.js +1634 -0
- package/src/entities/notification.js +1199 -0
- package/src/entities/presentation.js +1274 -0
- package/src/entities/productivity.js +1317 -0
- package/src/entities/project-management.js +1136 -0
- package/src/entities/recruiting.js +736 -0
- package/src/entities/shipping.js +509 -0
- package/src/entities/signature.js +1102 -0
- package/src/entities/site.js +222 -0
- package/src/entities/spreadsheet.js +1341 -0
- package/src/entities/storage.js +1198 -0
- package/src/entities/support.js +1166 -0
- package/src/entities/video-conferencing.js +1750 -0
- package/src/entities/video.js +950 -0
- package/src/entities.js +1663 -0
- package/src/index.js +74 -0
- package/src/providers/analytics/index.js +17 -0
- package/src/providers/analytics/mixpanel.js +255 -0
- package/src/providers/calendar/cal-com.js +303 -0
- package/src/providers/calendar/google-calendar.js +335 -0
- package/src/providers/calendar/index.js +20 -0
- package/src/providers/crm/hubspot.js +566 -0
- package/src/providers/crm/index.js +17 -0
- package/src/providers/development/github.js +472 -0
- package/src/providers/development/index.js +17 -0
- package/src/providers/ecommerce/index.js +17 -0
- package/src/providers/ecommerce/shopify.js +378 -0
- package/src/providers/email/index.js +20 -0
- package/src/providers/email/resend.js +258 -0
- package/src/providers/email/sendgrid.js +161 -0
- package/src/providers/finance/index.js +17 -0
- package/src/providers/finance/stripe.js +549 -0
- package/src/providers/forms/index.js +17 -0
- package/src/providers/forms/typeform.js +500 -0
- package/src/providers/index.js +123 -0
- package/src/providers/knowledge/index.js +17 -0
- package/src/providers/knowledge/notion.js +389 -0
- package/src/providers/marketing/index.js +17 -0
- package/src/providers/marketing/mailchimp.js +443 -0
- package/src/providers/media/cloudinary.js +318 -0
- package/src/providers/media/index.js +17 -0
- package/src/providers/messaging/index.js +20 -0
- package/src/providers/messaging/slack.js +393 -0
- package/src/providers/messaging/twilio-sms.js +249 -0
- package/src/providers/project-management/index.js +17 -0
- package/src/providers/project-management/linear.js +575 -0
- package/src/providers/registry.js +86 -0
- package/src/providers/spreadsheet/google-sheets.js +375 -0
- package/src/providers/spreadsheet/index.js +20 -0
- package/src/providers/spreadsheet/xlsx.js +423 -0
- package/src/providers/storage/index.js +24 -0
- package/src/providers/storage/s3.js +419 -0
- package/src/providers/support/index.js +17 -0
- package/src/providers/support/zendesk.js +373 -0
- package/src/providers/tasks/index.js +17 -0
- package/src/providers/tasks/todoist.js +286 -0
- package/src/providers/types.js +9 -0
- package/src/providers/video-conferencing/google-meet.js +286 -0
- package/src/providers/video-conferencing/index.js +31 -0
- package/src/providers/video-conferencing/jitsi.js +254 -0
- package/src/providers/video-conferencing/teams.js +270 -0
- package/src/providers/video-conferencing/zoom.js +332 -0
- package/src/registry.js +128 -0
- package/src/tools/communication.js +184 -0
- package/src/tools/data.js +205 -0
- package/src/tools/index.js +11 -0
- package/src/tools/web.js +137 -0
- package/src/types.js +10 -0
- package/test/define.test.js +306 -0
- package/test/registry.test.js +357 -0
- package/test/tools.test.js +363 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack Messaging Provider
|
|
3
|
+
*
|
|
4
|
+
* Concrete implementation of MessagingProvider using Slack API.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import { defineProvider } from '../registry.js';
|
|
9
|
+
const SLACK_API_URL = 'https://slack.com/api';
|
|
10
|
+
/**
|
|
11
|
+
* Slack provider info
|
|
12
|
+
*/
|
|
13
|
+
export const slackInfo = {
|
|
14
|
+
id: 'messaging.slack',
|
|
15
|
+
name: 'Slack',
|
|
16
|
+
description: 'Slack team messaging platform',
|
|
17
|
+
category: 'messaging',
|
|
18
|
+
website: 'https://slack.com',
|
|
19
|
+
docsUrl: 'https://api.slack.com/docs',
|
|
20
|
+
requiredConfig: ['accessToken'],
|
|
21
|
+
optionalConfig: ['botToken', 'signingSecret'],
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Create Slack messaging provider
|
|
25
|
+
*/
|
|
26
|
+
export function createSlackProvider(config) {
|
|
27
|
+
let token;
|
|
28
|
+
async function slackApi(method, body) {
|
|
29
|
+
const response = await fetch(`${SLACK_API_URL}/${method}`, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
33
|
+
Authorization: `Bearer ${token}`,
|
|
34
|
+
},
|
|
35
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
36
|
+
});
|
|
37
|
+
const data = await response.json();
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
info: slackInfo,
|
|
42
|
+
async initialize(cfg) {
|
|
43
|
+
token = (cfg.accessToken || cfg.botToken);
|
|
44
|
+
if (!token) {
|
|
45
|
+
throw new Error('Slack access token or bot token is required');
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
async healthCheck() {
|
|
49
|
+
const start = Date.now();
|
|
50
|
+
try {
|
|
51
|
+
const data = await slackApi('auth.test');
|
|
52
|
+
return {
|
|
53
|
+
healthy: data.ok === true,
|
|
54
|
+
latencyMs: Date.now() - start,
|
|
55
|
+
message: data.ok ? `Connected as ${data.user}` : data.error,
|
|
56
|
+
checkedAt: new Date(),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return {
|
|
61
|
+
healthy: false,
|
|
62
|
+
latencyMs: Date.now() - start,
|
|
63
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
64
|
+
checkedAt: new Date(),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
async dispose() {
|
|
69
|
+
// No cleanup needed
|
|
70
|
+
},
|
|
71
|
+
async send(options) {
|
|
72
|
+
const body = {
|
|
73
|
+
text: options.text,
|
|
74
|
+
};
|
|
75
|
+
if (options.channel) {
|
|
76
|
+
body.channel = options.channel;
|
|
77
|
+
}
|
|
78
|
+
else if (options.userId) {
|
|
79
|
+
// Open DM conversation first
|
|
80
|
+
const dm = await slackApi('conversations.open', { users: options.userId });
|
|
81
|
+
if (!dm.ok) {
|
|
82
|
+
return {
|
|
83
|
+
success: false,
|
|
84
|
+
error: { code: dm.error, message: `Failed to open DM: ${dm.error}` },
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
body.channel = dm.channel.id;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
error: { code: 'MISSING_TARGET', message: 'Either channel or userId is required' },
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (options.threadId) {
|
|
96
|
+
body.thread_ts = options.threadId;
|
|
97
|
+
}
|
|
98
|
+
if (options.blocks) {
|
|
99
|
+
body.blocks = options.blocks;
|
|
100
|
+
}
|
|
101
|
+
if (options.metadata) {
|
|
102
|
+
body.metadata = {
|
|
103
|
+
event_type: 'message_metadata',
|
|
104
|
+
event_payload: options.metadata,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const data = await slackApi('chat.postMessage', body);
|
|
108
|
+
if (data.ok) {
|
|
109
|
+
return {
|
|
110
|
+
success: true,
|
|
111
|
+
messageId: data.ts,
|
|
112
|
+
timestamp: data.ts,
|
|
113
|
+
channel: data.channel,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
success: false,
|
|
118
|
+
error: { code: data.error, message: data.error },
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
async edit(messageId, text, blocks) {
|
|
122
|
+
const body = {
|
|
123
|
+
ts: messageId,
|
|
124
|
+
text,
|
|
125
|
+
};
|
|
126
|
+
if (blocks) {
|
|
127
|
+
body.blocks = blocks;
|
|
128
|
+
}
|
|
129
|
+
const data = await slackApi('chat.update', body);
|
|
130
|
+
if (data.ok) {
|
|
131
|
+
return {
|
|
132
|
+
success: true,
|
|
133
|
+
messageId: data.ts,
|
|
134
|
+
timestamp: data.ts,
|
|
135
|
+
channel: data.channel,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
success: false,
|
|
140
|
+
error: { code: data.error, message: data.error },
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
async delete(messageId, channel) {
|
|
144
|
+
const data = await slackApi('chat.delete', { ts: messageId, channel });
|
|
145
|
+
return data.ok === true;
|
|
146
|
+
},
|
|
147
|
+
async react(messageId, channel, emoji) {
|
|
148
|
+
const data = await slackApi('reactions.add', {
|
|
149
|
+
name: emoji.replace(/:/g, ''),
|
|
150
|
+
timestamp: messageId,
|
|
151
|
+
channel,
|
|
152
|
+
});
|
|
153
|
+
return data.ok === true;
|
|
154
|
+
},
|
|
155
|
+
async unreact(messageId, channel, emoji) {
|
|
156
|
+
const data = await slackApi('reactions.remove', {
|
|
157
|
+
name: emoji.replace(/:/g, ''),
|
|
158
|
+
timestamp: messageId,
|
|
159
|
+
channel,
|
|
160
|
+
});
|
|
161
|
+
return data.ok === true;
|
|
162
|
+
},
|
|
163
|
+
async getMessage(messageId, channel) {
|
|
164
|
+
const data = await slackApi('conversations.history', {
|
|
165
|
+
channel,
|
|
166
|
+
latest: messageId,
|
|
167
|
+
inclusive: true,
|
|
168
|
+
limit: 1,
|
|
169
|
+
});
|
|
170
|
+
if (!data.ok || !data.messages?.length) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const msg = data.messages[0];
|
|
174
|
+
return mapSlackMessage(msg, channel);
|
|
175
|
+
},
|
|
176
|
+
async listMessages(channel, options) {
|
|
177
|
+
const body = {
|
|
178
|
+
channel,
|
|
179
|
+
limit: options?.limit || 100,
|
|
180
|
+
};
|
|
181
|
+
if (options?.cursor) {
|
|
182
|
+
body.cursor = options.cursor;
|
|
183
|
+
}
|
|
184
|
+
if (options?.since) {
|
|
185
|
+
body.oldest = (options.since.getTime() / 1000).toString();
|
|
186
|
+
}
|
|
187
|
+
if (options?.until) {
|
|
188
|
+
body.latest = (options.until.getTime() / 1000).toString();
|
|
189
|
+
}
|
|
190
|
+
const data = await slackApi('conversations.history', body);
|
|
191
|
+
if (!data.ok) {
|
|
192
|
+
return { items: [], hasMore: false };
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
items: data.messages.map((msg) => mapSlackMessage(msg, channel)),
|
|
196
|
+
hasMore: data.has_more || false,
|
|
197
|
+
nextCursor: data.response_metadata?.next_cursor,
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
async searchMessages(query, options) {
|
|
201
|
+
const data = await slackApi('search.messages', {
|
|
202
|
+
query,
|
|
203
|
+
count: options?.limit || 100,
|
|
204
|
+
page: options?.offset ? Math.floor(options.offset / (options.limit || 100)) + 1 : 1,
|
|
205
|
+
});
|
|
206
|
+
if (!data.ok) {
|
|
207
|
+
return { items: [], hasMore: false };
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
items: data.messages.matches.map((match) => mapSlackMessage(match, match.channel.id)),
|
|
211
|
+
hasMore: data.messages.paging.pages > data.messages.paging.page,
|
|
212
|
+
total: data.messages.total,
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
async listChannels(options) {
|
|
216
|
+
const body = {
|
|
217
|
+
limit: options?.limit || 100,
|
|
218
|
+
exclude_archived: options?.excludeArchived !== false,
|
|
219
|
+
};
|
|
220
|
+
if (options?.cursor) {
|
|
221
|
+
body.cursor = options.cursor;
|
|
222
|
+
}
|
|
223
|
+
if (options?.types) {
|
|
224
|
+
body.types = options.types.map((t) => (t === 'private' ? 'private_channel' : 'public_channel')).join(',');
|
|
225
|
+
}
|
|
226
|
+
const data = await slackApi('conversations.list', body);
|
|
227
|
+
if (!data.ok) {
|
|
228
|
+
return { items: [], hasMore: false };
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
items: data.channels.map(mapSlackChannel),
|
|
232
|
+
hasMore: data.response_metadata?.next_cursor ? true : false,
|
|
233
|
+
nextCursor: data.response_metadata?.next_cursor,
|
|
234
|
+
};
|
|
235
|
+
},
|
|
236
|
+
async getChannel(channelId) {
|
|
237
|
+
const data = await slackApi('conversations.info', { channel: channelId });
|
|
238
|
+
if (!data.ok) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
return mapSlackChannel(data.channel);
|
|
242
|
+
},
|
|
243
|
+
async createChannel(name, options) {
|
|
244
|
+
const body = {
|
|
245
|
+
name,
|
|
246
|
+
is_private: options?.isPrivate || false,
|
|
247
|
+
};
|
|
248
|
+
const data = await slackApi('conversations.create', body);
|
|
249
|
+
if (!data.ok) {
|
|
250
|
+
throw new Error(`Failed to create channel: ${data.error}`);
|
|
251
|
+
}
|
|
252
|
+
const channel = mapSlackChannel(data.channel);
|
|
253
|
+
// Set topic if provided
|
|
254
|
+
if (options?.topic) {
|
|
255
|
+
await slackApi('conversations.setTopic', {
|
|
256
|
+
channel: data.channel.id,
|
|
257
|
+
topic: options.topic,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
// Set description/purpose if provided
|
|
261
|
+
if (options?.description) {
|
|
262
|
+
await slackApi('conversations.setPurpose', {
|
|
263
|
+
channel: data.channel.id,
|
|
264
|
+
purpose: options.description,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return channel;
|
|
268
|
+
},
|
|
269
|
+
async archiveChannel(channelId) {
|
|
270
|
+
const data = await slackApi('conversations.archive', { channel: channelId });
|
|
271
|
+
return data.ok === true;
|
|
272
|
+
},
|
|
273
|
+
async joinChannel(channelId) {
|
|
274
|
+
const data = await slackApi('conversations.join', { channel: channelId });
|
|
275
|
+
return data.ok === true;
|
|
276
|
+
},
|
|
277
|
+
async leaveChannel(channelId) {
|
|
278
|
+
const data = await slackApi('conversations.leave', { channel: channelId });
|
|
279
|
+
return data.ok === true;
|
|
280
|
+
},
|
|
281
|
+
async listMembers(options) {
|
|
282
|
+
const body = {
|
|
283
|
+
limit: options?.limit || 100,
|
|
284
|
+
};
|
|
285
|
+
if (options?.cursor) {
|
|
286
|
+
body.cursor = options.cursor;
|
|
287
|
+
}
|
|
288
|
+
let data;
|
|
289
|
+
if (options?.channel) {
|
|
290
|
+
// Get members of specific channel
|
|
291
|
+
data = await slackApi('conversations.members', { ...body, channel: options.channel });
|
|
292
|
+
if (!data.ok) {
|
|
293
|
+
return { items: [], hasMore: false };
|
|
294
|
+
}
|
|
295
|
+
// Fetch user info for each member
|
|
296
|
+
const members = await Promise.all(data.members.map(async (userId) => {
|
|
297
|
+
const userInfo = await slackApi('users.info', { user: userId });
|
|
298
|
+
return userInfo.ok ? mapSlackUser(userInfo.user) : null;
|
|
299
|
+
}));
|
|
300
|
+
return {
|
|
301
|
+
items: members.filter(Boolean),
|
|
302
|
+
hasMore: data.response_metadata?.next_cursor ? true : false,
|
|
303
|
+
nextCursor: data.response_metadata?.next_cursor,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
// Get all workspace members
|
|
308
|
+
data = await slackApi('users.list', body);
|
|
309
|
+
if (!data.ok) {
|
|
310
|
+
return { items: [], hasMore: false };
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
items: data.members.filter((m) => !m.deleted).map(mapSlackUser),
|
|
314
|
+
hasMore: data.response_metadata?.next_cursor ? true : false,
|
|
315
|
+
nextCursor: data.response_metadata?.next_cursor,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
async getMember(userId) {
|
|
320
|
+
const data = await slackApi('users.info', { user: userId });
|
|
321
|
+
if (!data.ok) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
return mapSlackUser(data.user);
|
|
325
|
+
},
|
|
326
|
+
async getPresence(userId) {
|
|
327
|
+
const data = await slackApi('users.getPresence', { user: userId });
|
|
328
|
+
return {
|
|
329
|
+
userId,
|
|
330
|
+
presence: data.presence === 'active' ? 'online' : 'away',
|
|
331
|
+
};
|
|
332
|
+
},
|
|
333
|
+
async getWorkspace() {
|
|
334
|
+
const data = await slackApi('team.info');
|
|
335
|
+
if (!data.ok) {
|
|
336
|
+
throw new Error(`Failed to get workspace info: ${data.error}`);
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
id: data.team.id,
|
|
340
|
+
name: data.team.name,
|
|
341
|
+
domain: data.team.domain,
|
|
342
|
+
icon: data.team.icon?.image_132,
|
|
343
|
+
};
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function mapSlackMessage(msg, channel) {
|
|
348
|
+
return {
|
|
349
|
+
id: msg.ts,
|
|
350
|
+
channel,
|
|
351
|
+
userId: msg.user,
|
|
352
|
+
text: msg.text,
|
|
353
|
+
timestamp: msg.ts,
|
|
354
|
+
threadId: msg.thread_ts,
|
|
355
|
+
replyCount: msg.reply_count,
|
|
356
|
+
reactions: msg.reactions?.map((r) => ({
|
|
357
|
+
emoji: r.name,
|
|
358
|
+
count: r.count,
|
|
359
|
+
users: r.users,
|
|
360
|
+
})),
|
|
361
|
+
edited: !!msg.edited,
|
|
362
|
+
editedAt: msg.edited?.ts ? new Date(parseFloat(msg.edited.ts) * 1000) : undefined,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function mapSlackChannel(ch) {
|
|
366
|
+
return {
|
|
367
|
+
id: ch.id,
|
|
368
|
+
name: ch.name,
|
|
369
|
+
topic: ch.topic?.value,
|
|
370
|
+
description: ch.purpose?.value,
|
|
371
|
+
isPrivate: ch.is_private || false,
|
|
372
|
+
isArchived: ch.is_archived || false,
|
|
373
|
+
memberCount: ch.num_members || 0,
|
|
374
|
+
createdAt: new Date(ch.created * 1000),
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function mapSlackUser(user) {
|
|
378
|
+
return {
|
|
379
|
+
id: user.id,
|
|
380
|
+
username: user.name,
|
|
381
|
+
displayName: user.real_name || user.profile?.display_name || user.name,
|
|
382
|
+
email: user.profile?.email,
|
|
383
|
+
avatar: user.profile?.image_192,
|
|
384
|
+
title: user.profile?.title,
|
|
385
|
+
isAdmin: user.is_admin || user.is_owner || false,
|
|
386
|
+
isBot: user.is_bot || false,
|
|
387
|
+
timezone: user.tz,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Slack provider definition
|
|
392
|
+
*/
|
|
393
|
+
export const slackProvider = defineProvider(slackInfo, async (config) => createSlackProvider(config));
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twilio SMS Provider
|
|
3
|
+
*
|
|
4
|
+
* Concrete implementation of SmsProvider using Twilio API.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import { defineProvider } from '../registry.js';
|
|
9
|
+
const TWILIO_API_URL = 'https://api.twilio.com/2010-04-01';
|
|
10
|
+
/**
|
|
11
|
+
* Twilio SMS provider info
|
|
12
|
+
*/
|
|
13
|
+
export const twilioSmsInfo = {
|
|
14
|
+
id: 'messaging.twilio-sms',
|
|
15
|
+
name: 'Twilio SMS',
|
|
16
|
+
description: 'Twilio SMS messaging service',
|
|
17
|
+
category: 'messaging',
|
|
18
|
+
website: 'https://twilio.com',
|
|
19
|
+
docsUrl: 'https://www.twilio.com/docs/sms',
|
|
20
|
+
requiredConfig: ['accountSid', 'authToken'],
|
|
21
|
+
optionalConfig: ['defaultFrom', 'messagingServiceSid'],
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Create Twilio SMS provider
|
|
25
|
+
*/
|
|
26
|
+
export function createTwilioSmsProvider(config) {
|
|
27
|
+
let accountSid;
|
|
28
|
+
let authToken;
|
|
29
|
+
let defaultFrom;
|
|
30
|
+
let messagingServiceSid;
|
|
31
|
+
function getAuthHeader() {
|
|
32
|
+
return `Basic ${Buffer.from(`${accountSid}:${authToken}`).toString('base64')}`;
|
|
33
|
+
}
|
|
34
|
+
async function twilioApi(path, method = 'GET', body) {
|
|
35
|
+
const url = `${TWILIO_API_URL}/Accounts/${accountSid}${path}`;
|
|
36
|
+
const response = await fetch(url, {
|
|
37
|
+
method,
|
|
38
|
+
headers: {
|
|
39
|
+
Authorization: getAuthHeader(),
|
|
40
|
+
...(body && { 'Content-Type': 'application/x-www-form-urlencoded' }),
|
|
41
|
+
},
|
|
42
|
+
body: body?.toString(),
|
|
43
|
+
});
|
|
44
|
+
return response.json();
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
info: twilioSmsInfo,
|
|
48
|
+
async initialize(cfg) {
|
|
49
|
+
accountSid = cfg.accountSid;
|
|
50
|
+
authToken = cfg.authToken;
|
|
51
|
+
defaultFrom = cfg.defaultFrom;
|
|
52
|
+
messagingServiceSid = cfg.messagingServiceSid;
|
|
53
|
+
if (!accountSid || !authToken) {
|
|
54
|
+
throw new Error('Twilio account SID and auth token are required');
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
async healthCheck() {
|
|
58
|
+
const start = Date.now();
|
|
59
|
+
try {
|
|
60
|
+
const data = await twilioApi('.json');
|
|
61
|
+
return {
|
|
62
|
+
healthy: data.status === 'active',
|
|
63
|
+
latencyMs: Date.now() - start,
|
|
64
|
+
message: data.status === 'active' ? 'Connected' : `Status: ${data.status}`,
|
|
65
|
+
checkedAt: new Date(),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return {
|
|
70
|
+
healthy: false,
|
|
71
|
+
latencyMs: Date.now() - start,
|
|
72
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
73
|
+
checkedAt: new Date(),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
async dispose() {
|
|
78
|
+
// No cleanup needed
|
|
79
|
+
},
|
|
80
|
+
async send(options) {
|
|
81
|
+
const from = options.from || defaultFrom;
|
|
82
|
+
if (!from && !messagingServiceSid) {
|
|
83
|
+
return {
|
|
84
|
+
success: false,
|
|
85
|
+
error: { code: 'MISSING_FROM', message: 'From number or messaging service SID is required' },
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const body = new URLSearchParams();
|
|
89
|
+
body.append('To', options.to);
|
|
90
|
+
body.append('Body', options.body);
|
|
91
|
+
if (messagingServiceSid) {
|
|
92
|
+
body.append('MessagingServiceSid', messagingServiceSid);
|
|
93
|
+
}
|
|
94
|
+
else if (from) {
|
|
95
|
+
body.append('From', from);
|
|
96
|
+
}
|
|
97
|
+
if (options.statusCallback) {
|
|
98
|
+
body.append('StatusCallback', options.statusCallback);
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const data = await twilioApi('/Messages.json', 'POST', body);
|
|
102
|
+
if (data.sid) {
|
|
103
|
+
return {
|
|
104
|
+
success: true,
|
|
105
|
+
messageId: data.sid,
|
|
106
|
+
status: data.status,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
error: {
|
|
112
|
+
code: data.code?.toString() || 'UNKNOWN',
|
|
113
|
+
message: data.message || 'Failed to send SMS',
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
return {
|
|
119
|
+
success: false,
|
|
120
|
+
error: {
|
|
121
|
+
code: 'NETWORK_ERROR',
|
|
122
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
async sendMms(options) {
|
|
128
|
+
const from = options.from || defaultFrom;
|
|
129
|
+
if (!from && !messagingServiceSid) {
|
|
130
|
+
return {
|
|
131
|
+
success: false,
|
|
132
|
+
error: { code: 'MISSING_FROM', message: 'From number or messaging service SID is required' },
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const body = new URLSearchParams();
|
|
136
|
+
body.append('To', options.to);
|
|
137
|
+
body.append('Body', options.body);
|
|
138
|
+
if (messagingServiceSid) {
|
|
139
|
+
body.append('MessagingServiceSid', messagingServiceSid);
|
|
140
|
+
}
|
|
141
|
+
else if (from) {
|
|
142
|
+
body.append('From', from);
|
|
143
|
+
}
|
|
144
|
+
// Add media URLs
|
|
145
|
+
options.mediaUrls.forEach((url) => {
|
|
146
|
+
body.append('MediaUrl', url);
|
|
147
|
+
});
|
|
148
|
+
if (options.statusCallback) {
|
|
149
|
+
body.append('StatusCallback', options.statusCallback);
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const data = await twilioApi('/Messages.json', 'POST', body);
|
|
153
|
+
if (data.sid) {
|
|
154
|
+
return {
|
|
155
|
+
success: true,
|
|
156
|
+
messageId: data.sid,
|
|
157
|
+
status: data.status,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
success: false,
|
|
162
|
+
error: {
|
|
163
|
+
code: data.code?.toString() || 'UNKNOWN',
|
|
164
|
+
message: data.message || 'Failed to send MMS',
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
return {
|
|
170
|
+
success: false,
|
|
171
|
+
error: {
|
|
172
|
+
code: 'NETWORK_ERROR',
|
|
173
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
async getStatus(messageId) {
|
|
179
|
+
const data = await twilioApi(`/Messages/${messageId}.json`);
|
|
180
|
+
return {
|
|
181
|
+
messageId: data.sid,
|
|
182
|
+
status: mapTwilioStatus(data.status),
|
|
183
|
+
errorCode: data.error_code?.toString(),
|
|
184
|
+
errorMessage: data.error_message,
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
async list(options) {
|
|
188
|
+
const params = new URLSearchParams();
|
|
189
|
+
if (options?.limit) {
|
|
190
|
+
params.append('PageSize', options.limit.toString());
|
|
191
|
+
}
|
|
192
|
+
if (options?.to) {
|
|
193
|
+
params.append('To', options.to);
|
|
194
|
+
}
|
|
195
|
+
if (options?.from) {
|
|
196
|
+
params.append('From', options.from);
|
|
197
|
+
}
|
|
198
|
+
if (options?.since) {
|
|
199
|
+
params.append('DateSent>', options.since.toISOString().split('T')[0]);
|
|
200
|
+
}
|
|
201
|
+
if (options?.until) {
|
|
202
|
+
params.append('DateSent<', options.until.toISOString().split('T')[0]);
|
|
203
|
+
}
|
|
204
|
+
const queryString = params.toString();
|
|
205
|
+
const path = `/Messages.json${queryString ? `?${queryString}` : ''}`;
|
|
206
|
+
const data = await twilioApi(path);
|
|
207
|
+
return {
|
|
208
|
+
items: data.messages?.map(mapTwilioMessage) || [],
|
|
209
|
+
hasMore: !!data.next_page_uri,
|
|
210
|
+
nextCursor: data.next_page_uri,
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function mapTwilioStatus(status) {
|
|
216
|
+
switch (status) {
|
|
217
|
+
case 'queued':
|
|
218
|
+
case 'accepted':
|
|
219
|
+
return 'queued';
|
|
220
|
+
case 'sending':
|
|
221
|
+
return 'sending';
|
|
222
|
+
case 'sent':
|
|
223
|
+
return 'sent';
|
|
224
|
+
case 'delivered':
|
|
225
|
+
return 'delivered';
|
|
226
|
+
case 'failed':
|
|
227
|
+
return 'failed';
|
|
228
|
+
case 'undelivered':
|
|
229
|
+
return 'undelivered';
|
|
230
|
+
default:
|
|
231
|
+
return 'queued';
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function mapTwilioMessage(msg) {
|
|
235
|
+
return {
|
|
236
|
+
id: msg.sid,
|
|
237
|
+
to: msg.to,
|
|
238
|
+
from: msg.from,
|
|
239
|
+
body: msg.body,
|
|
240
|
+
status: msg.status,
|
|
241
|
+
direction: msg.direction === 'inbound' ? 'inbound' : 'outbound',
|
|
242
|
+
sentAt: msg.date_sent ? new Date(msg.date_sent) : undefined,
|
|
243
|
+
deliveredAt: msg.status === 'delivered' ? new Date(msg.date_updated) : undefined,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Twilio SMS provider definition
|
|
248
|
+
*/
|
|
249
|
+
export const twilioSmsProvider = defineProvider(twilioSmsInfo, async (config) => createTwilioSmsProvider(config));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project Management Providers
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { linearInfo, linearProvider, createLinearProvider } from './linear.js';
|
|
7
|
+
import { linearProvider } from './linear.js';
|
|
8
|
+
/**
|
|
9
|
+
* Register all project management providers
|
|
10
|
+
*/
|
|
11
|
+
export function registerProjectManagementProviders() {
|
|
12
|
+
linearProvider.register();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* All project management providers
|
|
16
|
+
*/
|
|
17
|
+
export const projectManagementProviders = [linearProvider];
|