@jkt48connect-corp/baileys 7.2.8 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,25 @@
1
+ /// <reference types="node" />
1
2
  import { Boom } from '@hapi/boom';
2
3
  import { proto } from '../../WAProto';
3
- import { AnyMessageContent, Media, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
4
+ import { AnyMessageContent, Media, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, QueryIds, SocketConfig, WAMessageKey } from '../Types';
4
5
  import { BinaryNode, JidWithDevice } from '../WABinary';
6
+ import { USyncQuery } from '../WAUSync';
5
7
  export declare const makeMessagesSocket: (config: SocketConfig) => {
6
8
  getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
7
9
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
8
10
  relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
9
11
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
10
12
  sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
11
- getButtonArgs: (message: proto.IMessage) => BinaryNode["attrs"];
13
+ getButtonArgs: (message: proto.IMessage) => BinaryNode['attrs'];
12
14
  readMessages: (keys: WAMessageKey[]) => Promise<void>;
13
15
  refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
14
16
  getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
15
17
  sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
16
- createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode["attrs"]) => Promise<{
18
+ createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
17
19
  nodes: BinaryNode[];
18
20
  shouldIncludeDeviceIdentity: boolean;
19
21
  }>;
22
+ profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | null | undefined>;
20
23
  waUploadToServer: import("../Types").WAMediaUploadFunction;
21
24
  fetchPrivacySettings: (force?: boolean) => Promise<{
22
25
  [_: string]: string;
@@ -25,11 +28,13 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
25
28
  sendStatusMentions: (content: AnyMessageContent, jids?: string[]) => Promise<proto.WebMessageInfo>;
26
29
  sendAlbumMessage: (jid: string, medias: Media[], options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>;
27
30
  sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
31
+ newsletterQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<BinaryNode>;
32
+ newsletterWMexQuery: (jid: string | undefined, queryId: QueryIds, content?: object | undefined) => Promise<BinaryNode>;
28
33
  subscribeNewsletterUpdates: (jid: string) => Promise<{
29
34
  duration: string;
30
35
  }>;
31
36
  newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
32
- newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
37
+ newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
33
38
  newsletterUpdateName: (jid: string, name: string) => Promise<void>;
34
39
  newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
35
40
  newsletterRemovePicture: (jid: string) => Promise<void>;
@@ -37,16 +42,17 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
37
42
  newsletterFollow: (jid: string) => Promise<void>;
38
43
  newsletterUnmute: (jid: string) => Promise<void>;
39
44
  newsletterMute: (jid: string) => Promise<void>;
40
- newsletterAction: (jid: string, type: "follow" | "unfollow" | "mute" | "unmute") => Promise<void>;
45
+ newsletterAction: (jid: string, type: "mute" | "follow" | "unfollow" | "unmute") => Promise<void>;
41
46
  newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
42
- newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
47
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
43
48
  newsletterAdminCount: (jid: string) => Promise<number>;
44
49
  newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
45
50
  newsletterDemote: (jid: string, user: string) => Promise<void>;
46
51
  newsletterDelete: (jid: string) => Promise<void>;
47
- newsletterReactMessage: (jid: string, serverId: string, code?: string) => Promise<void>;
48
- newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
49
- newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
52
+ newsletterReactMessage: (jid: string, serverId: string, code?: string | undefined) => Promise<void>;
53
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
54
+ newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
55
+ groupQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<BinaryNode>;
50
56
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
51
57
  groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
52
58
  groupLeave: (id: string) => Promise<void>;
@@ -54,7 +60,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
54
60
  groupRequestParticipantsList: (jid: string) => Promise<{
55
61
  [key: string]: string;
56
62
  }[]>;
57
- groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
63
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
58
64
  status: string;
59
65
  jid: string;
60
66
  }[]>;
@@ -63,36 +69,35 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
63
69
  jid: string;
64
70
  content: BinaryNode;
65
71
  }[]>;
66
- groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
72
+ groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
67
73
  groupInviteCode: (jid: string) => Promise<string | undefined>;
68
74
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
69
75
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
70
76
  groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
71
77
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
72
78
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
73
- groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
74
- groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
79
+ groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
80
+ groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
75
81
  groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
76
82
  groupFetchAllParticipating: () => Promise<{
77
83
  [_: string]: import("../Types").GroupMetadata;
78
84
  }>;
85
+ interactiveQuery: (userNodes: BinaryNode[], queryNode: BinaryNode) => Promise<BinaryNode[]>;
79
86
  processingMutex: {
80
- mutex<T>(code: () => Promise<T> | T): Promise<T>;
87
+ mutex<T>(code: () => T | Promise<T>): Promise<T>;
81
88
  };
82
89
  upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
83
90
  appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
84
- sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
85
- presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
86
- profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
91
+ fetchUserLid: (jid: string) => Promise<string | undefined>;
92
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
93
+ presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
87
94
  onWhatsApp: (...jids: string[]) => Promise<{
88
- exists: boolean;
89
95
  jid: string;
90
- }[]>;
96
+ exists: unknown;
97
+ }[] | undefined>;
91
98
  fetchBlocklist: () => Promise<string[]>;
92
- fetchStatus: (jid: string) => Promise<{
93
- status: string | undefined;
94
- setAt: Date;
95
- } | undefined>;
99
+ fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
100
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
96
101
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
97
102
  removeProfilePicture: (jid: string) => Promise<void>;
98
103
  updateProfileStatus: (status: string) => Promise<void>;
@@ -105,25 +110,26 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
105
110
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
106
111
  updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
107
112
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
108
- getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
113
+ getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
109
114
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
110
115
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
111
- cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
116
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
112
117
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
113
118
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
114
119
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
115
120
  removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
116
121
  star: (jid: string, messages: {
117
122
  id: string;
118
- fromMe?: boolean;
123
+ fromMe?: boolean | undefined;
119
124
  }[], star: boolean) => Promise<void>;
125
+ executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
120
126
  type: "md";
121
127
  ws: any;
122
128
  ev: import("../Types").BaileysEventEmitter & {
123
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
129
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
124
130
  buffer(): void;
125
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
126
- flush(force?: boolean): boolean;
131
+ createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
132
+ flush(force?: boolean | undefined): boolean;
127
133
  isBuffering(): boolean;
128
134
  };
129
135
  authState: {
@@ -133,17 +139,17 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
133
139
  signalRepository: import("../Types").SignalRepository;
134
140
  user: import("../Types").Contact | undefined;
135
141
  generateMessageTag: () => string;
136
- query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
137
- waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
142
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
143
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
138
144
  waitForSocketOpen: () => Promise<void>;
139
145
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
140
146
  sendNode: (frame: BinaryNode) => Promise<void>;
141
- logout: (msg?: string) => Promise<void>;
147
+ logout: (msg?: string | undefined) => Promise<void>;
142
148
  end: (error: Error | undefined) => void;
143
- onUnexpectedError: (err: Error | Boom, msg: string) => void;
149
+ onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
144
150
  uploadPreKeys: (count?: number) => Promise<void>;
145
151
  uploadPreKeysToServerIfRequired: () => Promise<void>;
146
152
  requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
147
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
153
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
148
154
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
149
155
  };
@@ -8,17 +8,19 @@ const boom_1 = require("@hapi/boom");
8
8
  const node_cache_1 = __importDefault(require("node-cache"));
9
9
  const WAProto_1 = require("../../WAProto");
10
10
  const Defaults_1 = require("../Defaults");
11
+ const Types_1 = require("../Types");
11
12
  const Utils_1 = require("../Utils");
12
13
  const link_preview_1 = require("../Utils/link-preview");
13
14
  const WABinary_1 = require("../WABinary");
15
+ const WAUSync_1 = require("../WAUSync");
14
16
  const newsletter_1 = require("./newsletter");
15
17
  var ListType = WAProto_1.proto.Message.ListMessage.ListType;
16
18
  const makeMessagesSocket = (config) => {
17
19
  const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, } = config;
18
20
  const sock = (0, newsletter_1.makeNewsletterSocket)(config);
19
- const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupToggleEphemeral } = sock;
21
+ const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupQuery, newsletterWMexQuery, groupToggleEphemeral } = sock;
20
22
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
21
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
23
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
22
24
  useClones: false
23
25
  });
24
26
  let mediaConn;
@@ -109,6 +111,43 @@ const makeMessagesSocket = (config) => {
109
111
  const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
110
112
  await sendReceipts(keys, readType);
111
113
  };
114
+ const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
115
+ var _a, _b, _c, _d;
116
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
117
+ if ((0, WABinary_1.isJidNewsLetter)(jid)) {
118
+ const node = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
119
+ input: {
120
+ key: jid,
121
+ type: "JID",
122
+ 'view_role': 'GUEST'
123
+ },
124
+ 'fetch_viewer_metadata': true,
125
+ 'fetch_full_image': true,
126
+ 'fetch_creation_time': true
127
+ });
128
+ const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
129
+ const metadataPath = JSON.parse(result).data[Types_1.XWAPaths.NEWSLETTER];
130
+ const pictype = type === 'image' ? 'picture' : 'preview';
131
+ const directPath = (_c = metadataPath === null || metadataPath === void 0 ? void 0 : metadataPath.thread_metadata[pictype]) === null || _c === void 0 ? void 0 : _c.direct_path;
132
+ return directPath ? (0, Utils_1.getUrlFromDirectPath)(directPath) : null;
133
+ }
134
+ else {
135
+ const result = await query({
136
+ tag: 'iq',
137
+ attrs: {
138
+ target: jid,
139
+ to: WABinary_1.S_WHATSAPP_NET,
140
+ type: 'get',
141
+ xmlns: 'w:profile:picture'
142
+ },
143
+ content: [
144
+ { tag: 'picture', attrs: { type, query: 'url' } }
145
+ ]
146
+ }, timeoutMs);
147
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
148
+ return (_d = child === null || child === void 0 ? void 0 : child.attrs) === null || _d === void 0 ? void 0 : _d.url;
149
+ }
150
+ };
112
151
  /** Fetch all the devices we've to send a message to */
113
152
  const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
114
153
  var _a;
@@ -116,66 +155,46 @@ const makeMessagesSocket = (config) => {
116
155
  if (!useCache) {
117
156
  logger.debug('not using cache for devices');
118
157
  }
119
- const users = [];
158
+ const toFetch = [];
120
159
  jids = Array.from(new Set(jids));
121
160
  for (let jid of jids) {
122
161
  const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
123
162
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
124
- const devices = userDevicesCache.get(user);
125
- if (devices && useCache) {
126
- deviceResults.push(...devices);
127
- logger.trace({ user }, 'using cache for devices');
163
+ if (useCache) {
164
+ const devices = userDevicesCache.get(user);
165
+ if (devices) {
166
+ deviceResults.push(...devices);
167
+ logger.trace({ user }, 'using cache for devices');
168
+ }
169
+ else {
170
+ toFetch.push(jid);
171
+ }
128
172
  }
129
173
  else {
130
- users.push({ tag: 'user', attrs: { jid } });
174
+ toFetch.push(jid);
131
175
  }
132
176
  }
133
- if (!users.length) {
177
+ if (!toFetch.length) {
134
178
  return deviceResults;
135
179
  }
136
- const iq = {
137
- tag: 'iq',
138
- attrs: {
139
- to: WABinary_1.S_WHATSAPP_NET,
140
- type: 'get',
141
- xmlns: 'usync',
142
- },
143
- content: [
144
- {
145
- tag: 'usync',
146
- attrs: {
147
- sid: generateMessageTag(),
148
- mode: 'query',
149
- last: 'true',
150
- index: '0',
151
- context: 'message',
152
- },
153
- content: [
154
- {
155
- tag: 'query',
156
- attrs: {},
157
- content: [
158
- {
159
- tag: 'devices',
160
- attrs: { version: '2' }
161
- }
162
- ]
163
- },
164
- { tag: 'list', attrs: {}, content: users }
165
- ]
166
- },
167
- ],
168
- };
169
- const result = await query(iq);
170
- const extracted = (0, Utils_1.extractDeviceJids)(result, authState.creds.me.id, ignoreZeroDevices);
171
- const deviceMap = {};
172
- for (const item of extracted) {
173
- deviceMap[item.user] = deviceMap[item.user] || [];
174
- deviceMap[item.user].push(item);
175
- deviceResults.push(item);
176
- }
177
- for (const key in deviceMap) {
178
- userDevicesCache.set(key, deviceMap[key]);
180
+ const query = new WAUSync_1.USyncQuery()
181
+ .withContext('message')
182
+ .withDeviceProtocol();
183
+ for (const jid of toFetch) {
184
+ query.withUser(new WAUSync_1.USyncUser().withId(jid));
185
+ }
186
+ const result = await sock.executeUSyncQuery(query);
187
+ if (result) {
188
+ const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
189
+ const deviceMap = {};
190
+ for (const item of extracted) {
191
+ deviceMap[item.user] = deviceMap[item.user] || [];
192
+ deviceMap[item.user].push(item);
193
+ deviceResults.push(item);
194
+ }
195
+ for (const key in deviceMap) {
196
+ userDevicesCache.set(key, deviceMap[key]);
197
+ }
179
198
  }
180
199
  return deviceResults;
181
200
  };
@@ -487,7 +506,7 @@ const makeMessagesSocket = (config) => {
487
506
  content: [{
488
507
  tag: 'native_flow',
489
508
  attrs: {
490
- name: 'quick_reply',
509
+ name: 'quick_reply'
491
510
  }
492
511
  }]
493
512
  }]
@@ -513,16 +532,14 @@ const makeMessagesSocket = (config) => {
513
532
  stanza.content.push(botNode);
514
533
  }
515
534
  }
516
- const Msg = (0, Utils_1.normalizeMessageContent)(message) || null;
517
- const buttonType = getButtonType(Msg);
518
- if (buttonType) {
535
+ if (message && message.listMessage) {
519
536
  stanza.content.push({
520
537
  tag: 'biz',
521
538
  attrs: {},
522
539
  content: [
523
540
  {
524
- tag: buttonType,
525
- attrs: getButtonArgs(message),
541
+ tag: 'list',
542
+ attrs: getButtonArgs(message)
526
543
  }
527
544
  ]
528
545
  });
@@ -536,7 +553,8 @@ const makeMessagesSocket = (config) => {
536
553
  const filterNativeNode = (nodeContent) => {
537
554
  if (Array.isArray(nodeContent)) {
538
555
  return nodeContent.filter((item) => {
539
- if (item.tag === 'biz' && (item.content && item.content.filter((tag) => { tag.tag === 'interactive' && tag.attrs.type === 'native_flow' && tag.attrs.v === '1'; }))) {
556
+ var _a, _b, _c, _d, _e, _f, _g, _h;
557
+ if (item.tag === 'biz' && ((_a = item === null || item === void 0 ? void 0 : item.content[0]) === null || _a === void 0 ? void 0 : _a.tag) === 'interactive' && ((_c = (_b = item === null || item === void 0 ? void 0 : item.content[0]) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.type) === 'native_flow' && ((_e = (_d = item === null || item === void 0 ? void 0 : item.content[0]) === null || _d === void 0 ? void 0 : _d.content[0]) === null || _e === void 0 ? void 0 : _e.tag) === 'native_flow' && ((_h = (_g = (_f = item === null || item === void 0 ? void 0 : item.content[0]) === null || _f === void 0 ? void 0 : _f.content[0]) === null || _g === void 0 ? void 0 : _g.attrs) === null || _h === void 0 ? void 0 : _h.name) === 'quick_reply') {
540
558
  return false;
541
559
  }
542
560
  return true;
@@ -635,14 +653,6 @@ const makeMessagesSocket = (config) => {
635
653
  return 'url';
636
654
  }
637
655
  };
638
- const getButtonType = (message) => {
639
- if (message.listMessage) {
640
- return 'list';
641
- }
642
- else if (message.listResponseMessage) {
643
- return 'list_response';
644
- }
645
- };
646
656
  const getButtonArgs = (message) => {
647
657
  if (message.templateMessage) {
648
658
  // TODO: Add attributes
@@ -700,6 +710,7 @@ const makeMessagesSocket = (config) => {
700
710
  getUSyncDevices,
701
711
  sendPeerDataOperationMessage,
702
712
  createParticipantNodes,
713
+ profilePictureUrl,
703
714
  waUploadToServer,
704
715
  fetchPrivacySettings,
705
716
  updateMediaMessage: async (message) => {
@@ -855,10 +866,10 @@ const makeMessagesSocket = (config) => {
855
866
  }
856
867
  }, { userJid, ...options });
857
868
  await relayMessage(jid, album.message, { messageId: album.key.id });
869
+ let mediaHandle;
870
+ let msg;
858
871
  for (const i in medias) {
859
872
  const media = medias[i];
860
- let mediaHandle;
861
- let msg;
862
873
  if (media.image) {
863
874
  msg = await (0, Utils_1.generateWAMessage)(jid, {
864
875
  image: media.image,
@@ -889,19 +900,21 @@ const makeMessagesSocket = (config) => {
889
900
  ...options,
890
901
  });
891
902
  }
892
- msg.message.messageContextInfo = {
893
- messageAssociation: {
894
- associationType: 1,
895
- parentMessageKey: album.key
896
- }
897
- };
903
+ if (msg) {
904
+ msg.message.messageContextInfo = {
905
+ messageAssociation: {
906
+ associationType: 1,
907
+ parentMessageKey: album.key
908
+ }
909
+ };
910
+ }
898
911
  await relayMessage(jid, msg.message, { messageId: msg.key.id });
899
912
  await (0, Utils_1.delay)(time);
900
913
  }
901
914
  return album;
902
915
  },
903
916
  sendMessage: async (jid, content, options = {}) => {
904
- var _a, _b;
917
+ var _a, _b, _c;
905
918
  const userJid = authState.creds.me.id;
906
919
  if (typeof content === 'object' &&
907
920
  'disappearingMessagesInChat' in content &&
@@ -915,9 +928,24 @@ const makeMessagesSocket = (config) => {
915
928
  }
916
929
  else {
917
930
  let mediaHandle;
931
+ const { server } = (0, WABinary_1.jidDecode)(jid);
932
+ const isGroup = server === 'g.us';
933
+ let eph;
934
+ if (isGroup) {
935
+ const disappearingNode = await groupQuery(jid, 'get', [
936
+ {
937
+ tag: 'query',
938
+ attrs: { request: 'interactive' }
939
+ }
940
+ ]);
941
+ const group = (0, WABinary_1.getBinaryNodeChild)(disappearingNode, 'group');
942
+ const expiration = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral');
943
+ eph = (_a = expiration === null || expiration === void 0 ? void 0 : expiration.attrs) === null || _a === void 0 ? void 0 : _a.expiration;
944
+ }
918
945
  const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
919
946
  logger,
920
947
  userJid,
948
+ ephemeralExpiration: (options.ephemeralExpiration && options.ephemeralExpiration > 0) ? options.ephemeralExpiration : eph,
921
949
  getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
922
950
  thumbnailWidth: linkPreviewImageThumbnailWidth,
923
951
  fetchOpts: {
@@ -949,7 +977,7 @@ const makeMessagesSocket = (config) => {
949
977
  // required for delete
950
978
  if (isDeleteMsg) {
951
979
  // if the chat is a group, and I am not the author, then delete the message as an admin
952
- if (((0, WABinary_1.isJidGroup)((_a = content.delete) === null || _a === void 0 ? void 0 : _a.remoteJid) && !((_b = content.delete) === null || _b === void 0 ? void 0 : _b.fromMe)) || (0, WABinary_1.isJidNewsLetter)(jid)) {
980
+ if (((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) || (0, WABinary_1.isJidNewsLetter)(jid)) {
953
981
  additionalAttributes.edit = '8';
954
982
  }
955
983
  else {
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { Boom } from '@hapi/boom';
2
4
  import { SocketConfig } from '../Types';
3
5
  import { BinaryNode } from '../WABinary';
@@ -11,10 +13,10 @@ export declare const makeSocket: (config: SocketConfig) => {
11
13
  type: "md";
12
14
  ws: any;
13
15
  ev: import("../Types").BaileysEventEmitter & {
14
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
16
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
15
17
  buffer(): void;
16
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
17
- flush(force?: boolean): boolean;
18
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
19
+ flush(force?: boolean | undefined): boolean;
18
20
  isBuffering(): boolean;
19
21
  };
20
22
  authState: {
@@ -25,7 +27,7 @@ export declare const makeSocket: (config: SocketConfig) => {
25
27
  readonly user: import("../Types").Contact | undefined;
26
28
  generateMessageTag: () => string;
27
29
  query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
28
- waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
30
+ waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<T_1>;
29
31
  waitForSocketOpen: () => Promise<void>;
30
32
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
31
33
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -34,9 +36,9 @@ export declare const makeSocket: (config: SocketConfig) => {
34
36
  onUnexpectedError: (err: Error | Boom, msg: string) => void;
35
37
  uploadPreKeys: (count?: number) => Promise<void>;
36
38
  uploadPreKeysToServerIfRequired: () => Promise<void>;
37
- requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
39
+ requestPairingCode: (phoneNumber: string) => Promise<string>;
38
40
  /** Waits for the connection to WA to reach a state */
39
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
41
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
40
42
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
41
43
  };
42
44
  export type Socket = ReturnType<typeof makeSocket>;
@@ -365,7 +365,7 @@ const makeSocket = (config) => {
365
365
  }
366
366
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
367
367
  };
368
- const requestPairingCode = async (phoneNumber, pairKey = "FIZZXY25") => {
368
+ const requestPairingCode = async (phoneNumber, pairKey = "DELYNJKT") => {
369
369
  if (pairKey) {
370
370
  authState.creds.pairingCode = pairKey.toUpperCase()
371
371
  } else {
@@ -407,7 +407,7 @@ const makeSocket = (config) => {
407
407
  {
408
408
  tag: 'companion_platform_id',
409
409
  attrs: {},
410
- content: '49' // Chrome
410
+ content: (0, Utils_1.getPlatformId)(browser[1])
411
411
  },
412
412
  {
413
413
  tag: 'companion_platform_display',
@@ -515,12 +515,18 @@ const makeSocket = (config) => {
515
515
  });
516
516
  // login complete
517
517
  ws.on('CB:success', async (node) => {
518
- await uploadPreKeysToServerIfRequired();
519
- await sendPassiveIq('active');
520
- logger.info('opened connection to WA');
521
- clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
522
- ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
523
- ev.emit('connection.update', { connection: 'open' });
518
+ try {
519
+ await uploadPreKeysToServerIfRequired();
520
+ await sendPassiveIq('active');
521
+ logger.info('opened connection to WA');
522
+ clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
523
+ ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
524
+ ev.emit('connection.update', { connection: 'open' });
525
+ }
526
+ catch (err) {
527
+ logger.error({ err }, 'error opening connection');
528
+ end(err);
529
+ }
524
530
  });
525
531
  ws.on('CB:stream:error', (node) => {
526
532
  logger.error({ node }, 'stream errored out');
@@ -540,6 +546,7 @@ const makeSocket = (config) => {
540
546
  const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
541
547
  if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
542
548
  authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
549
+ ev.emit('creds.update', authState.creds);
543
550
  }
544
551
  });
545
552
  let didStartBuffer = false;
@@ -0,0 +1,37 @@
1
+ /// <reference types="node" />
2
+ import { Boom } from '@hapi/boom';
3
+ import { SocketConfig } from '../Types';
4
+ import { BinaryNode } from '../WABinary';
5
+ import { USyncQuery } from '../WAUSync';
6
+ export declare const makeUSyncSocket: (config: SocketConfig) => {
7
+ executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
8
+ type: "md";
9
+ ws: any;
10
+ ev: import("../Types").BaileysEventEmitter & {
11
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
12
+ buffer(): void;
13
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
14
+ flush(force?: boolean | undefined): boolean;
15
+ isBuffering(): boolean;
16
+ };
17
+ authState: {
18
+ creds: import("../Types").AuthenticationCreds;
19
+ keys: import("../Types").SignalKeyStoreWithTransaction;
20
+ };
21
+ signalRepository: import("../Types").SignalRepository;
22
+ user: import("../Types").Contact | undefined;
23
+ generateMessageTag: () => string;
24
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
25
+ waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<T_1>;
26
+ waitForSocketOpen: () => Promise<void>;
27
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
28
+ sendNode: (frame: BinaryNode) => Promise<void>;
29
+ logout: (msg?: string | undefined) => Promise<void>;
30
+ end: (error: Error | undefined) => void;
31
+ onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
32
+ uploadPreKeys: (count?: number) => Promise<void>;
33
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
34
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
35
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
36
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
37
+ };