@d0v3riz/baileys 6.7.20 → 6.7.22
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 +30 -2
- package/lib/Socket/chats.d.ts +8 -3
- package/lib/Socket/chats.js +20 -2
- package/lib/Socket/groups.d.ts +8 -2
- package/lib/Socket/groups.js +1 -0
- package/lib/Socket/index.d.ts +30 -2
- package/lib/Socket/messages-recv.d.ts +30 -2
- package/lib/Socket/messages-recv.js +140 -0
- package/lib/Socket/messages-send.d.ts +30 -2
- package/lib/Socket/messages-send.js +28 -2
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +46 -0
- package/lib/Socket/newsletter.d.ts +141 -0
- package/lib/Socket/newsletter.js +183 -0
- package/lib/Socket/socket.js +0 -1
- package/lib/Types/Chat.d.ts +3 -0
- package/lib/Types/Events.d.ts +26 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/Message.d.ts +6 -1
- package/lib/Types/Newsletter.d.ts +134 -0
- package/lib/Types/Newsletter.js +33 -0
- package/lib/Types/index.d.ts +1 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/auth-utils.js +1 -1
- package/lib/Utils/chat-utils.js +14 -1
- package/lib/Utils/decode-wa-message.d.ts +3 -4
- package/lib/Utils/decode-wa-message.js +5 -1
- package/lib/Utils/generics.d.ts +1 -0
- package/lib/Utils/generics.js +4 -0
- package/lib/Utils/history.js +0 -6
- package/lib/Utils/messages-media.d.ts +11 -3
- package/lib/Utils/messages-media.js +74 -35
- package/lib/Utils/messages.d.ts +2 -2
- package/lib/Utils/messages.js +39 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/package.json +5 -5
package/lib/Socket/business.d.ts
CHANGED
|
@@ -39,6 +39,29 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
39
39
|
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
|
|
40
40
|
updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
|
|
41
41
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
|
|
42
|
+
newsletterCreate: (name: string, description?: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
43
|
+
newsletterUpdate: (jid: string, updates: import("../Types").NewsletterUpdate) => Promise<unknown>;
|
|
44
|
+
newsletterSubscribers: (jid: string) => Promise<{
|
|
45
|
+
subscribers: number;
|
|
46
|
+
}>;
|
|
47
|
+
newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<import("../Types").NewsletterMetadata | null>;
|
|
48
|
+
newsletterFollow: (jid: string) => Promise<unknown>;
|
|
49
|
+
newsletterUnfollow: (jid: string) => Promise<unknown>;
|
|
50
|
+
newsletterMute: (jid: string) => Promise<unknown>;
|
|
51
|
+
newsletterUnmute: (jid: string) => Promise<unknown>;
|
|
52
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<unknown>;
|
|
53
|
+
newsletterUpdateDescription: (jid: string, description: string) => Promise<unknown>;
|
|
54
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<unknown>;
|
|
55
|
+
newsletterRemovePicture: (jid: string) => Promise<unknown>;
|
|
56
|
+
newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
|
|
57
|
+
newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
|
|
58
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
59
|
+
duration: string;
|
|
60
|
+
} | null>;
|
|
61
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
62
|
+
newsletterChangeOwner: (jid: string, newOwnerJid: string) => Promise<void>;
|
|
63
|
+
newsletterDemote: (jid: string, userJid: string) => Promise<void>;
|
|
64
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
42
65
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
43
66
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
44
67
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -73,7 +96,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
73
96
|
processingMutex: {
|
|
74
97
|
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
75
98
|
};
|
|
76
|
-
upsertMessage: (msg: import("../Types").
|
|
99
|
+
upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
77
100
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
78
101
|
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
|
79
102
|
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
@@ -86,7 +109,10 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
86
109
|
fetchBlocklist: () => Promise<string[]>;
|
|
87
110
|
fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
88
111
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
89
|
-
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload
|
|
112
|
+
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
|
|
113
|
+
width: number;
|
|
114
|
+
height: number;
|
|
115
|
+
}) => Promise<void>;
|
|
90
116
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
91
117
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
92
118
|
updateProfileName: (name: string) => Promise<void>;
|
|
@@ -104,6 +130,8 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
104
130
|
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
105
131
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
106
132
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
133
|
+
addOrEditContact: (jid: string, contact: import("../Types").WAProto.SyncActionValue.IContactAction) => Promise<void>;
|
|
134
|
+
removeContact: (jid: string) => Promise<void>;
|
|
107
135
|
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
108
136
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
109
137
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
package/lib/Socket/chats.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
|
-
import { BotListInfo, ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
|
|
3
|
+
import { BotListInfo, ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAMessage, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
|
|
4
4
|
import { LabelActionBody } from '../Types/Label';
|
|
5
5
|
import { BinaryNode } from '../WABinary';
|
|
6
6
|
import { USyncQuery } from '../WAUSync';
|
|
@@ -12,7 +12,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
12
12
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
13
13
|
[_: string]: string;
|
|
14
14
|
}>;
|
|
15
|
-
upsertMessage: (msg:
|
|
15
|
+
upsertMessage: (msg: WAMessage, type: MessageUpsertType) => Promise<void>;
|
|
16
16
|
appPatch: (patchCreate: WAPatchCreate) => Promise<void>;
|
|
17
17
|
sendPresenceUpdate: (type: WAPresence, toJid?: string) => Promise<void>;
|
|
18
18
|
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
@@ -25,7 +25,10 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
25
25
|
fetchBlocklist: () => Promise<string[]>;
|
|
26
26
|
fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
|
27
27
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
|
28
|
-
updateProfilePicture: (jid: string, content: WAMediaUpload
|
|
28
|
+
updateProfilePicture: (jid: string, content: WAMediaUpload, dimensions?: {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
}) => Promise<void>;
|
|
29
32
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
30
33
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
31
34
|
updateProfileName: (name: string) => Promise<void>;
|
|
@@ -43,6 +46,8 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
43
46
|
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
44
47
|
chatModify: (mod: ChatModification, jid: string) => Promise<void>;
|
|
45
48
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
49
|
+
addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
|
|
50
|
+
removeContact: (jid: string) => Promise<void>;
|
|
46
51
|
addLabel: (jid: string, labels: LabelActionBody) => Promise<void>;
|
|
47
52
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
48
53
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
package/lib/Socket/chats.js
CHANGED
|
@@ -181,7 +181,7 @@ const makeChatsSocket = (config) => {
|
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
/** update the profile picture for yourself or a group */
|
|
184
|
-
const updateProfilePicture = async (jid, content) => {
|
|
184
|
+
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
185
185
|
let targetJid;
|
|
186
186
|
if (!jid) {
|
|
187
187
|
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
@@ -189,7 +189,7 @@ const makeChatsSocket = (config) => {
|
|
|
189
189
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
190
190
|
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
|
191
191
|
}
|
|
192
|
-
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
192
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content, dimensions);
|
|
193
193
|
await query({
|
|
194
194
|
tag: 'iq',
|
|
195
195
|
attrs: {
|
|
@@ -681,6 +681,22 @@ const makeChatsSocket = (config) => {
|
|
|
681
681
|
}
|
|
682
682
|
}, jid);
|
|
683
683
|
};
|
|
684
|
+
/**
|
|
685
|
+
* Add or Edit Contact
|
|
686
|
+
*/
|
|
687
|
+
const addOrEditContact = (jid, contact) => {
|
|
688
|
+
return chatModify({
|
|
689
|
+
contact
|
|
690
|
+
}, jid);
|
|
691
|
+
};
|
|
692
|
+
/**
|
|
693
|
+
* Remove Contact
|
|
694
|
+
*/
|
|
695
|
+
const removeContact = (jid) => {
|
|
696
|
+
return chatModify({
|
|
697
|
+
contact: null
|
|
698
|
+
}, jid);
|
|
699
|
+
};
|
|
684
700
|
/**
|
|
685
701
|
* Adds label
|
|
686
702
|
*/
|
|
@@ -869,6 +885,8 @@ const makeChatsSocket = (config) => {
|
|
|
869
885
|
resyncAppState,
|
|
870
886
|
chatModify,
|
|
871
887
|
cleanDirtyBits,
|
|
888
|
+
addOrEditContact,
|
|
889
|
+
removeContact,
|
|
872
890
|
addLabel,
|
|
873
891
|
addChatLabel,
|
|
874
892
|
removeChatLabel,
|
package/lib/Socket/groups.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
50
50
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
51
51
|
[_: string]: string;
|
|
52
52
|
}>;
|
|
53
|
-
upsertMessage: (msg:
|
|
53
|
+
upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
54
54
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
55
55
|
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
|
56
56
|
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
@@ -63,7 +63,10 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
63
63
|
fetchBlocklist: () => Promise<string[]>;
|
|
64
64
|
fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
65
65
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
66
|
-
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload
|
|
66
|
+
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
}) => Promise<void>;
|
|
67
70
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
68
71
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
69
72
|
updateProfileName: (name: string) => Promise<void>;
|
|
@@ -81,6 +84,8 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
81
84
|
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
82
85
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
83
86
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
87
|
+
addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
|
|
88
|
+
removeContact: (jid: string) => Promise<void>;
|
|
84
89
|
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
85
90
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
86
91
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
@@ -122,3 +127,4 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
122
127
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
123
128
|
};
|
|
124
129
|
export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
|
|
130
|
+
export type GroupsSocket = ReturnType<typeof makeGroupsSocket>;
|
package/lib/Socket/groups.js
CHANGED
|
@@ -303,6 +303,7 @@ const extractGroupMetadata = (result) => {
|
|
|
303
303
|
creation: +group.attrs.creation,
|
|
304
304
|
owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
|
|
305
305
|
ownerJid: group.attrs.creator_pn ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
|
|
306
|
+
owner_country_code: group.attrs.creator_country_code,
|
|
306
307
|
desc,
|
|
307
308
|
descId,
|
|
308
309
|
descOwner,
|
package/lib/Socket/index.d.ts
CHANGED
|
@@ -38,6 +38,29 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
38
38
|
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("..").JidWithDevice[]>;
|
|
39
39
|
updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
|
|
40
40
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
|
|
41
|
+
newsletterCreate: (name: string, description?: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
42
|
+
newsletterUpdate: (jid: string, updates: import("../Types").NewsletterUpdate) => Promise<unknown>;
|
|
43
|
+
newsletterSubscribers: (jid: string) => Promise<{
|
|
44
|
+
subscribers: number;
|
|
45
|
+
}>;
|
|
46
|
+
newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<import("../Types").NewsletterMetadata | null>;
|
|
47
|
+
newsletterFollow: (jid: string) => Promise<unknown>;
|
|
48
|
+
newsletterUnfollow: (jid: string) => Promise<unknown>;
|
|
49
|
+
newsletterMute: (jid: string) => Promise<unknown>;
|
|
50
|
+
newsletterUnmute: (jid: string) => Promise<unknown>;
|
|
51
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<unknown>;
|
|
52
|
+
newsletterUpdateDescription: (jid: string, description: string) => Promise<unknown>;
|
|
53
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<unknown>;
|
|
54
|
+
newsletterRemovePicture: (jid: string) => Promise<unknown>;
|
|
55
|
+
newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
|
|
56
|
+
newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
|
|
57
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
58
|
+
duration: string;
|
|
59
|
+
} | null>;
|
|
60
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
61
|
+
newsletterChangeOwner: (jid: string, newOwnerJid: string) => Promise<void>;
|
|
62
|
+
newsletterDemote: (jid: string, userJid: string) => Promise<void>;
|
|
63
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
41
64
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
42
65
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
43
66
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -72,7 +95,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
72
95
|
processingMutex: {
|
|
73
96
|
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
74
97
|
};
|
|
75
|
-
upsertMessage: (msg: import("../Types").
|
|
98
|
+
upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
76
99
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
77
100
|
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
|
78
101
|
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
@@ -85,7 +108,10 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
85
108
|
fetchBlocklist: () => Promise<string[]>;
|
|
86
109
|
fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
87
110
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
88
|
-
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload
|
|
111
|
+
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
|
|
112
|
+
width: number;
|
|
113
|
+
height: number;
|
|
114
|
+
}) => Promise<void>;
|
|
89
115
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
90
116
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
91
117
|
updateProfileName: (name: string) => Promise<void>;
|
|
@@ -103,6 +129,8 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
103
129
|
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
104
130
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
105
131
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
132
|
+
addOrEditContact: (jid: string, contact: import("../Types").WAProto.SyncActionValue.IContactAction) => Promise<void>;
|
|
133
|
+
removeContact: (jid: string) => Promise<void>;
|
|
106
134
|
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
107
135
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
108
136
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
@@ -28,6 +28,29 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
28
28
|
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
|
|
29
29
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
|
30
30
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
|
31
|
+
newsletterCreate: (name: string, description?: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
32
|
+
newsletterUpdate: (jid: string, updates: import("../Types").NewsletterUpdate) => Promise<unknown>;
|
|
33
|
+
newsletterSubscribers: (jid: string) => Promise<{
|
|
34
|
+
subscribers: number;
|
|
35
|
+
}>;
|
|
36
|
+
newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<import("../Types").NewsletterMetadata | null>;
|
|
37
|
+
newsletterFollow: (jid: string) => Promise<unknown>;
|
|
38
|
+
newsletterUnfollow: (jid: string) => Promise<unknown>;
|
|
39
|
+
newsletterMute: (jid: string) => Promise<unknown>;
|
|
40
|
+
newsletterUnmute: (jid: string) => Promise<unknown>;
|
|
41
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<unknown>;
|
|
42
|
+
newsletterUpdateDescription: (jid: string, description: string) => Promise<unknown>;
|
|
43
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<unknown>;
|
|
44
|
+
newsletterRemovePicture: (jid: string) => Promise<unknown>;
|
|
45
|
+
newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
|
|
46
|
+
newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
|
|
47
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
48
|
+
duration: string;
|
|
49
|
+
} | null>;
|
|
50
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
51
|
+
newsletterChangeOwner: (jid: string, newOwnerJid: string) => Promise<void>;
|
|
52
|
+
newsletterDemote: (jid: string, userJid: string) => Promise<void>;
|
|
53
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
31
54
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
32
55
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
33
56
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -62,7 +85,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
62
85
|
processingMutex: {
|
|
63
86
|
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
64
87
|
};
|
|
65
|
-
upsertMessage: (msg:
|
|
88
|
+
upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
66
89
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
67
90
|
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
|
68
91
|
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
@@ -75,7 +98,10 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
75
98
|
fetchBlocklist: () => Promise<string[]>;
|
|
76
99
|
fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
77
100
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
78
|
-
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload
|
|
101
|
+
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
|
|
102
|
+
width: number;
|
|
103
|
+
height: number;
|
|
104
|
+
}) => Promise<void>;
|
|
79
105
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
80
106
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
81
107
|
updateProfileName: (name: string) => Promise<void>;
|
|
@@ -93,6 +119,8 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
93
119
|
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
94
120
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
95
121
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
122
|
+
addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
|
|
123
|
+
removeContact: (jid: string) => Promise<void>;
|
|
96
124
|
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
97
125
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
98
126
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
@@ -304,6 +304,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
304
304
|
logger.debug({ jid }, 'got privacy token update');
|
|
305
305
|
}
|
|
306
306
|
break;
|
|
307
|
+
case 'newsletter':
|
|
308
|
+
await handleNewsletterNotification(node);
|
|
309
|
+
break;
|
|
310
|
+
case 'mex':
|
|
311
|
+
await handleMexNewsletterNotification(node);
|
|
312
|
+
break;
|
|
307
313
|
case 'w:gp2':
|
|
308
314
|
handleGroupNotification(node.attrs.participant, child, result);
|
|
309
315
|
break;
|
|
@@ -875,6 +881,140 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
875
881
|
processNodeWithBuffer(node, identifier, exec);
|
|
876
882
|
}
|
|
877
883
|
};
|
|
884
|
+
// Handles newsletter notifications
|
|
885
|
+
async function handleNewsletterNotification(node) {
|
|
886
|
+
var _a;
|
|
887
|
+
const from = node.attrs.from;
|
|
888
|
+
const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
889
|
+
const author = node.attrs.participant;
|
|
890
|
+
logger.info({ from, child }, 'got newsletter notification');
|
|
891
|
+
switch (child.tag) {
|
|
892
|
+
case 'reaction':
|
|
893
|
+
const reactionUpdate = {
|
|
894
|
+
id: from,
|
|
895
|
+
server_id: child.attrs.message_id,
|
|
896
|
+
reaction: {
|
|
897
|
+
code: (0, WABinary_1.getBinaryNodeChildString)(child, 'reaction'),
|
|
898
|
+
count: 1
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
ev.emit('newsletter.reaction', reactionUpdate);
|
|
902
|
+
break;
|
|
903
|
+
case 'view':
|
|
904
|
+
const viewUpdate = {
|
|
905
|
+
id: from,
|
|
906
|
+
server_id: child.attrs.message_id,
|
|
907
|
+
count: parseInt(((_a = child.content) === null || _a === void 0 ? void 0 : _a.toString()) || '0', 10)
|
|
908
|
+
};
|
|
909
|
+
ev.emit('newsletter.view', viewUpdate);
|
|
910
|
+
break;
|
|
911
|
+
case 'participant':
|
|
912
|
+
const participantUpdate = {
|
|
913
|
+
id: from,
|
|
914
|
+
author,
|
|
915
|
+
user: child.attrs.jid,
|
|
916
|
+
action: child.attrs.action,
|
|
917
|
+
new_role: child.attrs.role
|
|
918
|
+
};
|
|
919
|
+
ev.emit('newsletter-participants.update', participantUpdate);
|
|
920
|
+
break;
|
|
921
|
+
case 'update':
|
|
922
|
+
const settingsNode = (0, WABinary_1.getBinaryNodeChild)(child, 'settings');
|
|
923
|
+
if (settingsNode) {
|
|
924
|
+
const update = {};
|
|
925
|
+
const nameNode = (0, WABinary_1.getBinaryNodeChild)(settingsNode, 'name');
|
|
926
|
+
if (nameNode === null || nameNode === void 0 ? void 0 : nameNode.content)
|
|
927
|
+
update.name = nameNode.content.toString();
|
|
928
|
+
const descriptionNode = (0, WABinary_1.getBinaryNodeChild)(settingsNode, 'description');
|
|
929
|
+
if (descriptionNode === null || descriptionNode === void 0 ? void 0 : descriptionNode.content)
|
|
930
|
+
update.description = descriptionNode.content.toString();
|
|
931
|
+
ev.emit('newsletter-settings.update', {
|
|
932
|
+
id: from,
|
|
933
|
+
update
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
break;
|
|
937
|
+
case 'message':
|
|
938
|
+
const plaintextNode = (0, WABinary_1.getBinaryNodeChild)(child, 'plaintext');
|
|
939
|
+
if (plaintextNode === null || plaintextNode === void 0 ? void 0 : plaintextNode.content) {
|
|
940
|
+
try {
|
|
941
|
+
const contentBuf = typeof plaintextNode.content === 'string'
|
|
942
|
+
? Buffer.from(plaintextNode.content, 'binary')
|
|
943
|
+
: Buffer.from(plaintextNode.content);
|
|
944
|
+
const messageProto = WAProto_1.proto.Message.decode(contentBuf);
|
|
945
|
+
const fullMessage = WAProto_1.proto.WebMessageInfo.fromObject({
|
|
946
|
+
key: {
|
|
947
|
+
remoteJid: from,
|
|
948
|
+
id: child.attrs.message_id || child.attrs.server_id,
|
|
949
|
+
fromMe: false
|
|
950
|
+
},
|
|
951
|
+
message: messageProto,
|
|
952
|
+
messageTimestamp: +child.attrs.t
|
|
953
|
+
});
|
|
954
|
+
await upsertMessage(fullMessage, 'append');
|
|
955
|
+
logger.info('Processed plaintext newsletter message');
|
|
956
|
+
}
|
|
957
|
+
catch (error) {
|
|
958
|
+
logger.error({ error }, 'Failed to decode plaintext newsletter message');
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
break;
|
|
962
|
+
default:
|
|
963
|
+
logger.warn({ node }, 'Unknown newsletter notification');
|
|
964
|
+
break;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
// Handles mex newsletter notifications
|
|
968
|
+
async function handleMexNewsletterNotification(node) {
|
|
969
|
+
const mexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'mex');
|
|
970
|
+
if (!(mexNode === null || mexNode === void 0 ? void 0 : mexNode.content)) {
|
|
971
|
+
logger.warn({ node }, 'Invalid mex newsletter notification');
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
let data;
|
|
975
|
+
try {
|
|
976
|
+
data = JSON.parse(mexNode.content.toString());
|
|
977
|
+
}
|
|
978
|
+
catch (error) {
|
|
979
|
+
logger.error({ err: error, node }, 'Failed to parse mex newsletter notification');
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
const operation = data === null || data === void 0 ? void 0 : data.operation;
|
|
983
|
+
const updates = data === null || data === void 0 ? void 0 : data.updates;
|
|
984
|
+
if (!updates || !operation) {
|
|
985
|
+
logger.warn({ data }, 'Invalid mex newsletter notification content');
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
logger.info({ operation, updates }, 'got mex newsletter notification');
|
|
989
|
+
switch (operation) {
|
|
990
|
+
case 'NotificationNewsletterUpdate':
|
|
991
|
+
for (const update of updates) {
|
|
992
|
+
if (update.jid && update.settings && Object.keys(update.settings).length > 0) {
|
|
993
|
+
ev.emit('newsletter-settings.update', {
|
|
994
|
+
id: update.jid,
|
|
995
|
+
update: update.settings
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
break;
|
|
1000
|
+
case 'NotificationNewsletterAdminPromote':
|
|
1001
|
+
for (const update of updates) {
|
|
1002
|
+
if (update.jid && update.user) {
|
|
1003
|
+
ev.emit('newsletter-participants.update', {
|
|
1004
|
+
id: update.jid,
|
|
1005
|
+
author: node.attrs.from,
|
|
1006
|
+
user: update.user,
|
|
1007
|
+
new_role: 'ADMIN',
|
|
1008
|
+
action: 'promote'
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
break;
|
|
1013
|
+
default:
|
|
1014
|
+
logger.info({ operation, data }, 'Unhandled mex newsletter notification');
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
878
1018
|
// recv a message
|
|
879
1019
|
ws.on('CB:message', (node) => {
|
|
880
1020
|
processNode('message', node, 'processing message', handleMessage);
|
|
@@ -23,6 +23,29 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
23
23
|
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
|
|
24
24
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
|
25
25
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
|
26
|
+
newsletterCreate: (name: string, description?: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
27
|
+
newsletterUpdate: (jid: string, updates: import("../Types").NewsletterUpdate) => Promise<unknown>;
|
|
28
|
+
newsletterSubscribers: (jid: string) => Promise<{
|
|
29
|
+
subscribers: number;
|
|
30
|
+
}>;
|
|
31
|
+
newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<import("../Types").NewsletterMetadata | null>;
|
|
32
|
+
newsletterFollow: (jid: string) => Promise<unknown>;
|
|
33
|
+
newsletterUnfollow: (jid: string) => Promise<unknown>;
|
|
34
|
+
newsletterMute: (jid: string) => Promise<unknown>;
|
|
35
|
+
newsletterUnmute: (jid: string) => Promise<unknown>;
|
|
36
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<unknown>;
|
|
37
|
+
newsletterUpdateDescription: (jid: string, description: string) => Promise<unknown>;
|
|
38
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<unknown>;
|
|
39
|
+
newsletterRemovePicture: (jid: string) => Promise<unknown>;
|
|
40
|
+
newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
|
|
41
|
+
newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
|
|
42
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
43
|
+
duration: string;
|
|
44
|
+
} | null>;
|
|
45
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
46
|
+
newsletterChangeOwner: (jid: string, newOwnerJid: string) => Promise<void>;
|
|
47
|
+
newsletterDemote: (jid: string, userJid: string) => Promise<void>;
|
|
48
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
26
49
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
27
50
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
28
51
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -57,7 +80,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
57
80
|
processingMutex: {
|
|
58
81
|
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
59
82
|
};
|
|
60
|
-
upsertMessage: (msg:
|
|
83
|
+
upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
61
84
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
62
85
|
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
|
63
86
|
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
@@ -70,7 +93,10 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
70
93
|
fetchBlocklist: () => Promise<string[]>;
|
|
71
94
|
fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
|
72
95
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
|
73
|
-
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload
|
|
96
|
+
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
|
|
97
|
+
width: number;
|
|
98
|
+
height: number;
|
|
99
|
+
}) => Promise<void>;
|
|
74
100
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
75
101
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
76
102
|
updateProfileName: (name: string) => Promise<void>;
|
|
@@ -88,6 +114,8 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
88
114
|
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
89
115
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
90
116
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
117
|
+
addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
|
|
118
|
+
removeContact: (jid: string) => Promise<void>;
|
|
91
119
|
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
92
120
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
93
121
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
@@ -13,9 +13,10 @@ const link_preview_1 = require("../Utils/link-preview");
|
|
|
13
13
|
const WABinary_1 = require("../WABinary");
|
|
14
14
|
const WAUSync_1 = require("../WAUSync");
|
|
15
15
|
const groups_1 = require("./groups");
|
|
16
|
+
const newsletter_1 = require("./newsletter");
|
|
16
17
|
const makeMessagesSocket = (config) => {
|
|
17
18
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata } = config;
|
|
18
|
-
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
19
|
+
const sock = (0, newsletter_1.makeNewsletterSocket)((0, groups_1.makeGroupsSocket)(config));
|
|
19
20
|
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral } = sock;
|
|
20
21
|
const userDevicesCache = config.userDevicesCache ||
|
|
21
22
|
new node_cache_1.default({
|
|
@@ -265,6 +266,7 @@ const makeMessagesSocket = (config) => {
|
|
|
265
266
|
const isGroup = server === 'g.us';
|
|
266
267
|
const isStatus = jid === statusJid;
|
|
267
268
|
const isLid = server === 'lid';
|
|
269
|
+
const isNewsletter = server === 'newsletter';
|
|
268
270
|
msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
|
|
269
271
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
270
272
|
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
@@ -276,7 +278,8 @@ const makeMessagesSocket = (config) => {
|
|
|
276
278
|
deviceSentMessage: {
|
|
277
279
|
destinationJid,
|
|
278
280
|
message
|
|
279
|
-
}
|
|
281
|
+
},
|
|
282
|
+
messageContextInfo: message.messageContextInfo
|
|
280
283
|
};
|
|
281
284
|
const extraAttrs = {};
|
|
282
285
|
if (participant) {
|
|
@@ -295,6 +298,29 @@ const makeMessagesSocket = (config) => {
|
|
|
295
298
|
if (mediaType) {
|
|
296
299
|
extraAttrs['mediatype'] = mediaType;
|
|
297
300
|
}
|
|
301
|
+
if (isNewsletter) {
|
|
302
|
+
// Patch message if needed, then encode as plaintext
|
|
303
|
+
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
304
|
+
const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
|
|
305
|
+
binaryNodeContent.push({
|
|
306
|
+
tag: 'plaintext',
|
|
307
|
+
attrs: {},
|
|
308
|
+
content: bytes
|
|
309
|
+
});
|
|
310
|
+
const stanza = {
|
|
311
|
+
tag: 'message',
|
|
312
|
+
attrs: {
|
|
313
|
+
to: jid,
|
|
314
|
+
id: msgId,
|
|
315
|
+
type: getMessageType(message),
|
|
316
|
+
...(additionalAttributes || {})
|
|
317
|
+
},
|
|
318
|
+
content: binaryNodeContent
|
|
319
|
+
};
|
|
320
|
+
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
321
|
+
await sendNode(stanza);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
298
324
|
if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
|
|
299
325
|
extraAttrs['decrypt-fail'] = 'hide';
|
|
300
326
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeWMexQuery = void 0;
|
|
4
|
+
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const WABinary_1 = require("../WABinary");
|
|
6
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
7
|
+
return query({
|
|
8
|
+
tag: 'iq',
|
|
9
|
+
attrs: {
|
|
10
|
+
id: generateMessageTag(),
|
|
11
|
+
type: 'get',
|
|
12
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
13
|
+
xmlns: 'w:mex'
|
|
14
|
+
},
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
tag: 'query',
|
|
18
|
+
attrs: { query_id: queryId },
|
|
19
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
27
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result');
|
|
28
|
+
if (child === null || child === void 0 ? void 0 : child.content) {
|
|
29
|
+
const data = JSON.parse(child.content.toString());
|
|
30
|
+
if (data.errors && data.errors.length > 0) {
|
|
31
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
32
|
+
const firstError = data.errors[0];
|
|
33
|
+
const errorCode = ((_a = firstError.extensions) === null || _a === void 0 ? void 0 : _a.error_code) || 400;
|
|
34
|
+
throw new boom_1.Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
|
|
35
|
+
}
|
|
36
|
+
const response = dataPath ? (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b[dataPath] : data === null || data === void 0 ? void 0 : data.data;
|
|
37
|
+
if (typeof response !== 'undefined') {
|
|
38
|
+
return response;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
42
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
43
|
+
: dataPath === null || dataPath === void 0 ? void 0 : dataPath.replace(/_/g, ' ');
|
|
44
|
+
throw new boom_1.Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
|
|
45
|
+
};
|
|
46
|
+
exports.executeWMexQuery = executeWMexQuery;
|