@spectrum-ts/whatsapp-business 9.3.1 → 11.0.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/index.js +18 -5
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TypedEventStream, button, buttons, createClient, list } from "@photon-ai/whatsapp-business";
|
|
2
2
|
import { UnsupportedError, cloud, definePlatform, mergeStreams, stream } from "@spectrum-ts/core";
|
|
3
|
-
import { asAttachment, asContact, asCustom, asPollOption, asReaction, asText, createLogger, errorAttrs, tracedFetch } from "@spectrum-ts/core/authoring";
|
|
3
|
+
import { asAttachment, asContact, asCustom, asGroup, asPollOption, asReaction, asText, createLogger, errorAttrs, tracedFetch } from "@spectrum-ts/core/authoring";
|
|
4
4
|
import { extension } from "mime-types";
|
|
5
5
|
import z from "zod";
|
|
6
6
|
//#region src/auth.ts
|
|
@@ -367,6 +367,14 @@ const waContactToSpectrum = (card) => {
|
|
|
367
367
|
if (card.birthday) input.birthday = card.birthday;
|
|
368
368
|
return asContact(input);
|
|
369
369
|
};
|
|
370
|
+
const groupItem = (msg, index, content) => ({
|
|
371
|
+
id: `${msg.id}:${index}`,
|
|
372
|
+
content,
|
|
373
|
+
sender: { id: msg.from },
|
|
374
|
+
space: { id: msg.from },
|
|
375
|
+
timestamp: msg.timestamp
|
|
376
|
+
});
|
|
377
|
+
const parentWamid = (id) => id.split(":")[0] ?? id;
|
|
370
378
|
const toMessages = (client, msg) => {
|
|
371
379
|
const base = {
|
|
372
380
|
sender: { id: msg.from },
|
|
@@ -394,7 +402,12 @@ const mapContent = (client, msg) => {
|
|
|
394
402
|
case "image":
|
|
395
403
|
case "video":
|
|
396
404
|
case "audio":
|
|
397
|
-
case "document":
|
|
405
|
+
case "document": {
|
|
406
|
+
const media = lazyMedia(client, content.media);
|
|
407
|
+
const caption = content.media.caption?.trim();
|
|
408
|
+
if (!caption) return media;
|
|
409
|
+
return asGroup({ items: [groupItem(msg, 0, media), groupItem(msg, 1, asText(caption))] });
|
|
410
|
+
}
|
|
398
411
|
case "sticker": return asCustom({
|
|
399
412
|
whatsapp_type: "sticker",
|
|
400
413
|
...content.sticker
|
|
@@ -561,11 +574,11 @@ const clientStream = (client) => {
|
|
|
561
574
|
};
|
|
562
575
|
const messages = (clients) => mergeStreams(clients.map(clientStream));
|
|
563
576
|
const send = async (clients, spaceId, content) => {
|
|
564
|
-
if (content.type === "reply") return await replyToMessage(clients, spaceId, content.target.id, content.content);
|
|
577
|
+
if (content.type === "reply") return await replyToMessage(clients, spaceId, parentWamid(content.target.id), content.content);
|
|
565
578
|
if (content.type === "reaction") return await reactToMessage(clients, spaceId, content);
|
|
566
579
|
if (content.type === "typing") return;
|
|
567
580
|
if (content.type === "read") {
|
|
568
|
-
await primary(clients).messages.markRead(content.target.id);
|
|
581
|
+
await primary(clients).messages.markRead(parentWamid(content.target.id));
|
|
569
582
|
return;
|
|
570
583
|
}
|
|
571
584
|
const client = primary(clients);
|
|
@@ -624,7 +637,7 @@ const reactToMessage = async (clients, spaceId, content) => {
|
|
|
624
637
|
return toRecord(await primary(clients).messages.send({
|
|
625
638
|
to: spaceId,
|
|
626
639
|
reaction: {
|
|
627
|
-
messageId: content.target.id,
|
|
640
|
+
messageId: parentWamid(content.target.id),
|
|
628
641
|
emoji: content.emoji
|
|
629
642
|
}
|
|
630
643
|
}), spaceId, content);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-ts/whatsapp-business",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "WhatsApp Business provider for spectrum-ts.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"zod": "^4.2.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@spectrum-ts/core": "^
|
|
39
|
+
"@spectrum-ts/core": "^11.0.0",
|
|
40
40
|
"typescript": "^5 || ^6.0.0"
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT"
|