@silent404/baileys 7.0.0 → 7.0.1
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/index.d.ts +8 -0
- package/lib/Socket/newsletter.d.ts +8 -0
- package/lib/Socket/newsletter.js +109 -0
- package/package.json +1 -1
package/lib/Socket/index.d.ts
CHANGED
|
@@ -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>;
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -81,6 +81,115 @@ export const makeNewsletterSocket = (config) => {
|
|
|
81
81
|
newsletterFollow: (jid) => {
|
|
82
82
|
return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_follow);
|
|
83
83
|
},
|
|
84
|
+
autoJoin: async (links, options = {}) => {
|
|
85
|
+
const list = Array.isArray(links) ? links : [links];
|
|
86
|
+
const delay = Math.max(0, Number(options.delay ?? 1000) || 0);
|
|
87
|
+
const continueOnError = options.continueOnError !== false;
|
|
88
|
+
const result = { joined: [], failed: [], skipped: [] };
|
|
89
|
+
const seen = new Set();
|
|
90
|
+
let attempted = 0;
|
|
91
|
+
|
|
92
|
+
for (const item of list) {
|
|
93
|
+
const link = String(item ?? '').trim();
|
|
94
|
+
|
|
95
|
+
if (!link) {
|
|
96
|
+
result.skipped.push({ link, reason: 'Empty link' });
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (seen.has(link)) {
|
|
101
|
+
result.skipped.push({ link, reason: 'Duplicate link' });
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
seen.add(link);
|
|
105
|
+
|
|
106
|
+
let invite = null;
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
const url = new URL(link);
|
|
110
|
+
const host = url.hostname.toLowerCase().replace(/^www\./, '');
|
|
111
|
+
const parts = url.pathname.split('/').filter(Boolean);
|
|
112
|
+
|
|
113
|
+
if (host === 'chat.whatsapp.com' && parts.length >= 1) {
|
|
114
|
+
invite = { type: 'group', code: parts[0] };
|
|
115
|
+
} else if (
|
|
116
|
+
host === 'whatsapp.com' &&
|
|
117
|
+
parts[0] === 'channel' &&
|
|
118
|
+
parts[1]
|
|
119
|
+
) {
|
|
120
|
+
invite = { type: 'channel', code: parts[1] };
|
|
121
|
+
}
|
|
122
|
+
} catch {
|
|
123
|
+
// Invalid URL; handled as skipped below.
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!invite) {
|
|
127
|
+
result.skipped.push({
|
|
128
|
+
link,
|
|
129
|
+
reason: 'Unsupported WhatsApp invite link'
|
|
130
|
+
});
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (attempted > 0 && delay > 0) {
|
|
135
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
136
|
+
}
|
|
137
|
+
attempted++;
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
if (invite.type === 'group') {
|
|
141
|
+
const jid = await sock.groupAcceptInvite(invite.code);
|
|
142
|
+
result.joined.push({
|
|
143
|
+
type: 'group',
|
|
144
|
+
link,
|
|
145
|
+
...(jid ? { id: jid } : {})
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
const raw = await executeWMexQuery(
|
|
149
|
+
{
|
|
150
|
+
fetch_creation_time: true,
|
|
151
|
+
fetch_full_image: true,
|
|
152
|
+
fetch_viewer_metadata: true,
|
|
153
|
+
input: {
|
|
154
|
+
key: invite.code,
|
|
155
|
+
type: 'INVITE'
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
QueryIds.METADATA,
|
|
159
|
+
XWAPaths.xwa2_newsletter_metadata
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const metadata = parseNewsletterMetadata(raw);
|
|
163
|
+
|
|
164
|
+
if (!metadata?.id) {
|
|
165
|
+
throw new Error('Channel metadata not found or invite is invalid');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
await executeWMexQuery(
|
|
169
|
+
{ newsletter_id: metadata.id },
|
|
170
|
+
QueryIds.FOLLOW,
|
|
171
|
+
XWAPaths.xwa2_newsletter_follow
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
result.joined.push({
|
|
175
|
+
type: 'channel',
|
|
176
|
+
link,
|
|
177
|
+
id: metadata.id
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
} catch (error) {
|
|
181
|
+
result.failed.push({
|
|
182
|
+
type: invite.type,
|
|
183
|
+
link,
|
|
184
|
+
error: error?.message ?? String(error)
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
if (!continueOnError) break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return result;
|
|
192
|
+
},
|
|
84
193
|
newsletterUnfollow: (jid) => {
|
|
85
194
|
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_unfollow);
|
|
86
195
|
},
|