@rosyn/whats 0.1.6 → 0.1.7
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/README.md +7 -1
- package/dist/compat/index.d.ts.map +1 -1
- package/dist/compat/index.js +255 -47
- package/dist/compat/index.js.map +1 -1
- package/dist/media/index.d.ts +4 -1
- package/dist/media/index.d.ts.map +1 -1
- package/dist/media/index.js +57 -1
- package/dist/media/index.js.map +1 -1
- package/dist/proto/index.d.ts +23 -0
- package/dist/proto/index.d.ts.map +1 -1
- package/dist/proto/index.js +79 -0
- package/dist/proto/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Independent Multi-Device WhatsApp Messaging Library powered by **Rust**, **Rosyn
|
|
|
14
14
|
- **Authentication & Compact Storage**: QR code & 8-char pairing code (`requestPairingCode`), ADV device-sign verification, `rosyn_auth.rdb` compressed SQL auth store with automatic Signal session/message-key pruning.
|
|
15
15
|
- **Signal E2EE & LID/PN Resolution**: Full X3DH + Double Ratchet (DM & `deviceSentMessage`), Group `SenderKey` (`skmsg` + `SenderKeyDistributionMessage`), automatic `<receipt type="retry">` handling, and transparent `@lid` -> `@s.whatsapp.net` resolution.
|
|
16
16
|
- **Messaging & Rich Media**:
|
|
17
|
-
- Text, ExtendedText (replies/`quoted`, mentions, `isGroupStatus`), React (`react`), Edit (`edit`), Delete/Revoke (`delete`), Poll (`poll`), Location (`location`), Contacts/vCard (`contacts`).
|
|
17
|
+
- Text, ExtendedText (replies/`quoted`, mentions, `isGroupStatus`, `sendAfterRead`), React (`react`), Edit (`edit`), Delete/Revoke (`delete`), Poll (`poll`), Location (`location`), Contacts/vCard (`contacts`).
|
|
18
18
|
- Image, Video, Video Note (`ptv`), Audio/PTT (auto duration & 128-sample waveform via `ffmpeg`), Document, Sticker, and Sticker Pack (`stickerPack` with STORED ZIP + thumbnail upload).
|
|
19
19
|
- Interactive Native Flow, Carousel cards, Legacy Buttons, and `sendButtons` shorthand (`single_select`, `cta_url`, `cta_copy`, `quick_reply`).
|
|
20
20
|
- Media download (`downloadMediaMessage`), reupload retry (`updateMediaMessage`), and `readMessages` / per-chat `sendPresenceUpdate` (`composing` / `recording` / `paused`).
|
|
@@ -201,6 +201,12 @@ await sock.sendMessage(groupJid, {
|
|
|
201
201
|
text: "Group status update",
|
|
202
202
|
contextInfo: { isGroupStatus: true, participant: sock.user.id },
|
|
203
203
|
});
|
|
204
|
+
|
|
205
|
+
// After-Read Disappearing Message (default 5s, custom duration supported)
|
|
206
|
+
await sock.sendAfterRead(jid, "Disappears 15s after being read", {
|
|
207
|
+
quoted: m,
|
|
208
|
+
duration: 15,
|
|
209
|
+
});
|
|
204
210
|
```
|
|
205
211
|
|
|
206
212
|
### Interactive Buttons (`sendButtons` & `interactiveButtons`)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compat/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compat/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAW,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,MAAM,uBAAuB,CAAC;AA6BvC,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;AAEzB,eAAO,MAAM,QAAQ;sBACD,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;qBAClC,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;uBAC/B,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;mCACrB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;2BAChC,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;CACzD,CAAC;AAIF,wBAAsB,yBAAyB,IAAI,OAAO,CAAC;IAAE,OAAO,EAAE,CAAC,MA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I,CAAG"}
|
package/dist/compat/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { createCipheriv, createDecipheriv, createHash, createHmac, pbkdf2, randomBytes } from "node:crypto";
|
|
3
3
|
import { EventEmitter } from "node:events";
|
|
4
4
|
import * as fs from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
5
6
|
import * as path from "node:path";
|
|
6
7
|
import { promisify } from "node:util";
|
|
7
8
|
import { deflateRawSync, inflateRawSync } from "node:zlib";
|
|
@@ -241,6 +242,18 @@ export function makeWASocket(config = {}) {
|
|
|
241
242
|
const spkPriv = Buffer.from(spkKp.privateKeyHex, "hex");
|
|
242
243
|
const signalMgr = new SignalProtocolManager(native, getKey, setKey, { priv: identPriv, pub33: toSignalPub33(identPub) }, { keyId: 1, priv: spkPriv, pub33: toSignalPub33(spkPub) }, Number(authCreds.registrationId ?? 1));
|
|
243
244
|
const groupCache = new Map();
|
|
245
|
+
const seenMessageIds = new Set();
|
|
246
|
+
const markMessageSeen = (key) => {
|
|
247
|
+
if (seenMessageIds.has(key))
|
|
248
|
+
return false;
|
|
249
|
+
seenMessageIds.add(key);
|
|
250
|
+
if (seenMessageIds.size > 2000) {
|
|
251
|
+
const oldest = seenMessageIds.values().next().value;
|
|
252
|
+
if (oldest !== undefined)
|
|
253
|
+
seenMessageIds.delete(oldest);
|
|
254
|
+
}
|
|
255
|
+
return true;
|
|
256
|
+
};
|
|
244
257
|
const senderKeyMemory = new Map();
|
|
245
258
|
const sentMessages = new Map();
|
|
246
259
|
const ver = config.version ?? [2, 3000, 1056491763];
|
|
@@ -1336,6 +1349,9 @@ export function makeWASocket(config = {}) {
|
|
|
1336
1349
|
k !== "fastRatchetKeySenderKeyDistributionMessage" &&
|
|
1337
1350
|
k !== "messageContextInfo");
|
|
1338
1351
|
if (hasDisplayContent) {
|
|
1352
|
+
if (!markMessageSeen(`${chatId}:${msgId}`)) {
|
|
1353
|
+
break;
|
|
1354
|
+
}
|
|
1339
1355
|
if (isGroup &&
|
|
1340
1356
|
((participant?.endsWith("@lid") &&
|
|
1341
1357
|
!node.attrs.participant_pn &&
|
|
@@ -1416,6 +1432,7 @@ export function makeWASocket(config = {}) {
|
|
|
1416
1432
|
},
|
|
1417
1433
|
],
|
|
1418
1434
|
});
|
|
1435
|
+
break;
|
|
1419
1436
|
}
|
|
1420
1437
|
}
|
|
1421
1438
|
})().catch(() => { });
|
|
@@ -1484,6 +1501,7 @@ export function makeWASocket(config = {}) {
|
|
|
1484
1501
|
mediaKey: enc.mediaKey,
|
|
1485
1502
|
fileSha256: enc.fileSha256,
|
|
1486
1503
|
fileEncSha256: enc.fileEncSha256,
|
|
1504
|
+
...(enc.streamingSidecar ? { streamingSidecar: enc.streamingSidecar } : {}),
|
|
1487
1505
|
fileLength: plaintext.byteLength,
|
|
1488
1506
|
url: json.url ?? "",
|
|
1489
1507
|
directPath: json.direct_path ?? "",
|
|
@@ -1570,7 +1588,9 @@ export function makeWASocket(config = {}) {
|
|
|
1570
1588
|
...(c.edit.participant ? { participant: String(c.edit.participant) } : {}),
|
|
1571
1589
|
},
|
|
1572
1590
|
type: 14,
|
|
1573
|
-
editedMessage:
|
|
1591
|
+
editedMessage: c.contextInfo
|
|
1592
|
+
? { extendedTextMessage: { text: String(c.text ?? ""), contextInfo: c.contextInfo } }
|
|
1593
|
+
: { conversation: String(c.text ?? "") },
|
|
1574
1594
|
},
|
|
1575
1595
|
};
|
|
1576
1596
|
}
|
|
@@ -1824,14 +1844,108 @@ export function makeWASocket(config = {}) {
|
|
|
1824
1844
|
};
|
|
1825
1845
|
}
|
|
1826
1846
|
if (c?.video) {
|
|
1827
|
-
|
|
1828
|
-
|
|
1847
|
+
let buf = await resolveMediaBuffer(c.video);
|
|
1848
|
+
let autoSeconds = typeof c.seconds === "number" ? c.seconds : undefined;
|
|
1849
|
+
let autoWidth = typeof c.width === "number" ? c.width : undefined;
|
|
1850
|
+
let autoHeight = typeof c.height === "number" ? c.height : undefined;
|
|
1851
|
+
let autoThumb = c.jpegThumbnail instanceof Uint8Array ? c.jpegThumbnail : undefined;
|
|
1852
|
+
const tmpVid = path.join(tmpdir(), `rosyn_vid_${Date.now()}_${Math.random().toString(36).slice(2)}.mp4`);
|
|
1853
|
+
const tmpOut = `${tmpVid}.h264.mp4`;
|
|
1854
|
+
const tmpThumb = `${tmpVid}.jpg`;
|
|
1855
|
+
try {
|
|
1856
|
+
fs.writeFileSync(tmpVid, buf);
|
|
1857
|
+
const probeOut = await new Promise((resolve) => {
|
|
1858
|
+
const p = spawn("ffprobe", [
|
|
1859
|
+
"-v", "error",
|
|
1860
|
+
"-select_streams", "v:0",
|
|
1861
|
+
"-show_entries", "stream=codec_name,width,height,duration:format=duration",
|
|
1862
|
+
"-of", "json",
|
|
1863
|
+
tmpVid,
|
|
1864
|
+
]);
|
|
1865
|
+
let out = "";
|
|
1866
|
+
p.stdout?.on("data", (d) => (out += d.toString()));
|
|
1867
|
+
p.on("close", () => resolve(out));
|
|
1868
|
+
p.on("error", () => resolve(""));
|
|
1869
|
+
});
|
|
1870
|
+
let videoCodec;
|
|
1871
|
+
if (probeOut) {
|
|
1872
|
+
try {
|
|
1873
|
+
const pj = JSON.parse(probeOut);
|
|
1874
|
+
const st = Array.isArray(pj?.streams) ? pj.streams[0] : undefined;
|
|
1875
|
+
videoCodec = st?.codec_name;
|
|
1876
|
+
if (autoWidth === undefined && st?.width)
|
|
1877
|
+
autoWidth = Number(st.width);
|
|
1878
|
+
if (autoHeight === undefined && st?.height)
|
|
1879
|
+
autoHeight = Number(st.height);
|
|
1880
|
+
const dur = st?.duration ?? pj?.format?.duration;
|
|
1881
|
+
if (autoSeconds === undefined && dur)
|
|
1882
|
+
autoSeconds = Math.max(1, Math.round(Number(dur)));
|
|
1883
|
+
}
|
|
1884
|
+
catch { }
|
|
1885
|
+
}
|
|
1886
|
+
if (videoCodec && videoCodec !== "h264" && !c.gifPlayback) {
|
|
1887
|
+
await new Promise((resolve) => {
|
|
1888
|
+
const p = spawn("ffmpeg", [
|
|
1889
|
+
"-y", "-i", tmpVid,
|
|
1890
|
+
"-c:v", "libx264", "-preset", "ultrafast", "-crf", "23", "-pix_fmt", "yuv420p",
|
|
1891
|
+
"-c:a", "aac", "-b:a", "128k",
|
|
1892
|
+
"-movflags", "+faststart",
|
|
1893
|
+
tmpOut,
|
|
1894
|
+
]);
|
|
1895
|
+
p.on("close", () => resolve());
|
|
1896
|
+
p.on("error", () => resolve());
|
|
1897
|
+
});
|
|
1898
|
+
if (fs.existsSync(tmpOut)) {
|
|
1899
|
+
const transcoded = fs.readFileSync(tmpOut);
|
|
1900
|
+
if (transcoded.length > 0)
|
|
1901
|
+
buf = transcoded;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
if (!autoThumb) {
|
|
1905
|
+
await new Promise((resolve) => {
|
|
1906
|
+
const p = spawn("ffmpeg", [
|
|
1907
|
+
"-y", "-ss", "00:00:00", "-i", fs.existsSync(tmpOut) ? tmpOut : tmpVid,
|
|
1908
|
+
"-vf", "scale=32:-1", "-vframes", "1", "-f", "image2", tmpThumb,
|
|
1909
|
+
]);
|
|
1910
|
+
p.on("close", () => resolve());
|
|
1911
|
+
p.on("error", () => resolve());
|
|
1912
|
+
});
|
|
1913
|
+
if (fs.existsSync(tmpThumb)) {
|
|
1914
|
+
autoThumb = fs.readFileSync(tmpThumb);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
catch {
|
|
1919
|
+
}
|
|
1920
|
+
finally {
|
|
1921
|
+
try {
|
|
1922
|
+
if (fs.existsSync(tmpVid))
|
|
1923
|
+
fs.unlinkSync(tmpVid);
|
|
1924
|
+
}
|
|
1925
|
+
catch { }
|
|
1926
|
+
try {
|
|
1927
|
+
if (fs.existsSync(tmpOut))
|
|
1928
|
+
fs.unlinkSync(tmpOut);
|
|
1929
|
+
}
|
|
1930
|
+
catch { }
|
|
1931
|
+
try {
|
|
1932
|
+
if (fs.existsSync(tmpThumb))
|
|
1933
|
+
fs.unlinkSync(tmpThumb);
|
|
1934
|
+
}
|
|
1935
|
+
catch { }
|
|
1936
|
+
}
|
|
1937
|
+
const up = await uploadWaMedia(buf, c.ptv ? "ptv" : "video", "/mms/video");
|
|
1829
1938
|
const videoObj = {
|
|
1830
1939
|
url: up.url,
|
|
1831
1940
|
directPath: up.directPath,
|
|
1832
1941
|
mimetype: String(c.mimetype ?? "video/mp4"),
|
|
1833
|
-
|
|
1834
|
-
|
|
1942
|
+
...(c.caption ? { caption: String(c.caption) } : {}),
|
|
1943
|
+
...(c.gifPlayback ? { gifPlayback: true } : {}),
|
|
1944
|
+
...(typeof autoSeconds === "number" ? { seconds: autoSeconds } : {}),
|
|
1945
|
+
...(typeof autoWidth === "number" ? { width: autoWidth } : {}),
|
|
1946
|
+
...(typeof autoHeight === "number" ? { height: autoHeight } : {}),
|
|
1947
|
+
...(autoThumb ? { jpegThumbnail: autoThumb } : {}),
|
|
1948
|
+
...(up.streamingSidecar ? { streamingSidecar: up.streamingSidecar } : {}),
|
|
1835
1949
|
fileSha256: up.fileSha256,
|
|
1836
1950
|
fileEncSha256: up.fileEncSha256,
|
|
1837
1951
|
fileLength: up.fileLength,
|
|
@@ -2109,7 +2223,7 @@ export function makeWASocket(config = {}) {
|
|
|
2109
2223
|
}
|
|
2110
2224
|
const padded = writeRandomPadMax16(proto.Message.encode(waMsg));
|
|
2111
2225
|
const meJid = authCreds.me?.id ?? sock.user?.id ?? "0@s.whatsapp.net";
|
|
2112
|
-
const msgId = generateMessageIDV2(meJid);
|
|
2226
|
+
const msgId = options?.messageId ? String(options.messageId) : generateMessageIDV2(meJid);
|
|
2113
2227
|
sentMessages.set(msgId, { jid, message: waMsg });
|
|
2114
2228
|
setTimeout(() => sentMessages.delete(msgId), 5 * 60_000).unref();
|
|
2115
2229
|
const getDevices = async (userJids) => {
|
|
@@ -2208,35 +2322,14 @@ export function makeWASocket(config = {}) {
|
|
|
2208
2322
|
? String(content.edit.id ?? msgId)
|
|
2209
2323
|
: msgId;
|
|
2210
2324
|
const nlEditAttr = isNlDelete ? "8" : isNlEdit ? "3" : deleteEditAttr;
|
|
2211
|
-
const
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
tag: "plaintext",
|
|
2220
|
-
attrs: { mediatype: "sticker" },
|
|
2221
|
-
content: proto.Message.encode({ stickerMessage: plainSticker }),
|
|
2222
|
-
},
|
|
2223
|
-
],
|
|
2224
|
-
}));
|
|
2225
|
-
if (nlAudio && (nlAudio.url || nlAudio.directPath)) {
|
|
2226
|
-
transport.sendEncrypted(encodeWABinaryNode({
|
|
2227
|
-
tag: "message",
|
|
2228
|
-
attrs: { id: generateMessageIDV2(meJid), to: jid, type: "media" },
|
|
2229
|
-
content: [
|
|
2230
|
-
{
|
|
2231
|
-
tag: "plaintext",
|
|
2232
|
-
attrs: { mediatype: nlAudio.ptt ? "ptt" : "audio" },
|
|
2233
|
-
content: proto.Message.encode({ audioMessage: nlAudio }),
|
|
2234
|
-
},
|
|
2235
|
-
],
|
|
2236
|
-
}));
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
else {
|
|
2325
|
+
const nlMediaHandle = options?.mediaId ??
|
|
2326
|
+
waMsg.stickerMessage?.__mediaHandle ??
|
|
2327
|
+
waMsg.imageMessage?.__mediaHandle ??
|
|
2328
|
+
waMsg.videoMessage?.__mediaHandle ??
|
|
2329
|
+
waMsg.audioMessage?.__mediaHandle ??
|
|
2330
|
+
waMsg.documentMessage?.__mediaHandle ??
|
|
2331
|
+
waMsg.audioStickerMessage?.message?.stickerMessage?.__mediaHandle;
|
|
2332
|
+
{
|
|
2240
2333
|
const nlPlaintext = isNlDelete
|
|
2241
2334
|
? Buffer.alloc(0)
|
|
2242
2335
|
: isNlEdit && waMsg.protocolMessage?.editedMessage
|
|
@@ -2248,6 +2341,7 @@ export function makeWASocket(config = {}) {
|
|
|
2248
2341
|
id: nlMsgId,
|
|
2249
2342
|
to: jid,
|
|
2250
2343
|
type: stanzaType,
|
|
2344
|
+
...(nlMediaHandle ? { media_id: String(nlMediaHandle) } : {}),
|
|
2251
2345
|
...(nlEditAttr ? { edit: nlEditAttr } : {}),
|
|
2252
2346
|
},
|
|
2253
2347
|
content: [
|
|
@@ -2322,7 +2416,7 @@ export function makeWASocket(config = {}) {
|
|
|
2322
2416
|
id: msgId,
|
|
2323
2417
|
to: jid,
|
|
2324
2418
|
type: stanzaType,
|
|
2325
|
-
addressing_mode: addrMode,
|
|
2419
|
+
...(addrMode ? { addressing_mode: addrMode } : {}),
|
|
2326
2420
|
...(meta.ephemeralDuration && meta.ephemeralDuration > 0
|
|
2327
2421
|
? { expiration: String(meta.ephemeralDuration) }
|
|
2328
2422
|
: {}),
|
|
@@ -2394,6 +2488,15 @@ export function makeWASocket(config = {}) {
|
|
|
2394
2488
|
await client.sendMessage(jidNormalizedUser(jid), { text });
|
|
2395
2489
|
return { key: { remoteJid: jid, fromMe: true, id: msgId }, message: waMsg };
|
|
2396
2490
|
},
|
|
2491
|
+
signalRepository: {
|
|
2492
|
+
async encryptGroupMessage({ group, data, meId }) {
|
|
2493
|
+
const sender = meId || authCreds.me?.id || sock.user?.id || "0@s.whatsapp.net";
|
|
2494
|
+
const groupKey = `${group}:${jidToSignalAddress(sender)}`;
|
|
2495
|
+
const { distributionBytes } = await signalMgr.getOrCreateGroupDistribution(groupKey);
|
|
2496
|
+
const ciphertext = await signalMgr.encryptGroupMessage(groupKey, data);
|
|
2497
|
+
return { ciphertext, senderKeyDistributionMessage: distributionBytes };
|
|
2498
|
+
},
|
|
2499
|
+
},
|
|
2397
2500
|
async sendNode(node) {
|
|
2398
2501
|
transport.sendEncrypted(encodeWABinaryNode(node));
|
|
2399
2502
|
},
|
|
@@ -2401,6 +2504,62 @@ export function makeWASocket(config = {}) {
|
|
|
2401
2504
|
const res = await sock.sendMessage(jid, { rawMessage: message }, options);
|
|
2402
2505
|
return res.key.id;
|
|
2403
2506
|
},
|
|
2507
|
+
parseMention(text = "") {
|
|
2508
|
+
return [...String(text).matchAll(/@([0-9]{5,16}|0)/g)].map((v) => `${v[1]}@s.whatsapp.net`);
|
|
2509
|
+
},
|
|
2510
|
+
async fakeReply(jid, text = "", fakeJid, fakeText = "", fakeGroupJid, options = {}) {
|
|
2511
|
+
const targetFakeJid = fakeJid || authCreds.me?.id || sock.user?.id || "0@s.whatsapp.net";
|
|
2512
|
+
const meId = authCreds.me?.id ?? sock.user?.id ?? "0@s.whatsapp.net";
|
|
2513
|
+
const quoted = {
|
|
2514
|
+
key: {
|
|
2515
|
+
id: generateMessageIDV2(meId),
|
|
2516
|
+
fromMe: targetFakeJid === meId,
|
|
2517
|
+
participant: targetFakeJid,
|
|
2518
|
+
...(fakeGroupJid ? { remoteJid: fakeGroupJid } : {}),
|
|
2519
|
+
},
|
|
2520
|
+
message: { conversation: fakeText },
|
|
2521
|
+
participant: targetFakeJid,
|
|
2522
|
+
};
|
|
2523
|
+
return await sock.sendMessage(jid, { text, ...options }, { quoted, ...options });
|
|
2524
|
+
},
|
|
2525
|
+
async sendAfterRead(jid, content, options) {
|
|
2526
|
+
const duration = typeof options?.duration === "number" && options.duration >= 0 ? options.duration : 5;
|
|
2527
|
+
const quoted = options?.quoted;
|
|
2528
|
+
const afterReadCtx = {
|
|
2529
|
+
expiration: 0,
|
|
2530
|
+
ephemeralSettingTimestamp: Math.floor(Date.now() / 1000),
|
|
2531
|
+
disappearingMode: { initiator: 0, trigger: 1 },
|
|
2532
|
+
afterReadDuration: duration,
|
|
2533
|
+
...(options?.contextInfo || {}),
|
|
2534
|
+
};
|
|
2535
|
+
if (typeof content === "string") {
|
|
2536
|
+
return await sock.sendMessage(jid, {
|
|
2537
|
+
rawMessage: {
|
|
2538
|
+
extendedTextMessage: {
|
|
2539
|
+
text: content,
|
|
2540
|
+
previewType: 0,
|
|
2541
|
+
contextInfo: {
|
|
2542
|
+
...(quoted?.key?.id
|
|
2543
|
+
? {
|
|
2544
|
+
stanzaId: quoted.key.id,
|
|
2545
|
+
participant: quoted.sender || quoted.key.participant,
|
|
2546
|
+
quotedMessage: quoted.message,
|
|
2547
|
+
}
|
|
2548
|
+
: {}),
|
|
2549
|
+
...afterReadCtx,
|
|
2550
|
+
},
|
|
2551
|
+
},
|
|
2552
|
+
},
|
|
2553
|
+
});
|
|
2554
|
+
}
|
|
2555
|
+
return await sock.sendMessage(jid, {
|
|
2556
|
+
...content,
|
|
2557
|
+
contextInfo: {
|
|
2558
|
+
...(content?.contextInfo || {}),
|
|
2559
|
+
...afterReadCtx,
|
|
2560
|
+
},
|
|
2561
|
+
}, quoted ? { quoted } : undefined);
|
|
2562
|
+
},
|
|
2404
2563
|
async sendPresenceUpdate(presence, toJid) {
|
|
2405
2564
|
if (toJid && (presence === "composing" || presence === "recording" || presence === "paused")) {
|
|
2406
2565
|
transport.sendEncrypted(encodeWABinaryNode({
|
|
@@ -2463,31 +2622,50 @@ export function makeWASocket(config = {}) {
|
|
|
2463
2622
|
sticker: "/mms/image",
|
|
2464
2623
|
document: "/mms/document",
|
|
2465
2624
|
};
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2625
|
+
const nlPathMap = {
|
|
2626
|
+
image: "/newsletter/newsletter-image",
|
|
2627
|
+
video: "/newsletter/newsletter-video",
|
|
2628
|
+
audio: "/newsletter/newsletter-audio",
|
|
2629
|
+
ptt: "/newsletter/newsletter-ptt",
|
|
2630
|
+
sticker: "/newsletter/newsletter-sticker",
|
|
2631
|
+
document: "/newsletter/newsletter-document",
|
|
2632
|
+
};
|
|
2633
|
+
let uploadBody;
|
|
2634
|
+
let tokenB64;
|
|
2635
|
+
if (opts.newsletter) {
|
|
2636
|
+
const buf = stream instanceof Uint8Array ? stream : await toBuffer(stream);
|
|
2637
|
+
uploadBody = buf;
|
|
2638
|
+
tokenB64 = opts.fileSha256B64 ?? createHash("sha256").update(buf).digest("base64");
|
|
2639
|
+
}
|
|
2640
|
+
else if (opts.encData && opts.fileEncSha256B64) {
|
|
2641
|
+
uploadBody = opts.encData;
|
|
2642
|
+
tokenB64 = opts.fileEncSha256B64;
|
|
2471
2643
|
}
|
|
2472
2644
|
else {
|
|
2473
2645
|
const buf = stream instanceof Uint8Array ? stream : await toBuffer(stream);
|
|
2474
2646
|
const enc = encryptWaMedia(buf, mType);
|
|
2475
|
-
|
|
2476
|
-
|
|
2647
|
+
uploadBody = enc.encData;
|
|
2648
|
+
tokenB64 = enc.fileEncSha256.toString("base64");
|
|
2477
2649
|
}
|
|
2478
2650
|
const mc = await sock.refreshMediaConn();
|
|
2479
2651
|
const host = mc.hosts[0]?.hostname ?? "mmg.whatsapp.net";
|
|
2480
|
-
const token = Buffer.from(
|
|
2481
|
-
const
|
|
2652
|
+
const token = Buffer.from(tokenB64, "base64").toString("base64url");
|
|
2653
|
+
const upPath = opts.newsletter ? (nlPathMap[mType] ?? "/newsletter/newsletter-document") : (pathMap[mType] ?? "/mms/document");
|
|
2654
|
+
const upUrl = `https://${host}${upPath}/${token}?auth=${encodeURIComponent(mc.auth)}&token=${token}`;
|
|
2482
2655
|
const res = await fetch(upUrl, {
|
|
2483
2656
|
method: "POST",
|
|
2484
2657
|
headers: { "Content-Type": "application/octet-stream", Origin: "https://web.whatsapp.com" },
|
|
2485
|
-
body: new Uint8Array(
|
|
2658
|
+
body: new Uint8Array(uploadBody),
|
|
2486
2659
|
});
|
|
2487
2660
|
if (!res.ok)
|
|
2488
2661
|
throw new Error(`Media upload failed (${res.status})`);
|
|
2489
2662
|
const json = (await res.json());
|
|
2490
|
-
return {
|
|
2663
|
+
return {
|
|
2664
|
+
mediaUrl: json.url ?? "",
|
|
2665
|
+
directPath: json.direct_path ?? "",
|
|
2666
|
+
...(json.handle ? { handle: json.handle } : {}),
|
|
2667
|
+
meta_hmac: "",
|
|
2668
|
+
};
|
|
2491
2669
|
},
|
|
2492
2670
|
async updateMediaMessage(msg) {
|
|
2493
2671
|
const inner = normalizeMessageContent(msg?.message ?? msg);
|
|
@@ -2956,6 +3134,35 @@ export async function prepareWAMessageMedia(media, options) {
|
|
|
2956
3134
|
buf = Buffer.from(raw);
|
|
2957
3135
|
}
|
|
2958
3136
|
const encType = kind === "audio" && media.ptt ? "ptt" : kind;
|
|
3137
|
+
const isNewsletterUpload = Boolean(options?.newsletter);
|
|
3138
|
+
if (isNewsletterUpload) {
|
|
3139
|
+
const fileSha256 = createHash("sha256").update(buf).digest();
|
|
3140
|
+
let uploaded;
|
|
3141
|
+
if (typeof options?.upload === "function") {
|
|
3142
|
+
uploaded = await options.upload(buf, {
|
|
3143
|
+
mediaType: encType,
|
|
3144
|
+
newsletter: true,
|
|
3145
|
+
fileSha256B64: fileSha256.toString("base64"),
|
|
3146
|
+
});
|
|
3147
|
+
}
|
|
3148
|
+
return {
|
|
3149
|
+
[`${kind}Message`]: {
|
|
3150
|
+
...(uploaded?.mediaUrl || uploaded?.url ? { url: uploaded.mediaUrl || uploaded.url } : {}),
|
|
3151
|
+
...(uploaded?.directPath || uploaded?.direct_path
|
|
3152
|
+
? { directPath: uploaded.directPath || uploaded.direct_path }
|
|
3153
|
+
: {}),
|
|
3154
|
+
...(uploaded?.handle ? { __mediaHandle: uploaded.handle } : {}),
|
|
3155
|
+
fileSha256,
|
|
3156
|
+
fileLength: buf.length,
|
|
3157
|
+
mimetype: media.mimetype ?? (kind === "audio" && media.ptt ? "audio/ogg; codecs=opus" : defaultMime[kind]),
|
|
3158
|
+
...(typeof media.ptt === "boolean" ? { ptt: media.ptt } : {}),
|
|
3159
|
+
...(typeof media.seconds === "number" ? { seconds: media.seconds } : {}),
|
|
3160
|
+
...(typeof media.isAnimated === "boolean" ? { isAnimated: media.isAnimated } : {}),
|
|
3161
|
+
...(typeof media.caption === "string" ? { caption: media.caption } : {}),
|
|
3162
|
+
...(typeof media.fileName === "string" ? { fileName: media.fileName } : {}),
|
|
3163
|
+
},
|
|
3164
|
+
};
|
|
3165
|
+
}
|
|
2959
3166
|
const enc = encryptWaMedia(buf, encType);
|
|
2960
3167
|
let uploaded;
|
|
2961
3168
|
if (typeof options?.upload === "function") {
|
|
@@ -2974,6 +3181,7 @@ export async function prepareWAMessageMedia(media, options) {
|
|
|
2974
3181
|
mediaKey: enc.mediaKey,
|
|
2975
3182
|
fileSha256: enc.fileSha256,
|
|
2976
3183
|
fileEncSha256: enc.fileEncSha256,
|
|
3184
|
+
...(enc.streamingSidecar ? { streamingSidecar: enc.streamingSidecar } : {}),
|
|
2977
3185
|
fileLength: buf.length,
|
|
2978
3186
|
mediaKeyTimestamp: Math.floor(Date.now() / 1000),
|
|
2979
3187
|
mimetype: media.mimetype ?? (kind === "audio" && media.ptt ? "audio/ogg; codecs=opus" : defaultMime[kind]),
|