spectrum-ts 0.4.0 → 0.6.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/dist/chunk-UZWRB3FZ.js +624 -0
- package/dist/chunk-XZTTLPHE.js +341 -0
- package/dist/index.d.ts +137 -5
- package/dist/index.js +158 -79
- package/dist/providers/imessage/index.d.ts +1 -1
- package/dist/providers/imessage/index.js +369 -69
- package/dist/providers/terminal/index.d.ts +1 -1
- package/dist/providers/terminal/index.js +7 -3
- package/dist/providers/whatsapp-business/index.d.ts +1 -1
- package/dist/providers/whatsapp-business/index.js +289 -35
- package/dist/{types-BdWMydUJ.d.ts → types-DZMHfgYQ.d.ts} +102 -13
- package/package.json +9 -2
- package/dist/chunk-5XW4CAWS.js +0 -165
- package/dist/chunk-XEEDIGVK.js +0 -199
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
asAttachment,
|
|
3
|
+
asContact,
|
|
3
4
|
asCustom,
|
|
4
5
|
stream
|
|
5
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-UZWRB3FZ.js";
|
|
6
7
|
import {
|
|
7
8
|
asText,
|
|
8
9
|
definePlatform
|
|
9
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-XZTTLPHE.js";
|
|
10
11
|
|
|
11
12
|
// src/providers/whatsapp-business/index.ts
|
|
12
13
|
import {
|
|
@@ -14,13 +15,155 @@ import {
|
|
|
14
15
|
} from "@photon-ai/whatsapp-business";
|
|
15
16
|
|
|
16
17
|
// src/providers/whatsapp-business/messages.ts
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
sender: { id: msg.from },
|
|
21
|
-
space: { id: msg.from },
|
|
22
|
-
timestamp: msg.timestamp
|
|
18
|
+
import { extension as mimeExtension } from "mime-types";
|
|
19
|
+
var toSendResult = (result) => ({
|
|
20
|
+
id: result.messageId
|
|
23
21
|
});
|
|
22
|
+
var mapWaPhoneType = (type) => {
|
|
23
|
+
if (!type) {
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
const upper = type.toUpperCase();
|
|
27
|
+
if (upper === "CELL" || upper === "MOBILE" || upper === "IPHONE") {
|
|
28
|
+
return "mobile";
|
|
29
|
+
}
|
|
30
|
+
if (upper === "HOME") {
|
|
31
|
+
return "home";
|
|
32
|
+
}
|
|
33
|
+
if (upper === "WORK" || upper === "BUSINESS") {
|
|
34
|
+
return "work";
|
|
35
|
+
}
|
|
36
|
+
return "other";
|
|
37
|
+
};
|
|
38
|
+
var mapWaSimpleType = (type) => {
|
|
39
|
+
if (!type) {
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
const upper = type.toUpperCase();
|
|
43
|
+
if (upper === "HOME") {
|
|
44
|
+
return "home";
|
|
45
|
+
}
|
|
46
|
+
if (upper === "WORK" || upper === "BUSINESS") {
|
|
47
|
+
return "work";
|
|
48
|
+
}
|
|
49
|
+
return "other";
|
|
50
|
+
};
|
|
51
|
+
var waNameToSpectrum = (name) => {
|
|
52
|
+
const result = { formatted: name.formattedName };
|
|
53
|
+
if (name.firstName) {
|
|
54
|
+
result.first = name.firstName;
|
|
55
|
+
}
|
|
56
|
+
if (name.lastName) {
|
|
57
|
+
result.last = name.lastName;
|
|
58
|
+
}
|
|
59
|
+
if (name.middleName) {
|
|
60
|
+
result.middle = name.middleName;
|
|
61
|
+
}
|
|
62
|
+
if (name.prefix) {
|
|
63
|
+
result.prefix = name.prefix;
|
|
64
|
+
}
|
|
65
|
+
if (name.suffix) {
|
|
66
|
+
result.suffix = name.suffix;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
var waPhoneToSpectrum = (phone) => {
|
|
71
|
+
const entry = { value: phone.phone };
|
|
72
|
+
const type = mapWaPhoneType(phone.type);
|
|
73
|
+
if (type) {
|
|
74
|
+
entry.type = type;
|
|
75
|
+
}
|
|
76
|
+
return entry;
|
|
77
|
+
};
|
|
78
|
+
var waEmailToSpectrum = (email) => {
|
|
79
|
+
const entry = { value: email.email };
|
|
80
|
+
const type = mapWaSimpleType(email.type);
|
|
81
|
+
if (type) {
|
|
82
|
+
entry.type = type;
|
|
83
|
+
}
|
|
84
|
+
return entry;
|
|
85
|
+
};
|
|
86
|
+
var waAddressToSpectrum = (address) => {
|
|
87
|
+
const entry = {};
|
|
88
|
+
if (address.street) {
|
|
89
|
+
entry.street = address.street;
|
|
90
|
+
}
|
|
91
|
+
if (address.city) {
|
|
92
|
+
entry.city = address.city;
|
|
93
|
+
}
|
|
94
|
+
if (address.state) {
|
|
95
|
+
entry.region = address.state;
|
|
96
|
+
}
|
|
97
|
+
if (address.zip) {
|
|
98
|
+
entry.postalCode = address.zip;
|
|
99
|
+
}
|
|
100
|
+
if (address.country) {
|
|
101
|
+
entry.country = address.country;
|
|
102
|
+
}
|
|
103
|
+
const type = mapWaSimpleType(address.type);
|
|
104
|
+
if (type) {
|
|
105
|
+
entry.type = type;
|
|
106
|
+
}
|
|
107
|
+
return entry;
|
|
108
|
+
};
|
|
109
|
+
var waOrgToSpectrum = (org) => {
|
|
110
|
+
const entry = {};
|
|
111
|
+
if (org.company) {
|
|
112
|
+
entry.name = org.company;
|
|
113
|
+
}
|
|
114
|
+
if (org.title) {
|
|
115
|
+
entry.title = org.title;
|
|
116
|
+
}
|
|
117
|
+
if (org.department) {
|
|
118
|
+
entry.department = org.department;
|
|
119
|
+
}
|
|
120
|
+
return entry;
|
|
121
|
+
};
|
|
122
|
+
var waContactToSpectrum = (card) => {
|
|
123
|
+
const input = { raw: card };
|
|
124
|
+
input.name = waNameToSpectrum(card.name);
|
|
125
|
+
if (card.phones.length > 0) {
|
|
126
|
+
input.phones = card.phones.map(waPhoneToSpectrum);
|
|
127
|
+
}
|
|
128
|
+
if (card.emails.length > 0) {
|
|
129
|
+
input.emails = card.emails.map(waEmailToSpectrum);
|
|
130
|
+
}
|
|
131
|
+
if (card.addresses.length > 0) {
|
|
132
|
+
input.addresses = card.addresses.map(waAddressToSpectrum);
|
|
133
|
+
}
|
|
134
|
+
if (card.org) {
|
|
135
|
+
input.org = waOrgToSpectrum(card.org);
|
|
136
|
+
}
|
|
137
|
+
if (card.urls.length > 0) {
|
|
138
|
+
input.urls = card.urls.map((u) => u.url);
|
|
139
|
+
}
|
|
140
|
+
if (card.birthday) {
|
|
141
|
+
input.birthday = card.birthday;
|
|
142
|
+
}
|
|
143
|
+
return asContact(input);
|
|
144
|
+
};
|
|
145
|
+
var toMessages = (client, msg) => {
|
|
146
|
+
const base = {
|
|
147
|
+
sender: { id: msg.from },
|
|
148
|
+
space: { id: msg.from },
|
|
149
|
+
timestamp: msg.timestamp
|
|
150
|
+
};
|
|
151
|
+
if (msg.content.type === "contacts") {
|
|
152
|
+
const multi = msg.content.contacts.length > 1;
|
|
153
|
+
return msg.content.contacts.map((card, index) => ({
|
|
154
|
+
...base,
|
|
155
|
+
id: multi ? `${msg.id}:${index}` : msg.id,
|
|
156
|
+
content: waContactToSpectrum(card)
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
return [
|
|
160
|
+
{
|
|
161
|
+
...base,
|
|
162
|
+
id: msg.id,
|
|
163
|
+
content: mapContent(client, msg.content)
|
|
164
|
+
}
|
|
165
|
+
];
|
|
166
|
+
};
|
|
24
167
|
var mapContent = (client, content) => {
|
|
25
168
|
switch (content.type) {
|
|
26
169
|
case "text":
|
|
@@ -34,11 +177,6 @@ var mapContent = (client, content) => {
|
|
|
34
177
|
return asCustom({ whatsapp_type: "sticker", ...content.sticker });
|
|
35
178
|
case "location":
|
|
36
179
|
return asCustom({ whatsapp_type: "location", ...content.location });
|
|
37
|
-
case "contacts":
|
|
38
|
-
return asCustom({
|
|
39
|
-
whatsapp_type: "contacts",
|
|
40
|
-
contacts: content.contacts
|
|
41
|
-
});
|
|
42
180
|
case "reaction":
|
|
43
181
|
return asCustom({ whatsapp_type: "reaction", ...content.reaction });
|
|
44
182
|
case "interactive":
|
|
@@ -85,6 +223,74 @@ var mimeToMediaType = (mimeType) => {
|
|
|
85
223
|
}
|
|
86
224
|
return "document";
|
|
87
225
|
};
|
|
226
|
+
var voiceFilename = (content) => {
|
|
227
|
+
if (content.name) {
|
|
228
|
+
return content.name;
|
|
229
|
+
}
|
|
230
|
+
const ext = mimeExtension(content.mimeType);
|
|
231
|
+
return ext ? `voice.${ext}` : "voice";
|
|
232
|
+
};
|
|
233
|
+
var spectrumPhoneTypeToWa = (type) => {
|
|
234
|
+
if (type === "mobile") {
|
|
235
|
+
return "CELL";
|
|
236
|
+
}
|
|
237
|
+
if (type === "home" || type === "work" || type === "other") {
|
|
238
|
+
return type.toUpperCase();
|
|
239
|
+
}
|
|
240
|
+
return void 0;
|
|
241
|
+
};
|
|
242
|
+
var spectrumSimpleTypeToWa = (type) => type ? type.toUpperCase() : void 0;
|
|
243
|
+
var spectrumNameToWa = (name) => ({
|
|
244
|
+
formattedName: name?.formatted ?? ([name?.first, name?.middle, name?.last].filter((p) => Boolean(p)).join(" ") || "Unknown"),
|
|
245
|
+
firstName: name?.first,
|
|
246
|
+
lastName: name?.last,
|
|
247
|
+
middleName: name?.middle,
|
|
248
|
+
prefix: name?.prefix,
|
|
249
|
+
suffix: name?.suffix
|
|
250
|
+
});
|
|
251
|
+
var isWhatsAppContactCard = (value) => {
|
|
252
|
+
if (!value || typeof value !== "object") {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
const raw = value;
|
|
256
|
+
const name = raw.name;
|
|
257
|
+
if (!name || typeof name !== "object" || typeof name.formattedName !== "string") {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
return Array.isArray(raw.phones) && Array.isArray(raw.emails) && Array.isArray(raw.addresses) && Array.isArray(raw.urls);
|
|
261
|
+
};
|
|
262
|
+
var contactToWa = (contact) => {
|
|
263
|
+
if (isWhatsAppContactCard(contact.raw)) {
|
|
264
|
+
return contact.raw;
|
|
265
|
+
}
|
|
266
|
+
const card = {
|
|
267
|
+
name: spectrumNameToWa(contact.name),
|
|
268
|
+
phones: (contact.phones ?? []).map((p) => ({
|
|
269
|
+
phone: p.value,
|
|
270
|
+
type: spectrumPhoneTypeToWa(p.type)
|
|
271
|
+
})),
|
|
272
|
+
emails: (contact.emails ?? []).map((e) => ({
|
|
273
|
+
email: e.value,
|
|
274
|
+
type: spectrumSimpleTypeToWa(e.type)
|
|
275
|
+
})),
|
|
276
|
+
addresses: (contact.addresses ?? []).map((a) => ({
|
|
277
|
+
street: a.street,
|
|
278
|
+
city: a.city,
|
|
279
|
+
state: a.region,
|
|
280
|
+
zip: a.postalCode,
|
|
281
|
+
country: a.country,
|
|
282
|
+
type: spectrumSimpleTypeToWa(a.type)
|
|
283
|
+
})),
|
|
284
|
+
urls: (contact.urls ?? []).map((url) => ({ url })),
|
|
285
|
+
org: contact.org?.name || contact.org?.department || contact.org?.title ? {
|
|
286
|
+
company: contact.org.name,
|
|
287
|
+
department: contact.org.department,
|
|
288
|
+
title: contact.org.title
|
|
289
|
+
} : void 0,
|
|
290
|
+
birthday: contact.birthday
|
|
291
|
+
};
|
|
292
|
+
return card;
|
|
293
|
+
};
|
|
88
294
|
var messages = (client) => {
|
|
89
295
|
const eventStream = client.events.subscribe().filter(
|
|
90
296
|
(e) => e.type === "message"
|
|
@@ -93,7 +299,9 @@ var messages = (client) => {
|
|
|
93
299
|
(async () => {
|
|
94
300
|
try {
|
|
95
301
|
for await (const event of eventStream) {
|
|
96
|
-
|
|
302
|
+
for (const m of toMessages(client, event.message)) {
|
|
303
|
+
emit(m);
|
|
304
|
+
}
|
|
97
305
|
}
|
|
98
306
|
end();
|
|
99
307
|
} catch (e) {
|
|
@@ -106,8 +314,9 @@ var messages = (client) => {
|
|
|
106
314
|
var send = async (client, spaceId, content) => {
|
|
107
315
|
switch (content.type) {
|
|
108
316
|
case "text":
|
|
109
|
-
|
|
110
|
-
|
|
317
|
+
return toSendResult(
|
|
318
|
+
await client.messages.send({ to: spaceId, text: content.text })
|
|
319
|
+
);
|
|
111
320
|
case "attachment": {
|
|
112
321
|
const { mediaId } = await client.media.upload({
|
|
113
322
|
file: await content.read(),
|
|
@@ -116,14 +325,35 @@ var send = async (client, spaceId, content) => {
|
|
|
116
325
|
});
|
|
117
326
|
const mediaType = mimeToMediaType(content.mimeType);
|
|
118
327
|
const mediaPayload = mediaType === "document" ? { id: mediaId, filename: content.name } : { id: mediaId };
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
328
|
+
return toSendResult(
|
|
329
|
+
await client.messages.send({
|
|
330
|
+
to: spaceId,
|
|
331
|
+
[mediaType]: mediaPayload
|
|
332
|
+
})
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
case "contact":
|
|
336
|
+
return toSendResult(
|
|
337
|
+
await client.messages.send({
|
|
338
|
+
to: spaceId,
|
|
339
|
+
contacts: [contactToWa(content)]
|
|
340
|
+
})
|
|
341
|
+
);
|
|
342
|
+
case "voice": {
|
|
343
|
+
const { mediaId } = await client.media.upload({
|
|
344
|
+
file: await content.read(),
|
|
345
|
+
mimeType: content.mimeType,
|
|
346
|
+
filename: voiceFilename(content)
|
|
122
347
|
});
|
|
123
|
-
|
|
348
|
+
return toSendResult(
|
|
349
|
+
await client.messages.send({
|
|
350
|
+
to: spaceId,
|
|
351
|
+
audio: { id: mediaId }
|
|
352
|
+
})
|
|
353
|
+
);
|
|
124
354
|
}
|
|
125
355
|
default:
|
|
126
|
-
|
|
356
|
+
throw new Error(`Unsupported WhatsApp content type: ${content.type}`);
|
|
127
357
|
}
|
|
128
358
|
};
|
|
129
359
|
var reactToMessage = async (client, spaceId, messageId, reaction) => {
|
|
@@ -135,12 +365,13 @@ var reactToMessage = async (client, spaceId, messageId, reaction) => {
|
|
|
135
365
|
var replyToMessage = async (client, spaceId, messageId, content) => {
|
|
136
366
|
switch (content.type) {
|
|
137
367
|
case "text":
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
368
|
+
return toSendResult(
|
|
369
|
+
await client.messages.send({
|
|
370
|
+
to: spaceId,
|
|
371
|
+
replyTo: messageId,
|
|
372
|
+
text: content.text
|
|
373
|
+
})
|
|
374
|
+
);
|
|
144
375
|
case "attachment": {
|
|
145
376
|
const { mediaId } = await client.media.upload({
|
|
146
377
|
file: await content.read(),
|
|
@@ -149,15 +380,38 @@ var replyToMessage = async (client, spaceId, messageId, content) => {
|
|
|
149
380
|
});
|
|
150
381
|
const mediaType = mimeToMediaType(content.mimeType);
|
|
151
382
|
const mediaPayload = mediaType === "document" ? { id: mediaId, filename: content.name } : { id: mediaId };
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
383
|
+
return toSendResult(
|
|
384
|
+
await client.messages.send({
|
|
385
|
+
to: spaceId,
|
|
386
|
+
replyTo: messageId,
|
|
387
|
+
[mediaType]: mediaPayload
|
|
388
|
+
})
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
case "contact":
|
|
392
|
+
return toSendResult(
|
|
393
|
+
await client.messages.send({
|
|
394
|
+
to: spaceId,
|
|
395
|
+
replyTo: messageId,
|
|
396
|
+
contacts: [contactToWa(content)]
|
|
397
|
+
})
|
|
398
|
+
);
|
|
399
|
+
case "voice": {
|
|
400
|
+
const { mediaId } = await client.media.upload({
|
|
401
|
+
file: await content.read(),
|
|
402
|
+
mimeType: content.mimeType,
|
|
403
|
+
filename: voiceFilename(content)
|
|
156
404
|
});
|
|
157
|
-
|
|
405
|
+
return toSendResult(
|
|
406
|
+
await client.messages.send({
|
|
407
|
+
to: spaceId,
|
|
408
|
+
replyTo: messageId,
|
|
409
|
+
audio: { id: mediaId }
|
|
410
|
+
})
|
|
411
|
+
);
|
|
158
412
|
}
|
|
159
413
|
default:
|
|
160
|
-
|
|
414
|
+
throw new Error(`Unsupported WhatsApp content type: ${content.type}`);
|
|
161
415
|
}
|
|
162
416
|
};
|
|
163
417
|
|
|
@@ -214,7 +468,7 @@ var whatsappBusiness = definePlatform("WhatsApp Business", {
|
|
|
214
468
|
},
|
|
215
469
|
actions: {
|
|
216
470
|
send: async ({ space, content, client }) => {
|
|
217
|
-
await send(client, space.id, content);
|
|
471
|
+
return await send(client, space.id, content);
|
|
218
472
|
},
|
|
219
473
|
reactToMessage: async ({ space, messageId, reaction, client }) => {
|
|
220
474
|
await reactToMessage(
|
|
@@ -225,7 +479,7 @@ var whatsappBusiness = definePlatform("WhatsApp Business", {
|
|
|
225
479
|
);
|
|
226
480
|
},
|
|
227
481
|
replyToMessage: async ({ space, messageId, content, client }) => {
|
|
228
|
-
await replyToMessage(
|
|
482
|
+
return await replyToMessage(
|
|
229
483
|
client,
|
|
230
484
|
space.id,
|
|
231
485
|
messageId,
|
|
@@ -14,6 +14,70 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
|
|
|
14
14
|
size: z__default.ZodOptional<z__default.ZodNumber>;
|
|
15
15
|
read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
|
|
16
16
|
stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
|
|
17
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
18
|
+
type: z__default.ZodLiteral<"contact">;
|
|
19
|
+
user: z__default.ZodOptional<z__default.ZodObject<{
|
|
20
|
+
__platform: z__default.ZodString;
|
|
21
|
+
id: z__default.ZodString;
|
|
22
|
+
}, z__default.core.$strip>>;
|
|
23
|
+
name: z__default.ZodOptional<z__default.ZodObject<{
|
|
24
|
+
formatted: z__default.ZodOptional<z__default.ZodString>;
|
|
25
|
+
first: z__default.ZodOptional<z__default.ZodString>;
|
|
26
|
+
last: z__default.ZodOptional<z__default.ZodString>;
|
|
27
|
+
middle: z__default.ZodOptional<z__default.ZodString>;
|
|
28
|
+
prefix: z__default.ZodOptional<z__default.ZodString>;
|
|
29
|
+
suffix: z__default.ZodOptional<z__default.ZodString>;
|
|
30
|
+
}, z__default.core.$strip>>;
|
|
31
|
+
phones: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
|
|
32
|
+
value: z__default.ZodString;
|
|
33
|
+
type: z__default.ZodOptional<z__default.ZodEnum<{
|
|
34
|
+
mobile: "mobile";
|
|
35
|
+
home: "home";
|
|
36
|
+
work: "work";
|
|
37
|
+
other: "other";
|
|
38
|
+
}>>;
|
|
39
|
+
}, z__default.core.$strip>>>;
|
|
40
|
+
emails: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
|
|
41
|
+
value: z__default.ZodString;
|
|
42
|
+
type: z__default.ZodOptional<z__default.ZodEnum<{
|
|
43
|
+
home: "home";
|
|
44
|
+
work: "work";
|
|
45
|
+
other: "other";
|
|
46
|
+
}>>;
|
|
47
|
+
}, z__default.core.$strip>>>;
|
|
48
|
+
addresses: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
|
|
49
|
+
street: z__default.ZodOptional<z__default.ZodString>;
|
|
50
|
+
city: z__default.ZodOptional<z__default.ZodString>;
|
|
51
|
+
region: z__default.ZodOptional<z__default.ZodString>;
|
|
52
|
+
postalCode: z__default.ZodOptional<z__default.ZodString>;
|
|
53
|
+
country: z__default.ZodOptional<z__default.ZodString>;
|
|
54
|
+
type: z__default.ZodOptional<z__default.ZodEnum<{
|
|
55
|
+
home: "home";
|
|
56
|
+
work: "work";
|
|
57
|
+
other: "other";
|
|
58
|
+
}>>;
|
|
59
|
+
}, z__default.core.$strip>>>;
|
|
60
|
+
org: z__default.ZodOptional<z__default.ZodObject<{
|
|
61
|
+
name: z__default.ZodOptional<z__default.ZodString>;
|
|
62
|
+
title: z__default.ZodOptional<z__default.ZodString>;
|
|
63
|
+
department: z__default.ZodOptional<z__default.ZodString>;
|
|
64
|
+
}, z__default.core.$strip>>;
|
|
65
|
+
urls: z__default.ZodOptional<z__default.ZodArray<z__default.ZodString>>;
|
|
66
|
+
birthday: z__default.ZodOptional<z__default.ZodString>;
|
|
67
|
+
note: z__default.ZodOptional<z__default.ZodString>;
|
|
68
|
+
photo: z__default.ZodOptional<z__default.ZodObject<{
|
|
69
|
+
mimeType: z__default.ZodString;
|
|
70
|
+
read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
|
|
71
|
+
}, z__default.core.$strip>>;
|
|
72
|
+
raw: z__default.ZodOptional<z__default.ZodUnknown>;
|
|
73
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
74
|
+
type: z__default.ZodLiteral<"voice">;
|
|
75
|
+
name: z__default.ZodOptional<z__default.ZodString>;
|
|
76
|
+
mimeType: z__default.ZodString;
|
|
77
|
+
duration: z__default.ZodOptional<z__default.ZodNumber>;
|
|
78
|
+
size: z__default.ZodOptional<z__default.ZodNumber>;
|
|
79
|
+
read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
|
|
80
|
+
stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
|
|
17
81
|
}, z__default.core.$strip>], "type">;
|
|
18
82
|
type Content = z__default.infer<typeof contentSchema>;
|
|
19
83
|
interface ContentBuilder {
|
|
@@ -21,30 +85,42 @@ interface ContentBuilder {
|
|
|
21
85
|
}
|
|
22
86
|
type ContentInput = string | ContentBuilder;
|
|
23
87
|
|
|
24
|
-
interface
|
|
88
|
+
interface User {
|
|
25
89
|
readonly __platform: string;
|
|
26
90
|
readonly id: string;
|
|
27
|
-
responding<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
28
|
-
send(...content: [ContentInput, ...ContentInput[]]): Promise<void>;
|
|
29
|
-
startTyping(): Promise<void>;
|
|
30
|
-
stopTyping(): Promise<void>;
|
|
31
91
|
}
|
|
32
92
|
|
|
33
|
-
interface
|
|
93
|
+
interface Space<_Def = unknown> {
|
|
34
94
|
readonly __platform: string;
|
|
95
|
+
edit(message: OutboundMessage, newContent: ContentInput): Promise<void>;
|
|
35
96
|
readonly id: string;
|
|
97
|
+
responding<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
98
|
+
send(content: ContentInput): Promise<OutboundMessage>;
|
|
99
|
+
send(...content: [ContentInput, ContentInput, ...ContentInput[]]): Promise<OutboundMessage[]>;
|
|
100
|
+
startTyping(): Promise<void>;
|
|
101
|
+
stopTyping(): Promise<void>;
|
|
36
102
|
}
|
|
37
103
|
|
|
38
|
-
interface
|
|
104
|
+
interface BaseMessage<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> {
|
|
39
105
|
content: Content;
|
|
40
106
|
readonly id: string;
|
|
41
107
|
platform: TPlatform;
|
|
42
108
|
react(reaction: string): Promise<void>;
|
|
43
|
-
reply(
|
|
44
|
-
|
|
109
|
+
reply(content: ContentInput): Promise<OutboundMessage<TPlatform, TSender, TSpace>>;
|
|
110
|
+
reply(...content: [ContentInput, ContentInput, ...ContentInput[]]): Promise<OutboundMessage<TPlatform, TSender, TSpace>[]>;
|
|
45
111
|
space: TSpace;
|
|
46
112
|
timestamp: Date;
|
|
47
113
|
}
|
|
114
|
+
interface InboundMessage<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> extends BaseMessage<TPlatform, TSender, TSpace> {
|
|
115
|
+
direction: "inbound";
|
|
116
|
+
sender: TSender;
|
|
117
|
+
}
|
|
118
|
+
interface OutboundMessage<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> extends BaseMessage<TPlatform, TSender, TSpace> {
|
|
119
|
+
direction: "outbound";
|
|
120
|
+
edit(newContent: ContentInput): Promise<void>;
|
|
121
|
+
sender: TSender | undefined;
|
|
122
|
+
}
|
|
123
|
+
type Message<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> = InboundMessage<TPlatform, TSender, TSpace> | OutboundMessage<TPlatform, TSender, TSpace>;
|
|
48
124
|
|
|
49
125
|
type ResolvedSpace = Pick<Space, "id">;
|
|
50
126
|
type SpaceRef = Pick<Space, "id" | "__platform">;
|
|
@@ -67,6 +143,11 @@ type ProviderMessage<TSender extends ResolvedUser = ResolvedUser, TSpace extends
|
|
|
67
143
|
space: TSpace;
|
|
68
144
|
timestamp?: Date;
|
|
69
145
|
} & TExtra;
|
|
146
|
+
interface SendResult<TSender extends ResolvedUser = ResolvedUser> {
|
|
147
|
+
id: string;
|
|
148
|
+
sender?: TSender;
|
|
149
|
+
timestamp?: Date;
|
|
150
|
+
}
|
|
70
151
|
type MergeSchema<TSchema extends z__default.ZodType | undefined, TBase extends object> = TSchema extends z__default.ZodType ? string extends keyof z__default.infer<TSchema> ? TBase : Omit<z__default.infer<TSchema>, keyof TBase> & TBase : TBase;
|
|
71
152
|
type SchemaMessage<TUserSchema extends z__default.ZodType | undefined = undefined, TSpaceSchema extends z__default.ZodType | undefined = undefined> = ProviderMessage<MergeSchema<TUserSchema, ResolvedUser>, MergeSchema<TSpaceSchema, ResolvedSpace>>;
|
|
72
153
|
type InferEventPayload<T> = T extends (ctx: never) => AsyncIterable<infer P> ? P : never;
|
|
@@ -82,7 +163,7 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
|
|
|
82
163
|
content: Content;
|
|
83
164
|
client: _Client;
|
|
84
165
|
config: z__default.infer<_ConfigSchema>;
|
|
85
|
-
}) => Promise<
|
|
166
|
+
}) => Promise<SendResult<_ResolvedUser>>;
|
|
86
167
|
startTyping?: (_: {
|
|
87
168
|
space: _ResolvedSpace & SpaceRef;
|
|
88
169
|
client: _Client;
|
|
@@ -106,6 +187,13 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
|
|
|
106
187
|
content: Content;
|
|
107
188
|
client: _Client;
|
|
108
189
|
config: z__default.infer<_ConfigSchema>;
|
|
190
|
+
}) => Promise<SendResult<_ResolvedUser>>;
|
|
191
|
+
editMessage?: (_: {
|
|
192
|
+
space: _ResolvedSpace & SpaceRef;
|
|
193
|
+
messageId: string;
|
|
194
|
+
content: Content;
|
|
195
|
+
client: _Client;
|
|
196
|
+
config: z__default.infer<_ConfigSchema>;
|
|
109
197
|
}) => Promise<void>;
|
|
110
198
|
};
|
|
111
199
|
config: _ConfigSchema;
|
|
@@ -151,11 +239,12 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
|
|
|
151
239
|
}
|
|
152
240
|
interface AnyPlatformDef {
|
|
153
241
|
actions: {
|
|
154
|
-
send: (_: any) => Promise<
|
|
242
|
+
send: (_: any) => Promise<SendResult>;
|
|
155
243
|
startTyping?: (_: any) => Promise<void>;
|
|
156
244
|
stopTyping?: (_: any) => Promise<void>;
|
|
157
245
|
reactToMessage?: (_: any) => Promise<void>;
|
|
158
|
-
replyToMessage?: (_: any) => Promise<
|
|
246
|
+
replyToMessage?: (_: any) => Promise<SendResult>;
|
|
247
|
+
editMessage?: (_: any) => Promise<void>;
|
|
159
248
|
};
|
|
160
249
|
config: z__default.ZodType<object>;
|
|
161
250
|
events: {
|
|
@@ -254,4 +343,4 @@ interface Platform<Def extends AnyPlatformDef> {
|
|
|
254
343
|
(message: Message): PlatformMessage<Def>;
|
|
255
344
|
}
|
|
256
345
|
|
|
257
|
-
export type { AnyPlatformDef as A, ContentBuilder as C, EventProducer as E, Message as M, ProviderMessage as P, SpectrumLike as S, User as U, ContentInput as a, Content as b, PlatformDef as c, Platform as d, PlatformProviderConfig as e, CustomEventStreams as f, Space as g, PlatformInstance as h, PlatformMessage as i, PlatformSpace as j, PlatformUser as k, SchemaMessage as l };
|
|
346
|
+
export type { AnyPlatformDef as A, ContentBuilder as C, EventProducer as E, InboundMessage as I, Message as M, OutboundMessage as O, ProviderMessage as P, SpectrumLike as S, User as U, ContentInput as a, Content as b, PlatformDef as c, Platform as d, PlatformProviderConfig as e, CustomEventStreams as f, Space as g, PlatformInstance as h, PlatformMessage as i, PlatformSpace as j, PlatformUser as k, SchemaMessage as l };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spectrum-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -20,16 +20,23 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@photon-ai/advanced-imessage": "^0.4.3",
|
|
23
|
-
"@photon-ai/whatsapp-business": "^0.1.1",
|
|
24
23
|
"@photon-ai/imessage-kit": "^3.0.0-rc.2",
|
|
24
|
+
"@photon-ai/whatsapp-business": "^0.1.1",
|
|
25
25
|
"@repeaterjs/repeater": "^3.0.6",
|
|
26
26
|
"better-grpc": "^0.3.2",
|
|
27
27
|
"mime-types": "^3.0.1",
|
|
28
28
|
"type-fest": "^5.4.1",
|
|
29
|
+
"vcf": "^2.1.2",
|
|
29
30
|
"zod": "^4.2.1"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
33
|
+
"ffmpeg-static": "^5",
|
|
32
34
|
"typescript": "^5"
|
|
33
35
|
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"ffmpeg-static": {
|
|
38
|
+
"optional": true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
34
41
|
"license": "MIT"
|
|
35
42
|
}
|