@awangxcode/qiro-baileys 7.0.0-rc25.6 → 7.0.0-rc26.3
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/LICENSE +15 -0
- package/README.md +1445 -1041
- package/WAProto/WAProto.proto +4 -0
- package/WAProto/index.d.ts +4067 -243
- package/WAProto/index.js +74957 -43330
- package/assets/branding/qiro-logo.svg +24 -0
- package/assets/branding/qiro-mark.png +0 -0
- package/assets/branding/qiro-mark.svg +34 -0
- package/assets/branding/qiro-social-preview.png +0 -0
- package/lib/Defaults/index.d.ts +15 -0
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +40 -7
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Extensions/experimental.d.ts +0 -2
- package/lib/Extensions/experimental.d.ts.map +1 -1
- package/lib/Extensions/experimental.js +0 -2
- package/lib/Extensions/experimental.js.map +1 -1
- package/lib/MessageBuilder/index.d.ts.map +1 -1
- package/lib/MessageBuilder/index.js +10 -1
- package/lib/MessageBuilder/index.js.map +1 -1
- package/lib/Signal/lid-mapping.js +3 -3
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/business.d.ts +283 -1
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/chats.d.ts +114 -1
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +285 -10
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +283 -1
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/groups.d.ts +106 -0
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/index.d.ts +283 -1
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +4 -1
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +284 -1
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +73 -22
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +297 -1
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +164 -28
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +322 -37
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +341 -1
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +13 -0
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +84 -31
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +397 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +24 -0
- package/lib/Types/Chat.d.ts +13 -0
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Chat.js.map +1 -1
- package/lib/Types/Message.d.ts +65 -1
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/Mex.d.ts +68 -39
- package/lib/Types/Mex.d.ts.map +1 -1
- package/lib/Types/Mex.js +66 -0
- package/lib/Types/Mex.js.map +1 -1
- package/lib/Types/Socket.d.ts +45 -0
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Utils/audio-sticker.d.ts +14 -0
- package/lib/Utils/audio-sticker.js +172 -0
- package/lib/Utils/auth-store.d.ts +30 -0
- package/lib/Utils/auth-store.js +77 -0
- package/lib/Utils/chat-theme.d.ts +34 -0
- package/lib/Utils/chat-theme.js +336 -0
- package/lib/Utils/chat-utils.js +2 -2
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts +14 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +55 -0
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +2 -1
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js +3 -4
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +3 -2
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +10 -19
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/group-metadata-cache.d.ts +4 -0
- package/lib/Utils/group-metadata-cache.js +25 -0
- package/lib/Utils/history.js +1 -1
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/html-app.d.ts +19 -0
- package/lib/Utils/html-app.js +96 -0
- package/lib/Utils/html-multiplayer.d.ts +10 -0
- package/lib/Utils/html-multiplayer.js +94 -0
- package/lib/Utils/index.d.ts +25 -0
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +27 -0
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview-metadata.d.ts +47 -0
- package/lib/Utils/link-preview-metadata.js +88 -0
- package/lib/Utils/messages-media.d.ts +31 -2
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +66 -19
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +42 -2
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +117 -26
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/modern-messages.d.ts +150 -0
- package/lib/Utils/modern-messages.js +496 -0
- package/lib/Utils/native-flow.d.ts +11 -0
- package/lib/Utils/native-flow.js +116 -0
- package/lib/Utils/newsletter-status.d.ts +158 -0
- package/lib/Utils/newsletter-status.js +651 -0
- package/lib/Utils/optional-media.d.ts +3 -0
- package/lib/Utils/optional-media.js +46 -0
- package/lib/Utils/payment-messages.d.ts +38 -0
- package/lib/Utils/payment-messages.js +160 -0
- package/lib/Utils/process-message.d.ts +11 -0
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +80 -0
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/scheduled-message.d.ts +51 -0
- package/lib/Utils/scheduled-message.js +113 -0
- package/lib/Utils/sender-key-memory.d.ts +19 -0
- package/lib/Utils/sender-key-memory.js +51 -0
- package/lib/Utils/status-stickers.d.ts +127 -0
- package/lib/Utils/status-stickers.js +261 -0
- package/lib/Utils/ttl-cache.d.ts +29 -0
- package/lib/Utils/ttl-cache.js +121 -0
- package/lib/Utils/use-mongo-auth-state.d.ts +22 -0
- package/lib/Utils/use-mongo-auth-state.js +68 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -1
- package/lib/Utils/use-multi-file-auth-state.js +26 -13
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
- package/lib/Utils/use-mysql-auth-state.d.ts +20 -0
- package/lib/Utils/use-mysql-auth-state.js +80 -0
- package/lib/Utils/use-nekodb-auth.d.ts +19 -0
- package/lib/Utils/use-nekodb-auth.js +111 -0
- package/lib/Utils/use-postgres-auth-state.d.ts +20 -0
- package/lib/Utils/use-postgres-auth-state.js +80 -0
- package/lib/Utils/use-redis-auth-state.d.ts +20 -0
- package/lib/Utils/use-redis-auth-state.js +90 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +109 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +13 -0
- package/lib/Utils/use-sqlite-auth-state.js +121 -0
- package/lib/Utils/username.d.ts +12 -0
- package/lib/Utils/username.js +59 -0
- package/lib/Utils/voice-recognition.d.ts +53 -0
- package/lib/Utils/voice-recognition.js +219 -0
- package/lib/VoIP/audio-feeder.d.ts +24 -0
- package/lib/VoIP/audio-feeder.js +276 -0
- package/lib/VoIP/index.d.ts +93 -0
- package/lib/VoIP/index.js +998 -0
- package/lib/VoIP/relay-transport.d.ts +5 -0
- package/lib/VoIP/relay-transport.js +824 -0
- package/lib/VoIP/signaling.d.ts +11 -0
- package/lib/VoIP/signaling.js +1099 -0
- package/lib/VoIP/types.d.ts +2 -0
- package/lib/VoIP/types.js +12 -0
- package/lib/VoIP/video-feeder.d.ts +24 -0
- package/lib/VoIP/video-feeder.js +276 -0
- package/lib/VoIP/wasm-engine.d.ts +26 -0
- package/lib/VoIP/wasm-engine.js +1318 -0
- package/lib/VoIP/worker-bootstrap.js +1022 -0
- package/lib/WABinary/generic-utils.d.ts +2 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +2 -0
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WABinary/jid-utils.d.ts +2 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -1
- package/lib/WABinary/jid-utils.js +3 -1
- package/lib/WABinary/jid-utils.js.map +1 -1
- package/lib/extensions/awang-MessageBuilder.js +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/package.json +78 -31
- package/MIGRASI-QIRO-BAILEYS-RC25.md +0 -102
- package/QIRO-BAILEYS-RC25.md +0 -168
- package/THIRD_PARTY_NOTICES.md +0 -49
- /package/{engine-requirements.js → config/engine-requirements.js} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
export const pickSenderKeyRecipients = (devices, senderKeyMap, { force = false, skip } = {}) => {
|
|
3
|
+
const recipients = []
|
|
4
|
+
for (const device of devices) {
|
|
5
|
+
const deviceJid = device?.jid
|
|
6
|
+
if (!deviceJid) {
|
|
7
|
+
continue
|
|
8
|
+
}
|
|
9
|
+
if (!force && senderKeyMap[deviceJid]) {
|
|
10
|
+
continue
|
|
11
|
+
}
|
|
12
|
+
if (skip && skip(device)) {
|
|
13
|
+
continue
|
|
14
|
+
}
|
|
15
|
+
recipients.push(deviceJid)
|
|
16
|
+
}
|
|
17
|
+
return recipients
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const deliveredSenderKeyJids = nodes => {
|
|
21
|
+
const delivered = new Set()
|
|
22
|
+
for (const node of nodes || []) {
|
|
23
|
+
const jid = node?.attrs?.jid
|
|
24
|
+
if (jid) {
|
|
25
|
+
delivered.add(jid)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return delivered
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const senderKeyResetSummary = (stored, jid) => {
|
|
32
|
+
const devices = Object.keys(stored?.[jid] || {})
|
|
33
|
+
return { jid, cleared: devices.length, devices }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const commitSenderKeyDelivery = (senderKeyMap, recipients, nodes) => {
|
|
37
|
+
const delivered = deliveredSenderKeyJids(nodes)
|
|
38
|
+
const marked = []
|
|
39
|
+
const skipped = []
|
|
40
|
+
for (const jid of recipients) {
|
|
41
|
+
if (delivered.has(jid)) {
|
|
42
|
+
senderKeyMap[jid] = true
|
|
43
|
+
marked.push(jid)
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
delete senderKeyMap[jid]
|
|
47
|
+
skipped.push(jid)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { marked, skipped }
|
|
51
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { proto } from '../../WAProto/index.js';
|
|
2
|
+
|
|
3
|
+
export declare const StatusLinkType: Readonly<{
|
|
4
|
+
RASTERIZED_LINK_PREVIEW: 1;
|
|
5
|
+
RASTERIZED_LINK_TRUNCATED: 2;
|
|
6
|
+
RASTERIZED_LINK_FULL_URL: 3;
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
export interface StickerArea {
|
|
10
|
+
/** Distance from the left edge, as a fraction of the media width. */
|
|
11
|
+
x: number;
|
|
12
|
+
/** Distance from the top edge, as a fraction of the media height. */
|
|
13
|
+
y: number;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export declare const STICKER_DEFAULT_AREA: Readonly<StickerArea>;
|
|
19
|
+
|
|
20
|
+
export declare function stickerArea(area?: StickerArea): proto.IPoint[];
|
|
21
|
+
|
|
22
|
+
export declare function locationSticker(options: {
|
|
23
|
+
latitude: number;
|
|
24
|
+
longitude: number;
|
|
25
|
+
name?: string;
|
|
26
|
+
area?: StickerArea | proto.IPoint[];
|
|
27
|
+
skipConfirmation?: boolean;
|
|
28
|
+
}): proto.IInteractiveAnnotation;
|
|
29
|
+
|
|
30
|
+
export declare function channelSticker(options: {
|
|
31
|
+
jid: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
serverMessageId?: number;
|
|
34
|
+
accessibilityText?: string;
|
|
35
|
+
area?: StickerArea | proto.IPoint[];
|
|
36
|
+
}): proto.IInteractiveAnnotation;
|
|
37
|
+
|
|
38
|
+
export declare function linkSticker(options: {
|
|
39
|
+
url: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
area?: StickerArea | proto.IPoint[];
|
|
42
|
+
linkType?: number;
|
|
43
|
+
}): proto.IInteractiveAnnotation;
|
|
44
|
+
|
|
45
|
+
export declare function musicSticker(options: {
|
|
46
|
+
songId?: string;
|
|
47
|
+
title?: string;
|
|
48
|
+
author?: string;
|
|
49
|
+
mediaId?: string;
|
|
50
|
+
artworkDirectPath?: string;
|
|
51
|
+
artworkSha256?: Buffer | string;
|
|
52
|
+
artworkEncSha256?: Buffer | string;
|
|
53
|
+
artworkMediaKey?: Buffer | string;
|
|
54
|
+
artistAttribution?: string;
|
|
55
|
+
countryBlocklist?: Buffer | string;
|
|
56
|
+
isExplicit?: boolean;
|
|
57
|
+
startTimeMs?: number;
|
|
58
|
+
derivedStartTimeMs?: number;
|
|
59
|
+
durationMs?: number;
|
|
60
|
+
area?: StickerArea | proto.IPoint[];
|
|
61
|
+
}): proto.IInteractiveAnnotation;
|
|
62
|
+
|
|
63
|
+
export declare function messageSticker(options: {
|
|
64
|
+
stanzaId?: string;
|
|
65
|
+
message: proto.IMessage;
|
|
66
|
+
area?: StickerArea | proto.IPoint[];
|
|
67
|
+
}): proto.IInteractiveAnnotation;
|
|
68
|
+
|
|
69
|
+
export declare function normalizeStickers(
|
|
70
|
+
stickers: proto.IInteractiveAnnotation | proto.IInteractiveAnnotation[]
|
|
71
|
+
): proto.InteractiveAnnotation[];
|
|
72
|
+
|
|
73
|
+
export interface ReadSticker {
|
|
74
|
+
kind: 'location' | 'channel' | 'link' | 'music' | 'message' | 'unknown';
|
|
75
|
+
area?: StickerArea;
|
|
76
|
+
location?: proto.ILocation;
|
|
77
|
+
channel?: proto.ContextInfo.IForwardedNewsletterMessageInfo;
|
|
78
|
+
link?: { url?: string; title?: string; linkType?: number };
|
|
79
|
+
music?: { songId?: string; title?: string; author?: string };
|
|
80
|
+
message?: proto.IEmbeddedMessage;
|
|
81
|
+
annotation: proto.IInteractiveAnnotation;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export declare function readStickers(message: any): ReadSticker[];
|
|
85
|
+
|
|
86
|
+
export declare const MusicMessageStyle: Readonly<{ UNKNOWN: 0; VINYL: 1 }>;
|
|
87
|
+
|
|
88
|
+
export interface MusicMessageOptions {
|
|
89
|
+
songId?: string;
|
|
90
|
+
mediaId?: string;
|
|
91
|
+
title?: string;
|
|
92
|
+
author?: string;
|
|
93
|
+
artistAttribution?: string;
|
|
94
|
+
artworkDirectPath?: string;
|
|
95
|
+
artworkSha256?: Buffer | string;
|
|
96
|
+
artworkEncSha256?: Buffer | string;
|
|
97
|
+
artworkMediaKey?: Buffer | string;
|
|
98
|
+
countryBlocklist?: Buffer | string;
|
|
99
|
+
isExplicit?: boolean;
|
|
100
|
+
startTimeMs?: number;
|
|
101
|
+
derivedStartTimeMs?: number;
|
|
102
|
+
durationMs?: number;
|
|
103
|
+
songUri?: string;
|
|
104
|
+
artworkUri?: string;
|
|
105
|
+
style?: number;
|
|
106
|
+
contextInfo?: proto.IContextInfo;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export declare function buildMusicMessage(options?: MusicMessageOptions): proto.Message.IMusicMessage;
|
|
110
|
+
|
|
111
|
+
export declare function readMusicMessage(msg: any): {
|
|
112
|
+
songId?: string;
|
|
113
|
+
mediaId?: string;
|
|
114
|
+
title?: string;
|
|
115
|
+
author?: string;
|
|
116
|
+
artistAttribution?: string;
|
|
117
|
+
isExplicit?: boolean;
|
|
118
|
+
startTimeMs?: number | string;
|
|
119
|
+
durationMs?: number | string;
|
|
120
|
+
songUri?: string;
|
|
121
|
+
artworkUri?: string;
|
|
122
|
+
style?: number;
|
|
123
|
+
embeddedMusic: proto.IEmbeddedMusic;
|
|
124
|
+
} | null;
|
|
125
|
+
|
|
126
|
+
export declare const MUSIC_ALLOWED_HOSTS: readonly string[];
|
|
127
|
+
export declare function isMusicHostAllowed(value?: unknown): boolean;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
import { proto } from '../../WAProto/index.js'
|
|
3
|
+
|
|
4
|
+
export const StatusLinkType = Object.freeze({
|
|
5
|
+
RASTERIZED_LINK_PREVIEW: 1,
|
|
6
|
+
RASTERIZED_LINK_TRUNCATED: 2,
|
|
7
|
+
RASTERIZED_LINK_FULL_URL: 3
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export const STICKER_DEFAULT_AREA = Object.freeze({ x: 0.25, y: 0.4, width: 0.5, height: 0.2 })
|
|
11
|
+
|
|
12
|
+
const trimUndefined = (object) => {
|
|
13
|
+
for (const key of Object.keys(object)) {
|
|
14
|
+
if (object[key] === undefined) {
|
|
15
|
+
delete object[key]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return object
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const fraction = (value, name) => {
|
|
22
|
+
const number = Number(value)
|
|
23
|
+
if (!Number.isFinite(number) || number < 0 || number > 1) {
|
|
24
|
+
throw new TypeError(`${name} must be between 0 and 1, the client reads these as a fraction of the media`)
|
|
25
|
+
}
|
|
26
|
+
return number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const stickerArea = ({ x, y, width, height } = STICKER_DEFAULT_AREA) => {
|
|
30
|
+
const left = fraction(x, 'x')
|
|
31
|
+
const top = fraction(y, 'y')
|
|
32
|
+
const right = fraction(left + Number(width), 'x + width')
|
|
33
|
+
const bottom = fraction(top + Number(height), 'y + height')
|
|
34
|
+
if (right <= left || bottom <= top) {
|
|
35
|
+
throw new TypeError('a sticker area needs a positive width and height')
|
|
36
|
+
}
|
|
37
|
+
return [
|
|
38
|
+
{ x: left, y: top },
|
|
39
|
+
{ x: right, y: top },
|
|
40
|
+
{ x: right, y: bottom },
|
|
41
|
+
{ x: left, y: bottom }
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const annotation = (area, fields) => ({
|
|
46
|
+
polygonVertices: Array.isArray(area) ? area : stickerArea(area),
|
|
47
|
+
...fields
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
export const locationSticker = ({ latitude, longitude, name, area, skipConfirmation } = {}) => {
|
|
51
|
+
const degreesLatitude = Number(latitude)
|
|
52
|
+
const degreesLongitude = Number(longitude)
|
|
53
|
+
if (!Number.isFinite(degreesLatitude) || !Number.isFinite(degreesLongitude)) {
|
|
54
|
+
throw new TypeError('locationSticker needs a numeric latitude and longitude')
|
|
55
|
+
}
|
|
56
|
+
return annotation(area, {
|
|
57
|
+
location: { degreesLatitude, degreesLongitude, ...(name ? { name } : {}) },
|
|
58
|
+
...(skipConfirmation === undefined ? {} : { shouldSkipConfirmation: !!skipConfirmation })
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const channelSticker = ({ jid, name, serverMessageId = 0, accessibilityText, area } = {}) => {
|
|
63
|
+
if (typeof jid !== 'string' || !jid.endsWith('@newsletter')) {
|
|
64
|
+
throw new TypeError('channelSticker needs the channel jid, the one ending in @newsletter')
|
|
65
|
+
}
|
|
66
|
+
return annotation(area, {
|
|
67
|
+
newsletter: {
|
|
68
|
+
newsletterJid: jid,
|
|
69
|
+
serverMessageId: Number(serverMessageId),
|
|
70
|
+
...(name ? { newsletterName: name } : {}),
|
|
71
|
+
...(accessibilityText ? { accessibilityText } : {})
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const linkSticker = ({ url, title, area, linkType = StatusLinkType.RASTERIZED_LINK_PREVIEW } = {}) => {
|
|
77
|
+
if (typeof url !== 'string' || !url) {
|
|
78
|
+
throw new TypeError('linkSticker needs a url')
|
|
79
|
+
}
|
|
80
|
+
return annotation(area, {
|
|
81
|
+
tapAction: { tapUrl: url, ...(title ? { title } : {}) },
|
|
82
|
+
statusLinkType: linkType
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const musicSticker = ({
|
|
87
|
+
songId,
|
|
88
|
+
title,
|
|
89
|
+
author,
|
|
90
|
+
mediaId,
|
|
91
|
+
artworkDirectPath,
|
|
92
|
+
artworkSha256,
|
|
93
|
+
artworkEncSha256,
|
|
94
|
+
artworkMediaKey,
|
|
95
|
+
artistAttribution,
|
|
96
|
+
countryBlocklist,
|
|
97
|
+
isExplicit,
|
|
98
|
+
startTimeMs = 0,
|
|
99
|
+
derivedStartTimeMs,
|
|
100
|
+
durationMs,
|
|
101
|
+
area
|
|
102
|
+
} = {}) => {
|
|
103
|
+
if (!songId && !mediaId) {
|
|
104
|
+
throw new TypeError('musicSticker needs at least a songId or a musicContentMediaId')
|
|
105
|
+
}
|
|
106
|
+
const bytes = value => (value === undefined ? undefined : Buffer.isBuffer(value) ? value : Buffer.from(value, 'base64'))
|
|
107
|
+
const embeddedMusic = {
|
|
108
|
+
...(songId ? { songId: String(songId) } : {}),
|
|
109
|
+
...(mediaId ? { musicContentMediaId: String(mediaId) } : {}),
|
|
110
|
+
...(title ? { title } : {}),
|
|
111
|
+
...(author ? { author } : {}),
|
|
112
|
+
...(artistAttribution ? { artistAttribution } : {}),
|
|
113
|
+
...(artworkDirectPath ? { artworkDirectPath } : {}),
|
|
114
|
+
...(isExplicit === undefined ? {} : { isExplicit: !!isExplicit }),
|
|
115
|
+
musicSongStartTimeInMs: Number(startTimeMs),
|
|
116
|
+
...(derivedStartTimeMs === undefined ? {} : { derivedContentStartTimeInMs: Number(derivedStartTimeMs) }),
|
|
117
|
+
...(durationMs === undefined ? {} : { overlapDurationInMs: Number(durationMs) })
|
|
118
|
+
}
|
|
119
|
+
for (const [key, value] of [
|
|
120
|
+
['artworkSha256', artworkSha256],
|
|
121
|
+
['artworkEncSha256', artworkEncSha256],
|
|
122
|
+
['artworkMediaKey', artworkMediaKey],
|
|
123
|
+
['countryBlocklist', countryBlocklist]
|
|
124
|
+
]) {
|
|
125
|
+
const buffer = bytes(value)
|
|
126
|
+
if (buffer) {
|
|
127
|
+
embeddedMusic[key] = buffer
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return annotation(area, { embeddedContent: { embeddedMusic } })
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const messageSticker = ({ stanzaId, message, area } = {}) => {
|
|
134
|
+
if (!message) {
|
|
135
|
+
throw new TypeError('messageSticker needs the message it embeds')
|
|
136
|
+
}
|
|
137
|
+
return annotation(area, {
|
|
138
|
+
embeddedContent: { embeddedMessage: { ...(stanzaId ? { stanzaId } : {}), message } }
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const ACTIONS = ['location', 'newsletter', 'embeddedAction', 'tapAction']
|
|
143
|
+
|
|
144
|
+
export const normalizeStickers = (stickers) => {
|
|
145
|
+
const list = Array.isArray(stickers) ? stickers : [stickers]
|
|
146
|
+
return list.filter(Boolean).map((sticker, index) => {
|
|
147
|
+
const vertices = sticker.polygonVertices
|
|
148
|
+
if (!Array.isArray(vertices) || vertices.length !== 4) {
|
|
149
|
+
throw new TypeError(`sticker ${index} needs four polygonVertices, the client reads corner 0 and corner 2`)
|
|
150
|
+
}
|
|
151
|
+
const actions = ACTIONS.filter(name => sticker[name] !== undefined && sticker[name] !== null)
|
|
152
|
+
if (actions.length > 1) {
|
|
153
|
+
throw new TypeError(`sticker ${index} sets ${actions.join(' and ')}, but the client reads only one action per sticker`)
|
|
154
|
+
}
|
|
155
|
+
return proto.InteractiveAnnotation.fromObject(sticker)
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const readStickers = (message) => {
|
|
160
|
+
const media = message?.imageMessage ?? message?.videoMessage ?? message
|
|
161
|
+
const annotations = media?.interactiveAnnotations
|
|
162
|
+
if (!Array.isArray(annotations) || !annotations.length) {
|
|
163
|
+
return []
|
|
164
|
+
}
|
|
165
|
+
return annotations.map(item => {
|
|
166
|
+
const [topLeft, , bottomRight] = item.polygonVertices ?? []
|
|
167
|
+
const music = item.embeddedContent?.embeddedMusic
|
|
168
|
+
return {
|
|
169
|
+
kind: item.location
|
|
170
|
+
? 'location'
|
|
171
|
+
: item.newsletter
|
|
172
|
+
? 'channel'
|
|
173
|
+
: item.tapAction
|
|
174
|
+
? 'link'
|
|
175
|
+
: music
|
|
176
|
+
? 'music'
|
|
177
|
+
: item.embeddedContent?.embeddedMessage
|
|
178
|
+
? 'message'
|
|
179
|
+
: 'unknown',
|
|
180
|
+
area: topLeft && bottomRight
|
|
181
|
+
? { x: topLeft.x, y: topLeft.y, width: bottomRight.x - topLeft.x, height: bottomRight.y - topLeft.y }
|
|
182
|
+
: undefined,
|
|
183
|
+
location: item.location ?? undefined,
|
|
184
|
+
channel: item.newsletter ?? undefined,
|
|
185
|
+
link: item.tapAction ? { url: item.tapAction.tapUrl, title: item.tapAction.title, linkType: item.statusLinkType } : undefined,
|
|
186
|
+
music: music ? { songId: music.songId, title: music.title, author: music.author } : undefined,
|
|
187
|
+
message: item.embeddedContent?.embeddedMessage ?? undefined,
|
|
188
|
+
annotation: item
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export const MusicMessageStyle = Object.freeze({ UNKNOWN: 0, VINYL: 1 })
|
|
194
|
+
|
|
195
|
+
export const MUSIC_ALLOWED_HOSTS = Object.freeze([
|
|
196
|
+
'.whatsapp.net',
|
|
197
|
+
'.whatsapp.com',
|
|
198
|
+
'.fbcdn.net',
|
|
199
|
+
'.facebook.com',
|
|
200
|
+
'.instagram.com',
|
|
201
|
+
'.cdninstagram.com'
|
|
202
|
+
])
|
|
203
|
+
|
|
204
|
+
export const isMusicHostAllowed = (value) => {
|
|
205
|
+
let host
|
|
206
|
+
try {
|
|
207
|
+
host = new URL(String(value)).hostname.toLowerCase()
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return false
|
|
211
|
+
}
|
|
212
|
+
return MUSIC_ALLOWED_HOSTS.some(suffix => host.endsWith(suffix) || host === suffix.slice(1))
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const assertMusicHost = (value, label) => {
|
|
216
|
+
if (value === undefined) {
|
|
217
|
+
return undefined
|
|
218
|
+
}
|
|
219
|
+
if (!isMusicHostAllowed(value)) {
|
|
220
|
+
throw new TypeError(
|
|
221
|
+
`${label} must be hosted on ${MUSIC_ALLOWED_HOSTS.join(', ')} — the client refuses any other host `
|
|
222
|
+
+ 'and draws nothing. Both uris come from Meta music catalog entries, so carry them over from a '
|
|
223
|
+
+ 'message you received rather than pointing at your own file'
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
return value
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const embeddedMusicOf = (options) => musicSticker(options).embeddedContent.embeddedMusic
|
|
230
|
+
|
|
231
|
+
export const buildMusicMessage = ({ songUri, artworkUri, style = MusicMessageStyle.VINYL, contextInfo, ...music } = {}) =>
|
|
232
|
+
trimUndefined({
|
|
233
|
+
embeddedMusic: embeddedMusicOf(music),
|
|
234
|
+
songUri: assertMusicHost(songUri, 'songUri'),
|
|
235
|
+
artworkUri: assertMusicHost(artworkUri, 'artworkUri'),
|
|
236
|
+
style,
|
|
237
|
+
contextInfo
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
export const readMusicMessage = (msg) => {
|
|
241
|
+
const message = msg?.message ?? msg
|
|
242
|
+
const music = message?.musicMessage
|
|
243
|
+
if (!music) {
|
|
244
|
+
return null
|
|
245
|
+
}
|
|
246
|
+
const embedded = music.embeddedMusic ?? {}
|
|
247
|
+
return {
|
|
248
|
+
songId: embedded.songId,
|
|
249
|
+
mediaId: embedded.musicContentMediaId,
|
|
250
|
+
title: embedded.title,
|
|
251
|
+
author: embedded.author,
|
|
252
|
+
artistAttribution: embedded.artistAttribution,
|
|
253
|
+
isExplicit: embedded.isExplicit,
|
|
254
|
+
startTimeMs: embedded.musicSongStartTimeInMs,
|
|
255
|
+
durationMs: embedded.overlapDurationInMs,
|
|
256
|
+
songUri: music.songUri,
|
|
257
|
+
artworkUri: music.artworkUri,
|
|
258
|
+
style: music.style,
|
|
259
|
+
embeddedMusic: embedded
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
export declare class TTLCache<T = any> {
|
|
3
|
+
constructor(options?: {
|
|
4
|
+
/** lifetime in seconds, the same unit node-cache used; 0 or omitted means no expiry */
|
|
5
|
+
stdTTL?: number;
|
|
6
|
+
/** ceiling on entries, the oldest is evicted once it is reached */
|
|
7
|
+
maxKeys?: number;
|
|
8
|
+
/** alias for maxKeys */
|
|
9
|
+
max?: number;
|
|
10
|
+
/** lifetime in milliseconds, takes precedence over stdTTL */
|
|
11
|
+
ttl?: number;
|
|
12
|
+
});
|
|
13
|
+
get(key: string | number): T | undefined;
|
|
14
|
+
set(key: string | number, value: T, ttl?: number): boolean;
|
|
15
|
+
has(key: string | number): boolean;
|
|
16
|
+
del(keys: string | number | Array<string | number>): number;
|
|
17
|
+
take(key: string | number): T | undefined;
|
|
18
|
+
mget(keys: Array<string | number>): Record<string, T>;
|
|
19
|
+
mset(list: Array<{ key: string | number; value?: T; val?: T; ttl?: number }>): boolean;
|
|
20
|
+
keys(): string[];
|
|
21
|
+
flushAll(): void;
|
|
22
|
+
getStats(): { hits: number; misses: number; keys: number; ksize: number; vsize: number };
|
|
23
|
+
close(): void;
|
|
24
|
+
on(): this;
|
|
25
|
+
off(): this;
|
|
26
|
+
removeAllListeners(): this;
|
|
27
|
+
readonly size: number;
|
|
28
|
+
}
|
|
29
|
+
export default TTLCache;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
import { LRUCache } from 'lru-cache';
|
|
3
|
+
import { DEFAULT_CACHE_MAX_KEYS } from '../Defaults/index.js';
|
|
4
|
+
|
|
5
|
+
const asKey = (key) => (typeof key === 'string' ? key : String(key));
|
|
6
|
+
|
|
7
|
+
const toMilliseconds = (seconds) => {
|
|
8
|
+
const value = Number(seconds);
|
|
9
|
+
return Number.isFinite(value) && value > 0 ? Math.round(value * 1000) : 0;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export class TTLCache {
|
|
13
|
+
#store;
|
|
14
|
+
|
|
15
|
+
#ttl;
|
|
16
|
+
|
|
17
|
+
#hits = 0;
|
|
18
|
+
|
|
19
|
+
#misses = 0;
|
|
20
|
+
|
|
21
|
+
constructor({ stdTTL = 0, maxKeys, max, ttl } = {}) {
|
|
22
|
+
this.#ttl = ttl !== undefined ? Number(ttl) || 0 : toMilliseconds(stdTTL);
|
|
23
|
+
const limit = Number(max ?? maxKeys);
|
|
24
|
+
this.#store = new LRUCache({
|
|
25
|
+
max: Number.isFinite(limit) && limit > 0 ? limit : DEFAULT_CACHE_MAX_KEYS,
|
|
26
|
+
...(this.#ttl ? { ttl: this.#ttl } : {})
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get(key) {
|
|
31
|
+
const value = this.#store.get(asKey(key));
|
|
32
|
+
if (value === undefined) {
|
|
33
|
+
this.#misses += 1;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.#hits += 1;
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
set(key, value, ttl) {
|
|
42
|
+
const override = toMilliseconds(ttl);
|
|
43
|
+
this.#store.set(asKey(key), value, override ? { ttl: override } : undefined);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
has(key) {
|
|
48
|
+
return this.#store.has(asKey(key));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
del(keys) {
|
|
52
|
+
const list = Array.isArray(keys) ? keys : [keys];
|
|
53
|
+
let removed = 0;
|
|
54
|
+
for (const key of list) {
|
|
55
|
+
if (this.#store.delete(asKey(key))) {
|
|
56
|
+
removed += 1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return removed;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
take(key) {
|
|
63
|
+
const value = this.get(key);
|
|
64
|
+
this.del(key);
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
mget(keys) {
|
|
69
|
+
const found = {};
|
|
70
|
+
for (const key of Array.isArray(keys) ? keys : [keys]) {
|
|
71
|
+
const value = this.get(key);
|
|
72
|
+
if (value !== undefined) {
|
|
73
|
+
found[key] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return found;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
mset(list) {
|
|
80
|
+
for (const item of list ?? []) {
|
|
81
|
+
this.set(item.key, item.value ?? item.val, item.ttl);
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
keys() {
|
|
87
|
+
return [...this.#store.keys()];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
flushAll() {
|
|
91
|
+
this.#store.clear();
|
|
92
|
+
this.#hits = 0;
|
|
93
|
+
this.#misses = 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getStats() {
|
|
97
|
+
return { hits: this.#hits, misses: this.#misses, keys: this.#store.size, ksize: 0, vsize: 0 };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
close() {
|
|
101
|
+
this.#store.clear();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
on() {
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
off() {
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
removeAllListeners() {
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
get size() {
|
|
117
|
+
return this.#store.size;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export default TTLCache;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
export interface MongoAuthStateOptions {
|
|
3
|
+
collection?: any;
|
|
4
|
+
db?: any;
|
|
5
|
+
uri?: string;
|
|
6
|
+
clientOptions?: any;
|
|
7
|
+
dbName?: string;
|
|
8
|
+
collectionName?: string;
|
|
9
|
+
session?: string;
|
|
10
|
+
}
|
|
11
|
+
export function useMongoAuthState(opts?: MongoAuthStateOptions): Promise<{
|
|
12
|
+
state: {
|
|
13
|
+
creds: any;
|
|
14
|
+
keys: {
|
|
15
|
+
get: (type: any, ids: any) => Promise<{}>;
|
|
16
|
+
set: (data: any) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
saveCreds: () => Promise<void>;
|
|
20
|
+
clearAuth: () => Promise<void>;
|
|
21
|
+
close: () => Promise<void>;
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
import { loadOptionalModule, makeAuthStateFromStore } from './auth-store.js';
|
|
3
|
+
export async function useMongoAuthState(opts = {}) {
|
|
4
|
+
const session = opts.session ?? 'default';
|
|
5
|
+
let collection = opts.collection;
|
|
6
|
+
let client;
|
|
7
|
+
if (!collection) {
|
|
8
|
+
let db = opts.db;
|
|
9
|
+
if (!db) {
|
|
10
|
+
if (!opts.uri) {
|
|
11
|
+
throw new Error('useMongoAuthState needs a collection, a db, or a uri');
|
|
12
|
+
}
|
|
13
|
+
const mongodb = await loadOptionalModule('mongodb', 'useMongoAuthState');
|
|
14
|
+
client = new mongodb.MongoClient(opts.uri, opts.clientOptions);
|
|
15
|
+
await client.connect();
|
|
16
|
+
db = client.db(opts.dbName);
|
|
17
|
+
}
|
|
18
|
+
collection = db.collection(opts.collectionName ?? 'baileys_auth');
|
|
19
|
+
}
|
|
20
|
+
await collection.createIndex({ session: 1, type: 1, id: 1 }, { unique: true });
|
|
21
|
+
const store = {
|
|
22
|
+
read: async (type, id) => {
|
|
23
|
+
const doc = await collection.findOne({ session, type, id });
|
|
24
|
+
return doc?.value ?? null;
|
|
25
|
+
},
|
|
26
|
+
readMany: async (type, ids) => {
|
|
27
|
+
if (!ids.length) {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
const docs = await collection.find({ session, type, id: { $in: ids } }).toArray();
|
|
31
|
+
const rows = {};
|
|
32
|
+
for (const doc of docs) {
|
|
33
|
+
rows[doc.id] = doc.value;
|
|
34
|
+
}
|
|
35
|
+
return rows;
|
|
36
|
+
},
|
|
37
|
+
write: async (type, id, value) => {
|
|
38
|
+
await collection.updateOne({ session, type, id }, { $set: { value } }, { upsert: true });
|
|
39
|
+
},
|
|
40
|
+
apply: async (writes, removals) => {
|
|
41
|
+
const operations = [];
|
|
42
|
+
for (const entry of writes) {
|
|
43
|
+
operations.push({
|
|
44
|
+
updateOne: {
|
|
45
|
+
filter: { session, type: entry.type, id: entry.id },
|
|
46
|
+
update: { $set: { value: entry.value } },
|
|
47
|
+
upsert: true
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
for (const entry of removals) {
|
|
52
|
+
operations.push({
|
|
53
|
+
deleteOne: {
|
|
54
|
+
filter: { session, type: entry.type, id: entry.id }
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
await collection.bulkWrite(operations, { ordered: false });
|
|
59
|
+
},
|
|
60
|
+
clear: async () => {
|
|
61
|
+
await collection.deleteMany({ session });
|
|
62
|
+
},
|
|
63
|
+
close: async () => {
|
|
64
|
+
await client?.close();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return makeAuthStateFromStore(store);
|
|
68
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-multi-file-auth-state.d.ts","sourceRoot":"","sources":["../../src/Utils/use-multi-file-auth-state.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAuB,mBAAmB,EAAqB,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"use-multi-file-auth-state.d.ts","sourceRoot":"","sources":["../../src/Utils/use-multi-file-auth-state.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAuB,mBAAmB,EAAqB,MAAM,UAAU,CAAA;AAW3F,eAAO,MAAM,kBAAkB,cAAuB,CAAA;AAYtD;;;;;;KAMK;AACL,eAAO,MAAM,qBAAqB,GACjC,QAAQ,MAAM,KACZ,OAAO,CAAC;IAAE,KAAK,EAAE,mBAAmB,CAAC;IAAC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAgHxE,CAAA"}
|