@periskope/baileys 6.7.16-alpha.9 → 6.7.17-alpha.2
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/lib/Socket/business.d.ts +5 -5
- package/lib/Socket/chats.d.ts +3 -3
- package/lib/Socket/groups.d.ts +4 -4
- package/lib/Socket/groups.js +2 -2
- package/lib/Socket/index.d.ts +5 -5
- package/lib/Socket/messages-recv.d.ts +5 -5
- package/lib/Socket/messages-recv.js +18 -3
- package/lib/Socket/messages-send.d.ts +5 -5
- package/lib/Socket/socket.d.ts +3 -3
- package/lib/Socket/socket.js +6 -4
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Types/Events.d.ts +1 -1
- package/lib/Types/GroupMetadata.d.ts +1 -1
- package/lib/Types/Message.d.ts +1 -1
- package/lib/Utils/business.js +11 -3
- package/lib/Utils/generics.js +1 -1
- package/lib/Utils/messages-media.d.ts +2 -3
- package/lib/Utils/messages-media.js +41 -41
- package/lib/Utils/messages.js +14 -16
- package/package.json +1 -1
package/lib/Socket/business.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
20
20
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
21
21
|
fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").default) => Promise<string>;
|
|
22
22
|
requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
|
|
23
|
-
getPrivacyTokens: (jids: string[]) => Promise<
|
|
23
|
+
getPrivacyTokens: (jids: string[]) => Promise<any>;
|
|
24
24
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
25
25
|
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
26
26
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
@@ -60,7 +60,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
60
60
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
61
61
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
62
62
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
63
|
-
groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<
|
|
63
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
|
|
64
64
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
65
65
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
66
66
|
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
@@ -130,8 +130,8 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
130
130
|
signalRepository: import("../Types").SignalRepository;
|
|
131
131
|
user: import("../Types").Contact | undefined;
|
|
132
132
|
generateMessageTag: () => string;
|
|
133
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
134
|
-
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
|
133
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
134
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
135
135
|
waitForSocketOpen: () => Promise<void>;
|
|
136
136
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
137
137
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
@@ -142,5 +142,5 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
142
142
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
143
143
|
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
144
144
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
145
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
145
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
146
146
|
};
|
package/lib/Socket/chats.d.ts
CHANGED
|
@@ -69,8 +69,8 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
69
69
|
signalRepository: import("../Types").SignalRepository;
|
|
70
70
|
user: import("../Types").Contact | undefined;
|
|
71
71
|
generateMessageTag: () => string;
|
|
72
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
73
|
-
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
|
72
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
73
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
74
74
|
waitForSocketOpen: () => Promise<void>;
|
|
75
75
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
76
76
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
@@ -81,5 +81,5 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
81
81
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
82
82
|
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
83
83
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
84
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
84
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
85
85
|
};
|
package/lib/Socket/groups.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
34
34
|
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
35
35
|
* @param inviteMessage the message to accept
|
|
36
36
|
*/
|
|
37
|
-
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<
|
|
37
|
+
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
|
|
38
38
|
groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
|
|
39
39
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
40
40
|
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
@@ -107,8 +107,8 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
107
107
|
signalRepository: import("../Types").SignalRepository;
|
|
108
108
|
user: import("../Types").Contact | undefined;
|
|
109
109
|
generateMessageTag: () => string;
|
|
110
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
111
|
-
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
|
110
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
111
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
112
112
|
waitForSocketOpen: () => Promise<void>;
|
|
113
113
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
114
114
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
@@ -119,6 +119,6 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
119
119
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
120
120
|
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
121
121
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
122
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
122
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
123
123
|
};
|
|
124
124
|
export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
|
package/lib/Socket/groups.js
CHANGED
|
@@ -69,7 +69,7 @@ const makeGroupsSocket = (config) => {
|
|
|
69
69
|
...sock,
|
|
70
70
|
groupMetadata,
|
|
71
71
|
groupCreate: async (subject, participants) => {
|
|
72
|
-
const key = (0, Utils_1.
|
|
72
|
+
const key = (0, Utils_1.generateMessageIDV2)();
|
|
73
73
|
const result = await groupQuery('@g.us', 'set', [
|
|
74
74
|
{
|
|
75
75
|
tag: 'create',
|
|
@@ -163,7 +163,7 @@ const makeGroupsSocket = (config) => {
|
|
|
163
163
|
{
|
|
164
164
|
tag: 'description',
|
|
165
165
|
attrs: {
|
|
166
|
-
...(description ? { id: (0, Utils_1.
|
|
166
|
+
...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
|
|
167
167
|
...(prev ? { prev } : {})
|
|
168
168
|
},
|
|
169
169
|
content: description ? [
|
package/lib/Socket/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
19
19
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
20
20
|
fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").default) => Promise<string>;
|
|
21
21
|
requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
|
|
22
|
-
getPrivacyTokens: (jids: string[]) => Promise<
|
|
22
|
+
getPrivacyTokens: (jids: string[]) => Promise<any>;
|
|
23
23
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
24
24
|
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
25
25
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
@@ -59,7 +59,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
59
59
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
60
60
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
61
61
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
62
|
-
groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<
|
|
62
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
|
|
63
63
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
64
64
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
65
65
|
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
@@ -129,8 +129,8 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
129
129
|
signalRepository: import("../Types").SignalRepository;
|
|
130
130
|
user: import("../Types").Contact | undefined;
|
|
131
131
|
generateMessageTag: () => string;
|
|
132
|
-
query: (node: import("..").BinaryNode, timeoutMs?: number) => Promise<
|
|
133
|
-
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
|
132
|
+
query: (node: import("..").BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
133
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
134
134
|
waitForSocketOpen: () => Promise<void>;
|
|
135
135
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
136
136
|
sendNode: (frame: import("..").BinaryNode) => Promise<void>;
|
|
@@ -141,6 +141,6 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
141
141
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
142
142
|
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
143
143
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
144
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
144
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
145
145
|
};
|
|
146
146
|
export default makeWASocket;
|
|
@@ -9,7 +9,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
9
9
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
10
10
|
fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
|
|
11
11
|
requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
|
|
12
|
-
getPrivacyTokens: (jids: string[]) => Promise<
|
|
12
|
+
getPrivacyTokens: (jids: string[]) => Promise<any>;
|
|
13
13
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
14
14
|
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
15
15
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
@@ -49,7 +49,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
49
49
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
50
50
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
51
51
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
52
|
-
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<
|
|
52
|
+
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
|
|
53
53
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
54
54
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
55
55
|
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
@@ -119,8 +119,8 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
119
119
|
signalRepository: import("../Types").SignalRepository;
|
|
120
120
|
user: import("../Types").Contact | undefined;
|
|
121
121
|
generateMessageTag: () => string;
|
|
122
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
123
|
-
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
|
122
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
123
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
124
124
|
waitForSocketOpen: () => Promise<void>;
|
|
125
125
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
126
126
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
@@ -131,5 +131,5 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
131
131
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
132
132
|
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
133
133
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
134
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
134
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
135
135
|
};
|
|
@@ -35,6 +35,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
35
35
|
});
|
|
36
36
|
let sendActiveReceipts = false;
|
|
37
37
|
const sendMessageAck = async ({ tag, attrs, content }, errorCode) => {
|
|
38
|
+
var _a, _b, _c, _d, _e;
|
|
38
39
|
const stanza = {
|
|
39
40
|
tag: 'ack',
|
|
40
41
|
attrs: {
|
|
@@ -58,14 +59,27 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
58
59
|
if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
|
|
59
60
|
stanza.attrs.from = authState.creds.me.id;
|
|
60
61
|
}
|
|
61
|
-
if (tag === 'receipt') {
|
|
62
|
+
if (tag === 'receipt' && ((_a = attrs.from) === null || _a === void 0 ? void 0 : _a.includes('broadcast'))) {
|
|
62
63
|
ev.emit('broadcast-receipt.update', {
|
|
63
64
|
id: attrs.id,
|
|
64
65
|
participant: attrs.participant,
|
|
65
66
|
timestamp: Number(attrs.t),
|
|
66
67
|
broadcast: attrs.from,
|
|
67
|
-
type: attrs.type
|
|
68
|
+
type: attrs.type === 'read' ? 'read' : 'delivered'
|
|
68
69
|
});
|
|
70
|
+
if (content) {
|
|
71
|
+
for (const child of content) {
|
|
72
|
+
for (const c of child === null || child === void 0 ? void 0 : child.content) {
|
|
73
|
+
ev.emit('broadcast-receipt.update', {
|
|
74
|
+
id: (_b = child === null || child === void 0 ? void 0 : child.attrs) === null || _b === void 0 ? void 0 : _b.key,
|
|
75
|
+
participant: (_c = c === null || c === void 0 ? void 0 : c.attrs) === null || _c === void 0 ? void 0 : _c.jid,
|
|
76
|
+
timestamp: Number((_d = c === null || c === void 0 ? void 0 : c.attrs) === null || _d === void 0 ? void 0 : _d.t),
|
|
77
|
+
broadcast: attrs.from,
|
|
78
|
+
type: ((_e = c === null || c === void 0 ? void 0 : c.attrs) === null || _e === void 0 ? void 0 : _e.type) === 'read' ? 'read' : 'delivered'
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
69
83
|
}
|
|
70
84
|
logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
|
|
71
85
|
await sendNode(stanza);
|
|
@@ -498,7 +512,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
498
512
|
const isLid = attrs.from.includes('lid');
|
|
499
513
|
const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(attrs.participant || attrs.from, isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
|
|
500
514
|
const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
|
|
501
|
-
const fromMe = !attrs.recipient || (attrs.type === 'retry'
|
|
515
|
+
const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender')
|
|
516
|
+
&& isNodeFromMe);
|
|
502
517
|
const key = {
|
|
503
518
|
remoteJid,
|
|
504
519
|
id: '',
|
|
@@ -4,7 +4,7 @@ import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptio
|
|
|
4
4
|
import { BinaryNode, JidWithDevice } from '../WABinary';
|
|
5
5
|
import { USyncQuery } from '../WAUSync';
|
|
6
6
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
7
|
-
getPrivacyTokens: (jids: string[]) => Promise<
|
|
7
|
+
getPrivacyTokens: (jids: string[]) => Promise<any>;
|
|
8
8
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
9
9
|
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
10
10
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
@@ -44,7 +44,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
44
44
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
45
45
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
46
46
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
47
|
-
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<
|
|
47
|
+
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
|
|
48
48
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
49
49
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
50
50
|
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
@@ -114,8 +114,8 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
114
114
|
signalRepository: import("../Types").SignalRepository;
|
|
115
115
|
user: import("../Types").Contact | undefined;
|
|
116
116
|
generateMessageTag: () => string;
|
|
117
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
118
|
-
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
|
117
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
118
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
119
119
|
waitForSocketOpen: () => Promise<void>;
|
|
120
120
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
121
121
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
@@ -126,5 +126,5 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
126
126
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
127
127
|
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
128
128
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
129
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
129
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
130
130
|
};
|
package/lib/Socket/socket.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
|
25
25
|
signalRepository: import("../Types").SignalRepository;
|
|
26
26
|
readonly user: import("../Types").Contact | undefined;
|
|
27
27
|
generateMessageTag: () => string;
|
|
28
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
29
|
-
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
|
28
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
29
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
30
30
|
waitForSocketOpen: () => Promise<void>;
|
|
31
31
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
32
32
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
@@ -38,5 +38,5 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
|
38
38
|
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
39
39
|
/** Waits for the connection to WA to reach a state */
|
|
40
40
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
41
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
41
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
42
42
|
};
|
package/lib/Socket/socket.js
CHANGED
|
@@ -117,7 +117,7 @@ const makeSocket = (config) => {
|
|
|
117
117
|
let onRecv;
|
|
118
118
|
let onErr;
|
|
119
119
|
try {
|
|
120
|
-
|
|
120
|
+
const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
121
121
|
onRecv = resolve;
|
|
122
122
|
onErr = err => {
|
|
123
123
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
@@ -126,6 +126,7 @@ const makeSocket = (config) => {
|
|
|
126
126
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
127
127
|
ws.off('error', onErr);
|
|
128
128
|
});
|
|
129
|
+
return result;
|
|
129
130
|
}
|
|
130
131
|
finally {
|
|
131
132
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
@@ -139,9 +140,10 @@ const makeSocket = (config) => {
|
|
|
139
140
|
node.attrs.id = generateMessageTag();
|
|
140
141
|
}
|
|
141
142
|
const msgId = node.attrs.id;
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
const [result] = await Promise.all([
|
|
144
|
+
waitForMessage(msgId, timeoutMs),
|
|
145
|
+
sendNode(node)
|
|
146
|
+
]);
|
|
145
147
|
if ('tag' in result) {
|
|
146
148
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
147
149
|
}
|
package/lib/Socket/usync.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
|
20
20
|
signalRepository: import("../Types").SignalRepository;
|
|
21
21
|
user: import("../Types").Contact | undefined;
|
|
22
22
|
generateMessageTag: () => string;
|
|
23
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
24
|
-
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
|
23
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
24
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
25
25
|
waitForSocketOpen: () => Promise<void>;
|
|
26
26
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
27
27
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
@@ -32,5 +32,5 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
|
32
32
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
33
33
|
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
34
34
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
35
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
35
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
36
36
|
};
|
package/lib/Types/Events.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type RequestJoinMethod = 'invite_link' | 'linked_group_join' | 'non_admin
|
|
|
10
10
|
export interface GroupMetadata {
|
|
11
11
|
id: string;
|
|
12
12
|
/** group uses 'lid' or 'pn' to send messages */
|
|
13
|
-
addressingMode:
|
|
13
|
+
addressingMode: "pn" | "lid";
|
|
14
14
|
owner: string | undefined;
|
|
15
15
|
subject: string;
|
|
16
16
|
/** group subject owner */
|
package/lib/Types/Message.d.ts
CHANGED
|
@@ -215,7 +215,7 @@ export type MiscMessageGenerationOptions = MinimalRelayOptions & {
|
|
|
215
215
|
export type MessageGenerationOptionsFromContent = MiscMessageGenerationOptions & {
|
|
216
216
|
userJid: string;
|
|
217
217
|
};
|
|
218
|
-
export type WAMediaUploadFunction = (
|
|
218
|
+
export type WAMediaUploadFunction = (encFilePath: string, opts: {
|
|
219
219
|
fileEncSha256B64: string;
|
|
220
220
|
mediaType: MediaType;
|
|
221
221
|
timeoutMs?: number;
|
package/lib/Utils/business.js
CHANGED
|
@@ -4,7 +4,11 @@ exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductN
|
|
|
4
4
|
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
5
5
|
const boom_1 = require("@hapi/boom");
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const os_1 = require("os");
|
|
9
|
+
const path_1 = require("path");
|
|
7
10
|
const WABinary_1 = require("../WABinary");
|
|
11
|
+
const generics_1 = require("./generics");
|
|
8
12
|
const messages_media_1 = require("./messages-media");
|
|
9
13
|
const parseCatalogNode = (node) => {
|
|
10
14
|
const catalogNode = (0, WABinary_1.getBinaryNodeChild)(node, 'product_catalog');
|
|
@@ -202,17 +206,21 @@ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30
|
|
|
202
206
|
}
|
|
203
207
|
const { stream } = await (0, messages_media_1.getStream)(img);
|
|
204
208
|
const hasher = (0, crypto_1.createHash)('sha256');
|
|
205
|
-
const
|
|
209
|
+
const filePath = (0, path_1.join)((0, os_1.tmpdir)(), 'img' + (0, generics_1.generateMessageIDV2)());
|
|
210
|
+
const encFileWriteStream = (0, fs_1.createWriteStream)(filePath);
|
|
206
211
|
for await (const block of stream) {
|
|
207
212
|
hasher.update(block);
|
|
208
|
-
|
|
213
|
+
encFileWriteStream.write(block);
|
|
209
214
|
}
|
|
210
215
|
const sha = hasher.digest('base64');
|
|
211
|
-
const { directPath } = await waUploadToServer(
|
|
216
|
+
const { directPath } = await waUploadToServer(filePath, {
|
|
212
217
|
mediaType: 'product-catalog-image',
|
|
213
218
|
fileEncSha256B64: sha,
|
|
214
219
|
timeoutMs
|
|
215
220
|
});
|
|
221
|
+
await fs_1.promises
|
|
222
|
+
.unlink(filePath)
|
|
223
|
+
.catch(err => console.log('Error deleting temp file ', err));
|
|
216
224
|
return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
|
|
217
225
|
}));
|
|
218
226
|
return results;
|
package/lib/Utils/generics.js
CHANGED
|
@@ -35,7 +35,7 @@ exports.Browsers = {
|
|
|
35
35
|
};
|
|
36
36
|
const getPlatformId = (browser) => {
|
|
37
37
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
38
|
-
return platformType ? platformType.toString()
|
|
38
|
+
return platformType ? platformType.toString() : '1'; //chrome
|
|
39
39
|
};
|
|
40
40
|
exports.getPlatformId = getPlatformId;
|
|
41
41
|
exports.BufferJSON = {
|
|
@@ -63,13 +63,12 @@ type EncryptedStreamOptions = {
|
|
|
63
63
|
};
|
|
64
64
|
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
|
65
65
|
mediaKey: Buffer<ArrayBufferLike>;
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
originalFilePath: string | undefined;
|
|
67
|
+
encFilePath: string;
|
|
68
68
|
mac: Buffer<ArrayBuffer>;
|
|
69
69
|
fileEncSha256: Buffer<ArrayBufferLike>;
|
|
70
70
|
fileSha256: Buffer<ArrayBufferLike>;
|
|
71
71
|
fileLength: number;
|
|
72
|
-
didSaveToTmpPath: boolean;
|
|
73
72
|
}>;
|
|
74
73
|
export type MediaDownloadOptions = {
|
|
75
74
|
startByte?: number;
|
|
@@ -336,7 +336,7 @@ async function generateThumbnail(file, mediaType, options) {
|
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
else if (mediaType === 'video') {
|
|
339
|
-
const imgFilename = (0, path_1.join)(getTmpFilesDirectory(), (0, generics_1.
|
|
339
|
+
const imgFilename = (0, path_1.join)(getTmpFilesDirectory(), (0, generics_1.generateMessageIDV2)() + '.jpg');
|
|
340
340
|
try {
|
|
341
341
|
await extractVideoThumb(file, imgFilename, '00:00:00', { width: 32, height: 32 });
|
|
342
342
|
const buff = await fs_1.promises.readFile(imgFilename);
|
|
@@ -358,27 +358,29 @@ const getHttpStream = async (url, options = {}) => {
|
|
|
358
358
|
};
|
|
359
359
|
exports.getHttpStream = getHttpStream;
|
|
360
360
|
const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
361
|
+
var _a, _b;
|
|
361
362
|
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
362
363
|
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
363
364
|
const mediaKey = Crypto.randomBytes(32);
|
|
364
365
|
const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType);
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
let
|
|
368
|
-
let
|
|
369
|
-
if (
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
else if (saveOriginalFileIfRequired) {
|
|
373
|
-
bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
|
|
374
|
-
writeStream = (0, fs_1.createWriteStream)(bodyPath);
|
|
375
|
-
didSaveToTmpPath = true;
|
|
366
|
+
const encFilePath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageIDV2)() + '-enc');
|
|
367
|
+
const encFileWriteStream = (0, fs_1.createWriteStream)(encFilePath);
|
|
368
|
+
let originalFileStream;
|
|
369
|
+
let originalFilePath;
|
|
370
|
+
if (saveOriginalFileIfRequired) {
|
|
371
|
+
originalFilePath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageIDV2)() + '-original');
|
|
372
|
+
originalFileStream = (0, fs_1.createWriteStream)(originalFilePath);
|
|
376
373
|
}
|
|
377
374
|
let fileLength = 0;
|
|
378
375
|
const aes = Crypto.createCipheriv('aes-256-cbc', cipherKey, iv);
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
376
|
+
const hmac = Crypto.createHmac('sha256', macKey).update(iv);
|
|
377
|
+
const sha256Plain = Crypto.createHash('sha256');
|
|
378
|
+
const sha256Enc = Crypto.createHash('sha256');
|
|
379
|
+
const onChunk = (buff) => {
|
|
380
|
+
sha256Enc.update(buff);
|
|
381
|
+
hmac.update(buff);
|
|
382
|
+
encFileWriteStream.write(buff);
|
|
383
|
+
};
|
|
382
384
|
try {
|
|
383
385
|
for await (const data of stream) {
|
|
384
386
|
fileLength += data.length;
|
|
@@ -389,57 +391,54 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
389
391
|
data: { media, type }
|
|
390
392
|
});
|
|
391
393
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
394
|
+
if (originalFileStream) {
|
|
395
|
+
if (!originalFileStream.write(data)) {
|
|
396
|
+
await (0, events_1.once)(originalFileStream, 'drain');
|
|
397
|
+
}
|
|
395
398
|
}
|
|
399
|
+
sha256Plain.update(data);
|
|
396
400
|
onChunk(aes.update(data));
|
|
397
401
|
}
|
|
398
402
|
onChunk(aes.final());
|
|
399
403
|
const mac = hmac.digest().slice(0, 10);
|
|
400
|
-
sha256Enc
|
|
404
|
+
sha256Enc.update(mac);
|
|
401
405
|
const fileSha256 = sha256Plain.digest();
|
|
402
406
|
const fileEncSha256 = sha256Enc.digest();
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
407
|
+
encFileWriteStream.write(mac);
|
|
408
|
+
encFileWriteStream.end();
|
|
409
|
+
(_a = originalFileStream === null || originalFileStream === void 0 ? void 0 : originalFileStream.end) === null || _a === void 0 ? void 0 : _a.call(originalFileStream);
|
|
406
410
|
stream.destroy();
|
|
407
411
|
logger === null || logger === void 0 ? void 0 : logger.debug('encrypted data successfully');
|
|
408
412
|
return {
|
|
409
413
|
mediaKey,
|
|
410
|
-
|
|
411
|
-
|
|
414
|
+
originalFilePath,
|
|
415
|
+
encFilePath,
|
|
412
416
|
mac,
|
|
413
417
|
fileEncSha256,
|
|
414
418
|
fileSha256,
|
|
415
|
-
fileLength
|
|
416
|
-
didSaveToTmpPath
|
|
419
|
+
fileLength
|
|
417
420
|
};
|
|
418
421
|
}
|
|
419
422
|
catch (error) {
|
|
420
423
|
// destroy all streams with error
|
|
421
|
-
|
|
422
|
-
|
|
424
|
+
encFileWriteStream.destroy();
|
|
425
|
+
(_b = originalFileStream === null || originalFileStream === void 0 ? void 0 : originalFileStream.destroy) === null || _b === void 0 ? void 0 : _b.call(originalFileStream);
|
|
423
426
|
aes.destroy();
|
|
424
427
|
hmac.destroy();
|
|
425
428
|
sha256Plain.destroy();
|
|
426
429
|
sha256Enc.destroy();
|
|
427
430
|
stream.destroy();
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
catch (err) {
|
|
433
|
-
logger === null || logger === void 0 ? void 0 : logger.error({ err }, 'failed to save to tmp path');
|
|
431
|
+
try {
|
|
432
|
+
await fs_1.promises.unlink(encFilePath);
|
|
433
|
+
if (originalFilePath) {
|
|
434
|
+
await fs_1.promises.unlink(originalFilePath);
|
|
434
435
|
}
|
|
435
436
|
}
|
|
437
|
+
catch (err) {
|
|
438
|
+
logger === null || logger === void 0 ? void 0 : logger.error({ err }, 'failed deleting tmp files');
|
|
439
|
+
}
|
|
436
440
|
throw error;
|
|
437
441
|
}
|
|
438
|
-
function onChunk(buff) {
|
|
439
|
-
sha256Enc = sha256Enc.update(buff);
|
|
440
|
-
hmac = hmac.update(buff);
|
|
441
|
-
encWriteStream.push(buff);
|
|
442
|
-
}
|
|
443
442
|
};
|
|
444
443
|
exports.encryptedStream = encryptedStream;
|
|
445
444
|
const DEF_HOST = 'mmg.whatsapp.net';
|
|
@@ -559,7 +558,7 @@ function extensionForMediaMessage(message) {
|
|
|
559
558
|
return extension;
|
|
560
559
|
}
|
|
561
560
|
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
562
|
-
return async (
|
|
561
|
+
return async (filePath, { mediaType, fileEncSha256B64, timeoutMs }) => {
|
|
563
562
|
var _a, _b;
|
|
564
563
|
// send a query JSON to obtain the url & auth token to upload our media
|
|
565
564
|
let uploadInfo = await refreshMediaConn(false);
|
|
@@ -573,8 +572,9 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
573
572
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
574
573
|
let result;
|
|
575
574
|
try {
|
|
576
|
-
const body = await axios_1.default.post(url,
|
|
575
|
+
const body = await axios_1.default.post(url, (0, fs_1.createReadStream)(filePath), {
|
|
577
576
|
...options,
|
|
577
|
+
maxRedirects: 0,
|
|
578
578
|
headers: {
|
|
579
579
|
...options.headers || {},
|
|
580
580
|
'Content-Type': 'application/octet-stream',
|
package/lib/Utils/messages.js
CHANGED
|
@@ -111,7 +111,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
111
111
|
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
|
|
112
112
|
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
113
113
|
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
114
|
-
const { mediaKey,
|
|
114
|
+
const { mediaKey, encFilePath, originalFilePath, fileEncSha256, fileSha256, fileLength } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
115
115
|
logger,
|
|
116
116
|
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
117
117
|
opts: options.options
|
|
@@ -120,14 +120,14 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
120
120
|
const fileEncSha256B64 = fileEncSha256.toString('base64');
|
|
121
121
|
const [{ mediaUrl, directPath }] = await Promise.all([
|
|
122
122
|
(async () => {
|
|
123
|
-
const result = await options.upload(
|
|
123
|
+
const result = await options.upload(encFilePath, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
|
|
124
124
|
logger === null || logger === void 0 ? void 0 : logger.debug({ mediaType, cacheableKey }, 'uploaded media');
|
|
125
125
|
return result;
|
|
126
126
|
})(),
|
|
127
127
|
(async () => {
|
|
128
128
|
try {
|
|
129
129
|
if (requiresThumbnailComputation) {
|
|
130
|
-
const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(
|
|
130
|
+
const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(originalFilePath, mediaType, options);
|
|
131
131
|
uploadData.jpegThumbnail = thumbnail;
|
|
132
132
|
if (!uploadData.width && originalImageDimensions) {
|
|
133
133
|
uploadData.width = originalImageDimensions.width;
|
|
@@ -137,11 +137,11 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
137
137
|
logger === null || logger === void 0 ? void 0 : logger.debug('generated thumbnail');
|
|
138
138
|
}
|
|
139
139
|
if (requiresDurationComputation) {
|
|
140
|
-
uploadData.seconds = await (0, messages_media_1.getAudioDuration)(
|
|
140
|
+
uploadData.seconds = await (0, messages_media_1.getAudioDuration)(originalFilePath);
|
|
141
141
|
logger === null || logger === void 0 ? void 0 : logger.debug('computed audio duration');
|
|
142
142
|
}
|
|
143
143
|
if (requiresWaveformProcessing) {
|
|
144
|
-
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(
|
|
144
|
+
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(originalFilePath, logger);
|
|
145
145
|
logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
|
|
146
146
|
}
|
|
147
147
|
if (requiresAudioBackground) {
|
|
@@ -155,17 +155,15 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
155
155
|
})(),
|
|
156
156
|
])
|
|
157
157
|
.finally(async () => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
await fs_1.promises.access(bodyPath);
|
|
163
|
-
await fs_1.promises.unlink(bodyPath);
|
|
164
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp file');
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
|
|
158
|
+
try {
|
|
159
|
+
await fs_1.promises.unlink(encFilePath);
|
|
160
|
+
if (originalFilePath) {
|
|
161
|
+
await fs_1.promises.unlink(originalFilePath);
|
|
168
162
|
}
|
|
163
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp files');
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
|
|
169
167
|
}
|
|
170
168
|
});
|
|
171
169
|
const obj = Types_1.WAProto.Message.fromObject({
|
|
@@ -493,7 +491,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
493
491
|
key: {
|
|
494
492
|
remoteJid: jid,
|
|
495
493
|
fromMe: true,
|
|
496
|
-
id: (options === null || options === void 0 ? void 0 : options.messageId) || (0, generics_1.
|
|
494
|
+
id: (options === null || options === void 0 ? void 0 : options.messageId) || (0, generics_1.generateMessageIDV2)(),
|
|
497
495
|
},
|
|
498
496
|
message: message,
|
|
499
497
|
messageTimestamp: timestamp,
|