@deathnaitsa/wa-api 1.0.12 → 1.0.14
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/dist/Messaging/index.js +19 -331
- package/package.json +2 -2
- package/readme.md +126 -59
package/dist/Messaging/index.js
CHANGED
|
@@ -32,52 +32,7 @@ const is_exist_1 = require("../Utils/is-exist");
|
|
|
32
32
|
const mime_1 = __importDefault(require("mime"));
|
|
33
33
|
const Error_1 = require("../Error");
|
|
34
34
|
const qrcode = require("qrcode")
|
|
35
|
-
const joinGroup = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
var { sessionId, text = ""} = _a, props = __rest(_a, ["sessionId", "text"]);
|
|
37
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
38
|
-
if (!session) {
|
|
39
|
-
throw new Error_1.SessionNotFound(sessionId);
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
session.groupAcceptInvite(text)
|
|
43
|
-
});
|
|
44
|
-
exports.joinGroup = joinGroup;
|
|
45
|
-
const del = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
var { sessionId, to = "",id='',sender=''} = _a, props = __rest(_a, ["sessionId", "to","id","sender"]);
|
|
47
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
48
|
-
if (!session) {
|
|
49
|
-
throw new Error_1.SessionNotFound(sessionId);
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
session.sendMessage(to, { delete: { remoteJid: to, id: id, participant: sender } })
|
|
53
|
-
});
|
|
54
|
-
exports.del = del;
|
|
55
|
-
const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
-
var { sessionId, to, text = "", isGroup = false,Jid } = _a, props = __rest(_a, ["sessionId", "to", "text", "isGroup","Jid"]);
|
|
57
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
58
|
-
|
|
59
|
-
if (!session)
|
|
60
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
61
|
-
const oldPhone = to;
|
|
62
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
63
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
64
|
-
sessionId,
|
|
65
|
-
to,
|
|
66
|
-
isGroup,
|
|
67
|
-
});
|
|
68
|
-
if (!isRegistered) {
|
|
69
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
70
|
-
}
|
|
71
|
-
return yield session.sendMessage(to, { text: text,mentions: Jid
|
|
72
|
-
}, {
|
|
73
|
-
quoted: props.answering,
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
exports.sendTextMessage = sendTextMessage;
|
|
78
35
|
|
|
79
|
-
|
|
80
|
-
// Cache sessions to avoid repeated lookups
|
|
81
36
|
const sessionCache = new Map();
|
|
82
37
|
|
|
83
38
|
function getCachedSession(sessionId) {
|
|
@@ -118,293 +73,26 @@ async function sendMessage(sessionId, jid, content, options) {
|
|
|
118
73
|
|
|
119
74
|
exports.sendMessage = sendMessage;
|
|
120
75
|
|
|
121
|
-
const kickusr = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
-
var { sessionId, to, text = "", isGroup = true } = _a, props = __rest(_a, ["sessionId", "to", "text",'isGroup']);
|
|
123
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
124
|
-
|
|
125
|
-
if (!session)
|
|
126
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
127
|
-
const oldPhone = to;
|
|
128
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
129
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
130
|
-
sessionId,
|
|
131
|
-
to,
|
|
132
|
-
isGroup,
|
|
133
|
-
});
|
|
134
|
-
if (!isRegistered) {
|
|
135
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
136
|
-
}
|
|
137
|
-
return session.groupParticipantsUpdate(to,[`${text}`],"remove")
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
exports.kickusr = kickusr;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const sendImage = (_b) => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
-
var { sessionId, to, text = "", isGroup = false, media } = _b, props = __rest(_b, ["sessionId", "to", "text", "isGroup", "media"]);
|
|
145
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
146
|
-
if (!session)
|
|
147
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
148
|
-
const oldPhone = to;
|
|
149
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
150
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
151
|
-
sessionId,
|
|
152
|
-
to,
|
|
153
|
-
isGroup,
|
|
154
|
-
});
|
|
155
|
-
if (!isRegistered) {
|
|
156
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
157
|
-
}
|
|
158
|
-
if (!media)
|
|
159
|
-
throw new Error_1.WhatsappError("parameter media must be Buffer or String URL");
|
|
160
|
-
return yield session.sendMessage(to, {
|
|
161
|
-
image: typeof media == "string"
|
|
162
|
-
? {
|
|
163
|
-
url: media,
|
|
164
|
-
}
|
|
165
|
-
: media,
|
|
166
|
-
caption: text,
|
|
167
|
-
}, {
|
|
168
|
-
quoted: props.answering,
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
exports.sendImage = sendImage;
|
|
172
|
-
const sendQr = (_b) => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
-
var { sessionId, to, text = "", isGroup = false } = _b, props = __rest(_b, ["sessionId", "to", "text", "isGroup"]);
|
|
174
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
175
|
-
if (!session)
|
|
176
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
177
|
-
const oldPhone = to;
|
|
178
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
179
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
180
|
-
sessionId,
|
|
181
|
-
to,
|
|
182
|
-
isGroup,
|
|
183
|
-
});
|
|
184
|
-
if (!isRegistered) {
|
|
185
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
186
|
-
}
|
|
187
|
-
session.sendMessage(to,{image: { url: qrcode.toDataURL(text.slice(0, 2048), { scale: 8 })},"fileName":'qrcode.png'}, { quoted: props.answering});
|
|
188
|
-
});
|
|
189
|
-
exports.sendQr = sendQr;
|
|
190
|
-
const sendVideo = (_c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
191
|
-
var { sessionId, to, text = "", isGroup = false, media } = _c, props = __rest(_c, ["sessionId", "to", "text", "isGroup", "media"]);
|
|
192
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
193
|
-
if (!session)
|
|
194
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
195
|
-
const oldPhone = to;
|
|
196
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
197
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
198
|
-
sessionId,
|
|
199
|
-
to,
|
|
200
|
-
isGroup,
|
|
201
|
-
});
|
|
202
|
-
if (!isRegistered) {
|
|
203
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
204
|
-
}
|
|
205
|
-
if (!media)
|
|
206
|
-
throw new Error_1.WhatsappError("parameter media must be Buffer or String URL");
|
|
207
|
-
return yield session.sendMessage(to, {
|
|
208
|
-
video: typeof media == "string"
|
|
209
|
-
? {
|
|
210
|
-
url: media,
|
|
211
|
-
}
|
|
212
|
-
: media,
|
|
213
|
-
caption: text,
|
|
214
|
-
}, {
|
|
215
|
-
quoted: props.answering,
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
exports.sendVideo = sendVideo;
|
|
219
|
-
const sendDocument = (_d) => __awaiter(void 0, void 0, void 0, function* () {
|
|
220
|
-
var { sessionId, to, text = "", isGroup = false, media, filename } = _d, props = __rest(_d, ["sessionId", "to", "text", "isGroup", "media", "filename"]);
|
|
221
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
222
|
-
if (!session)
|
|
223
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
224
|
-
const oldPhone = to;
|
|
225
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
226
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
227
|
-
sessionId,
|
|
228
|
-
to,
|
|
229
|
-
isGroup,
|
|
230
|
-
});
|
|
231
|
-
if (!isRegistered) {
|
|
232
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
233
|
-
}
|
|
234
|
-
if (!media) {
|
|
235
|
-
throw new Error_1.WhatsappError(`Invalid Media`);
|
|
236
|
-
}
|
|
237
|
-
const mimetype = mime_1.default.getType(filename);
|
|
238
|
-
if (!mimetype) {
|
|
239
|
-
throw new Error_1.WhatsappError(`Filename must include valid extension`);
|
|
240
|
-
}
|
|
241
|
-
return yield session.sendMessage(to, {
|
|
242
|
-
fileName: filename,
|
|
243
|
-
document: typeof media == "string"
|
|
244
|
-
? {
|
|
245
|
-
url: media,
|
|
246
|
-
}
|
|
247
|
-
: media,
|
|
248
|
-
mimetype: mimetype,
|
|
249
|
-
caption: text,
|
|
250
|
-
}, {
|
|
251
|
-
quoted: props.answering,
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
exports.sendDocument = sendDocument;
|
|
255
|
-
const gruppeninfo = (_e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
256
|
-
var { sessionId, to, isGroup = false } = _e, props = __rest(_e, ["sessionId", "to","isGroup"]);
|
|
257
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
258
|
-
if (!session)
|
|
259
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
260
|
-
const oldPhone = to;
|
|
261
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
262
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
263
|
-
sessionId,
|
|
264
|
-
to,
|
|
265
|
-
isGroup,
|
|
266
|
-
});
|
|
267
|
-
if (!isRegistered) {
|
|
268
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
269
|
-
}
|
|
270
|
-
return yield session.groupMetadata(to);
|
|
271
|
-
})
|
|
272
|
-
exports.gruppeninfo = gruppeninfo;
|
|
273
|
-
const getAllGroupInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
274
|
-
const sessions = Socket_1.getAllSessions();
|
|
275
|
-
const groupMetadatas = [];
|
|
276
|
-
for (const session of sessions) {
|
|
277
|
-
const groups = yield session.getAllGroups();
|
|
278
|
-
for (const group of groups) {
|
|
279
|
-
const metadata = yield session.groupMetadata(group);
|
|
280
|
-
groupMetadatas.push(metadata);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return groupMetadatas;
|
|
284
|
-
});
|
|
285
|
-
exports.getAllGroupInfo = getAllGroupInfo;
|
|
286
|
-
|
|
287
|
-
const sendMention = (_e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
288
|
-
var { sessionId, to,text = "",mention = "", isGroup = false } = _e, props = __rest(_e, ["sessionId", "to","text", "mention","isGroup"]);
|
|
289
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
290
|
-
if (!session)
|
|
291
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
292
|
-
const oldPhone = to;
|
|
293
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
294
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
295
|
-
sessionId,
|
|
296
|
-
to,
|
|
297
|
-
isGroup,
|
|
298
|
-
});
|
|
299
|
-
if (!isRegistered) {
|
|
300
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
301
|
-
}
|
|
302
|
-
return yield session.sendMessage(to, {
|
|
303
|
-
text: text,
|
|
304
|
-
mentions: mention,
|
|
305
|
-
}, {
|
|
306
|
-
quoted: props.answering,
|
|
307
|
-
});
|
|
308
|
-
})
|
|
309
|
-
exports.sendMention = sendMention;
|
|
310
|
-
|
|
311
|
-
const sendVoiceNote = (_e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
312
|
-
var { sessionId, to, isGroup = false, media } = _e, props = __rest(_e, ["sessionId", "to", "isGroup", "media"]);
|
|
313
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
314
|
-
if (!session)
|
|
315
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
316
|
-
const oldPhone = to;
|
|
317
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
318
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
319
|
-
sessionId,
|
|
320
|
-
to,
|
|
321
|
-
isGroup,
|
|
322
|
-
});
|
|
323
|
-
if (!isRegistered) {
|
|
324
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
325
|
-
}
|
|
326
|
-
if (!media) {
|
|
327
|
-
throw new Error_1.WhatsappError(`Invalid Media`);
|
|
328
|
-
}
|
|
329
|
-
return yield session.sendMessage(to, {
|
|
330
|
-
audio : {url: media},
|
|
331
|
-
fileName: "test" + '.mp3', mimetype: 'audio/mpeg' }, {
|
|
332
|
-
quoted: props.answering,
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
exports.sendVoiceNote = sendVoiceNote;
|
|
336
|
-
const sendSticker = (_f) => __awaiter(void 0, void 0, void 0, function* () {
|
|
337
|
-
var { sessionId, to, isGroup, media } = _f, props = __rest(_f, ["sessionId", "to", "isGroup", "media"]);
|
|
338
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
339
|
-
if (!session)
|
|
340
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
341
|
-
const oldPhone = to;
|
|
342
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
343
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
344
|
-
sessionId,
|
|
345
|
-
to,
|
|
346
|
-
isGroup,
|
|
347
|
-
});
|
|
348
|
-
if (!isRegistered) {
|
|
349
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
350
|
-
}
|
|
351
|
-
if (!media) {
|
|
352
|
-
throw new Error_1.WhatsappError(`Invalid Media`);
|
|
353
|
-
}
|
|
354
|
-
return yield session.sendMessage(to, {
|
|
355
|
-
sticker: typeof media == "string"
|
|
356
|
-
? {
|
|
357
|
-
url: media,
|
|
358
|
-
}
|
|
359
|
-
: media,
|
|
360
|
-
}, {
|
|
361
|
-
quoted: props.answering,
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
exports.sendSticker = sendSticker;
|
|
365
|
-
/**
|
|
366
|
-
* Give typing effect to target
|
|
367
|
-
*
|
|
368
|
-
* Looks like human typing
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* @param sessionId - Session ID
|
|
372
|
-
* @param to - Target
|
|
373
|
-
* @param duration - Duration in miliseconds typing effect will appear
|
|
374
|
-
*/
|
|
375
|
-
const sendTyping = ({ sessionId, to, duration = 1000, isGroup = false, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
376
|
-
const oldPhone = to;
|
|
377
|
-
to = (0, Utils_1.phoneToJid)({ to, isGroup });
|
|
378
|
-
const session = (0, Socket_1.getSession)(sessionId);
|
|
379
|
-
if (!session)
|
|
380
|
-
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
381
|
-
const isRegistered = yield (0, is_exist_1.isExist)({
|
|
382
|
-
sessionId,
|
|
383
|
-
to,
|
|
384
|
-
isGroup,
|
|
385
|
-
});
|
|
386
|
-
if (!isRegistered) {
|
|
387
|
-
throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
|
|
388
|
-
}
|
|
389
|
-
yield session.sendPresenceUpdate("composing", to);
|
|
390
|
-
yield (0, create_delay_1.createDelay)(duration);
|
|
391
|
-
yield session.sendPresenceUpdate("available", to);
|
|
392
|
-
});
|
|
393
|
-
exports.sendTyping = sendTyping;
|
|
394
76
|
/**
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
* Looks like human typing
|
|
77
|
+
* Low-level relayMessage-Wrapper für Baileys.
|
|
398
78
|
*
|
|
79
|
+
* @param {string} sessionId - Deine Session-ID
|
|
80
|
+
* @param {string} jid - Ziel-JID oder Telefonnummer
|
|
81
|
+
* @param {object} content - das rohe Message-Node-Objekt
|
|
82
|
+
* @param {object} options - zusätzliche Relay-Optionen wie messageId, participant, additionalNodes, etc.
|
|
399
83
|
*
|
|
400
|
-
* @
|
|
401
|
-
* @param to - Target
|
|
402
|
-
* @param duration - Duration in miliseconds typing effect will appear
|
|
84
|
+
* @returns {Promise<string>} die gesendete Nachricht-ID
|
|
403
85
|
*/
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
86
|
+
async function relayMessage(sessionId, jid, content, options = {}) {
|
|
87
|
+
const session = getCachedSession(sessionId);
|
|
88
|
+
if (!session) throw new WhatsappError(`Session ${sessionId} nicht gefunden`);
|
|
89
|
+
|
|
90
|
+
const destJid = jid.includes("@") ? jid : phoneToJid({ to: jid });
|
|
91
|
+
try {
|
|
92
|
+
// Baileys-intern sendet hier direkt das XML-Stanza
|
|
93
|
+
return await session.relayMessage(destJid, content, options);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
throw new Error_1.WhatsappError(`Relay an ${destJid} fehlgeschlagen: ${err.message}`, { cause: err });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.relayMessage = relayMessage;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deathnaitsa/wa-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "Multi Session Whatsapp Library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
|
|
7
|
+
"licenses": "LiCINSE",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/DeathNaitsa/wa-api.git"
|
package/readme.md
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
# wa-api
|
|
2
2
|
|
|
3
|
-
Leichte Bibliothek zur Verwaltung mehrerer WhatsApp-Sessions – mit
|
|
3
|
+
Leichte Bibliothek zur Verwaltung mehrerer WhatsApp-Sessions – mit einer zentralen `sendMessage`-Funktion und direktem Zugriff auf Baileys’ `relayMessage`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📑 Inhaltsverzeichnis
|
|
8
|
+
|
|
9
|
+
1. [Kurzübersicht](#kurzübersicht)
|
|
10
|
+
2. [Installation & Setup](#installation--setup)
|
|
11
|
+
3. [Session Management](#session-management)
|
|
12
|
+
4. [Nachrichten senden (`sendMessage`)](#nachrichten-senden-sendmessage)
|
|
13
|
+
5. [Low-Level Relay (`relayMessage`)](#low-level-relay-relaymessage)
|
|
14
|
+
6. [Listener](#listener)
|
|
15
|
+
7. [Fehlerbehandlung](#fehlerbehandlung)
|
|
16
|
+
8. [Support](#support)
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 🚀 Kurzübersicht
|
|
21
|
+
|
|
22
|
+
**wa-api** bietet:
|
|
23
|
+
|
|
24
|
+
* **Multi-Session**: Verwaltung beliebig vieler WhatsApp-Sessions in einer App.
|
|
25
|
+
* **One-Stop Messaging**: Eine einzige `sendMessage`-Funktion für **Text**, **Media**, **Umfragen**, **Reactions**, **Status-Updates** u.v.m.
|
|
26
|
+
* **Low-Level Relay**: Direkter Zugriff auf Baileys’ `relayMessage` für Spezialfälle.
|
|
27
|
+
* **Automatisches Caching** und **JID-Konvertierung**.
|
|
28
|
+
* **Konsistentes Error-Handling** mit `WhatsappError`.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 📦 Installation & Setup
|
|
6
33
|
|
|
7
34
|
```bash
|
|
8
35
|
npm install @deathnaitsa/wa-api@latest
|
|
9
36
|
```
|
|
10
37
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Verwende den klassischen Import-Stil:
|
|
38
|
+
**Import**
|
|
14
39
|
|
|
15
40
|
```js
|
|
16
41
|
// CommonJS
|
|
@@ -20,89 +45,131 @@ const wa = require('@deathnaitsa/wa-api');
|
|
|
20
45
|
import * as wa from '@deathnaitsa/wa-api';
|
|
21
46
|
```
|
|
22
47
|
|
|
23
|
-
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 🔑 Session Management
|
|
51
|
+
|
|
52
|
+
| Funktion | Beschreibung |
|
|
53
|
+
| ----------------------------------------------------- | ------------------------------------------------- |
|
|
54
|
+
| `wa.startSession(id)` | Neue Session starten + QR-Code im Terminal zeigen |
|
|
55
|
+
| `wa.startSessionWithPairingCode(id, { phoneNumber })` | Direkt per Pairing-Code starten |
|
|
56
|
+
| `wa.getAllSession()` | Array aller aktiven Session-IDs |
|
|
57
|
+
| `wa.getSession(id)` | Metadaten einer Session abrufen |
|
|
58
|
+
| `wa.loadSessionsFromStorage()` | Alle gespeicherten Sessions aus Ordner laden |
|
|
59
|
+
|
|
60
|
+
**Beispiel**
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
await wa.startSession('meineSession');
|
|
64
|
+
const sessions = wa.getAllSession();
|
|
65
|
+
console.log(sessions);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
24
69
|
|
|
25
|
-
##
|
|
70
|
+
## 💬 Nachrichten senden (`sendMessage`)
|
|
26
71
|
|
|
27
72
|
```js
|
|
28
|
-
|
|
29
|
-
|
|
73
|
+
await wa.sendMessage(
|
|
74
|
+
sessionId, // string
|
|
75
|
+
jidOrPhone, // string (z.B. '491234567890@c.us')
|
|
76
|
+
content, // AnyMessageContent-Objekt
|
|
77
|
+
options // MiscMessageGenerationOptions (optional)
|
|
78
|
+
);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
| Typ | Beispiel-Content | Beispiel-Options |
|
|
82
|
+
| ------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------ |
|
|
83
|
+
| **Text** | `{ text: 'Hallo Welt!' }` | `{ quoted, mentions }` |
|
|
84
|
+
| **Bild** | `{ image:{ url:'./bild.png' }, caption:'Bild', viewOnce:true }` | `{ quoted }` |
|
|
85
|
+
| **Video** | `{ video:{ url:'./video.mp4' }, caption:'Video' }` | `{ }` |
|
|
86
|
+
| **GIF** | `{ video:{ url:'./gif.mp4' }, gifPlayback:true }` | `{ }` |
|
|
87
|
+
| **Audio** | `{ audio:{ url:'./test.ogg' }, mimetype:'audio/ogg', ptt:true }` | `{ quoted }` |
|
|
88
|
+
| **Dokument** | `{ document:{ url:'./doc.pdf', filename:'Doc.pdf' } }` | `{ }` |
|
|
89
|
+
| **Poll** | `{ pollCreationMessage:{ name:'Umfrage', options:[{name:'A'},{name:'B'}], selectableCount:1 } }` | `{ quoted }` |
|
|
90
|
+
| **React** | `{ react:{ text:'👍', key:msg.key } }` | `{ quoted }` |
|
|
91
|
+
| **Delete** | `{ delete: msg.key }` | `{ }` |
|
|
92
|
+
| **Pin** | `{ pin:{ type:1, time:3600, key:msg.key } }` | `{ }` |
|
|
93
|
+
| **Contacts** | `{ contacts:{ displayName:'Max', contacts:[{ vcard }] } }` | `{ }` |
|
|
94
|
+
| **Location** | `{ location:{ degreesLatitude:52.52, degreesLongitude:13.405 } }` | `{ }` |
|
|
95
|
+
| **Forward** | `{ forward: origMsg }` | `{ quoted }` |
|
|
96
|
+
| **Status** | `{ video:{ url:'story.mp4' }, caption:'Status' }` | `{ statusJidList:['...@s.whatsapp.net'] }` |
|
|
30
97
|
|
|
31
|
-
|
|
32
|
-
const paired = await wa.startSessionWithPairingCode('meineSession', { phoneNumber: '491234567890' });
|
|
98
|
+
---
|
|
33
99
|
|
|
34
|
-
|
|
35
|
-
const sessions = wa.getAllSession(); // z.B. ['meineSession']
|
|
100
|
+
## 🔄 Low-Level Relay (`relayMessage`)
|
|
36
101
|
|
|
37
|
-
|
|
38
|
-
const data = wa.getSession('meineSession');
|
|
102
|
+
Direktes Senden von XML-Stanzas. **Use Cases**:
|
|
39
103
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
104
|
+
### ProtocolMessage: Nachricht löschen (Revoke)
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
const deleteNode = { protocolMessage:{ key:{ remoteJid, fromMe:true, id:targetId }, type:7 } };
|
|
108
|
+
await wa.relayMessage(sessionId, remoteJid, deleteNode, { messageId: targetId });
|
|
43
109
|
```
|
|
44
110
|
|
|
45
|
-
|
|
111
|
+
### Ephemeral-Modus (Gruppen)
|
|
46
112
|
|
|
47
|
-
|
|
113
|
+
```js
|
|
114
|
+
await wa.relayMessage(sessionId, groupJid, { disappearingMessagesInChat: 86400 }, {});
|
|
115
|
+
await wa.relayMessage(sessionId, groupJid, { disappearingMessagesInChat: 0 }, {});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Status-Update (Story)
|
|
48
119
|
|
|
49
120
|
```js
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
'49123342524523@s.whatsapp.net', // JID oder Telefonnummer
|
|
53
|
-
content, // AnyMessageContent-Objekt
|
|
54
|
-
options // MiscMessageGenerationOptions (optional)
|
|
55
|
-
);
|
|
121
|
+
const node = { videoMessage:{ url:'./story.mp4' }, caption:'Meine Story' };
|
|
122
|
+
await wa.relayMessage(sessionId, 'status@broadcast', node, { statusJidList });
|
|
56
123
|
```
|
|
57
124
|
|
|
58
|
-
###
|
|
59
|
-
|
|
60
|
-
| Typ | content-Beispiel | optionale Flags | Beschreibung |
|
|
61
|
-
| ------------ | ----------------------------------------------------------------------------------------------- | ---------------------- | --------------------------------------------- |
|
|
62
|
-
| **Text** | `{ text: 'Hallo Welt!' }` | `{ quoted, mentions }` | Einfache Textnachricht |
|
|
63
|
-
| **Quote** | `{ text: 'Antwort...' }`, `options: { quoted: msgObj }` | | Text als Antwort (Quote) |
|
|
64
|
-
| **Mention** | `{ text: '@491234567890 Hallo' }`, `options: { mentions: ['491234567890@s.whatsapp.net'] }` | | Erwähnung in Text |
|
|
65
|
-
| **Bild** | `{ image: { url:'./bild.png' }, caption:'Bild', viewOnce:true }` | `viewOnce` | Bild senden; `viewOnce` für Einmaldarstellung |
|
|
66
|
-
| **Video** | `{ video: { url:'./video.mp4' }, caption:'Video', gifPlayback:true }` | `gifPlayback` | Video oder GIF (als MP4) |
|
|
67
|
-
| **Audio** | `{ audio: { url:'./audio.ogg' }, mimetype:'audio/ogg', ptt:true }` | `ptt` | Audio/Sprachnachricht |
|
|
68
|
-
| **Dokument** | `{ document: { url:'./doc.pdf', filename:'D.pdf' } }` | | Datei/Dokument |
|
|
69
|
-
| **Umfrage** | `{ poll: { name:'Umfrage?', values:['A','B'], selectableCount:1, toAnnouncementGroup:false } }` | | Neue Umfrage |
|
|
70
|
-
| **Reaktion** | `{ react: { text:'👍', key:msgObj.key } }` | | Nachricht mit Emoji reagieren |
|
|
71
|
-
| **Löschen** | `{ delete: msgObj.key }` | | Nachricht für alle löschen |
|
|
72
|
-
| **Pinning** | `{ pin: { type:1, time:86400, key:msgObj.key } }` | | Nachricht pinnen (1) oder entpinnen (0) |
|
|
73
|
-
| **Kontakte** | `{ contacts:{ displayName:'Max', contacts:[{ vcard }] } }` | | Kontaktkarte |
|
|
74
|
-
| **Standort** | `{ location:{ degreesLatitude:52.52, degreesLongitude:13.405 } }` | | Standort |
|
|
75
|
-
| **Weiterl.** | `{ forward: msgToForward }` | | Nachricht weiterleiten |
|
|
76
|
-
|
|
77
|
-
> **Hinweis:** Weitere Flags und Optionen (`edit`, `mentions`, `quoted`, etc.) können über das `options`-Objekt übergeben werden.
|
|
125
|
+
### Weiterleiten (Forward)
|
|
78
126
|
|
|
79
|
-
|
|
127
|
+
```js
|
|
128
|
+
const origMsg = getMessageFromStore();
|
|
129
|
+
const node = { forward: origMsg };
|
|
130
|
+
await wa.relayMessage(sessionId, chatJid, node, { messageId: origMsg.key.id });
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Profilbild aktualisieren
|
|
80
134
|
|
|
81
135
|
```js
|
|
82
|
-
|
|
83
|
-
wa.
|
|
136
|
+
const node = { profilePictureChange:{ displayPhoneNumber:true, displayName:true } };
|
|
137
|
+
await wa.relayMessage(sessionId, userJid, node, { messageId:'nishiProfPic' });
|
|
138
|
+
```
|
|
84
139
|
|
|
85
|
-
|
|
86
|
-
wa.onQRUpdated(({ sessionId, qr }) => console.log(`Scan QR (${sessionId}):`, qr));
|
|
140
|
+
### Chat als gelesen markieren
|
|
87
141
|
|
|
88
|
-
|
|
89
|
-
|
|
142
|
+
```js
|
|
143
|
+
const node = { protocolMessage:{ key:{ remoteJid:chatJid }, type:3 } };
|
|
144
|
+
await wa.relayMessage(sessionId, chatJid, node, { messageId:'nishiRead' });
|
|
90
145
|
```
|
|
91
146
|
|
|
92
|
-
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## 🎧 Listener
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
wa.onConnected(id => console.log('Online:', id));
|
|
153
|
+
wa.onQRUpdated(info => console.log('QR:', info));
|
|
154
|
+
wa.onMessageReceived(msg => console.log('Msg:', msg));
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
93
158
|
|
|
94
|
-
|
|
159
|
+
## ⚠️ Fehlerbehandlung
|
|
95
160
|
|
|
96
161
|
```js
|
|
97
162
|
try {
|
|
98
163
|
await wa.sendMessage(...);
|
|
99
164
|
} catch (e) {
|
|
100
|
-
if (e instanceof wa.WhatsappError)
|
|
101
|
-
console.error('WhatsApp-Fehler:', e.message);
|
|
102
|
-
}
|
|
165
|
+
if (e instanceof wa.WhatsappError) console.error(e.message);
|
|
103
166
|
}
|
|
104
167
|
```
|
|
105
168
|
|
|
106
169
|
---
|
|
107
170
|
|
|
108
|
-
|
|
171
|
+
## 🆘 Support
|
|
172
|
+
|
|
173
|
+
**E-Mail:** [sebloidl13@gmail.com](mailto:sebloidl13@gmail.com)
|
|
174
|
+
|
|
175
|
+
© 2025 `@deathnaitsa/wa-api`
|