@deathnaitsa/wa-api 1.0.11 → 1.0.13
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 +161 -60
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.13",
|
|
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,108 +1,209 @@
|
|
|
1
1
|
# wa-api
|
|
2
2
|
|
|
3
|
-
Leichte Bibliothek zur Verwaltung mehrerer WhatsApp-Sessions – mit **einer** universellen `sendMessage`-Funktion für
|
|
3
|
+
Leichte Bibliothek zur Verwaltung mehrerer WhatsApp-Sessions – mit **einer** universellen `sendMessage`-Funktion und direkter `relayMessage`-Unterstützung für alle fortgeschrittenen Szenarien.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📑 Inhaltsverzeichnis
|
|
8
|
+
|
|
9
|
+
1. [Installation](#installation)
|
|
10
|
+
2. [Import & Setup](#import--setup)
|
|
11
|
+
3. [Session Management](#session-management)
|
|
12
|
+
4. [Nachrichten senden via `sendMessage`](#nachrichten-senden-via-sendmessage)
|
|
13
|
+
5. [Low-level `relayMessage` Beispiele](#low-level-relaymessage-beispiele)
|
|
14
|
+
|
|
15
|
+
* [ProtocolMessage: Nachricht löschen (Revoke)](#protocolmessage-nachricht-löschen-revoke)
|
|
16
|
+
* [Ephemeral-Modus (Gruppen)](#ephemeral-modus-gruppen)
|
|
17
|
+
* [Status-Update (Story)](#status-update-story)
|
|
18
|
+
* [Weiterleiten (Forward)](#weiterleiten-forward)
|
|
19
|
+
* [Profilbild aktualisieren](#profilbild-aktualisieren)
|
|
20
|
+
* [Chat als gelesen markieren](#chat-als-gelesen-markieren)
|
|
21
|
+
6. [Listener](#listener)
|
|
22
|
+
7. [Fehlerbehandlung](#fehlerbehandlung)
|
|
23
|
+
|
|
24
|
+
---
|
|
4
25
|
|
|
5
26
|
## 📦 Installation
|
|
6
27
|
|
|
7
28
|
```bash
|
|
8
|
-
npm install @deathnaitsa/
|
|
29
|
+
npm install @deathnaitsa/wa-api@latest
|
|
9
30
|
```
|
|
10
31
|
|
|
11
32
|
## 🔌 Import & Setup
|
|
12
33
|
|
|
13
|
-
Verwende den klassischen Import-Stil:
|
|
14
|
-
|
|
15
34
|
```js
|
|
16
35
|
// CommonJS
|
|
17
|
-
const wa = require('@deathnaitsa/
|
|
36
|
+
const wa = require('@deathnaitsa/wa-api');
|
|
18
37
|
|
|
19
38
|
// ES Module
|
|
20
|
-
import * as wa from '@deathnaitsa/
|
|
39
|
+
import * as wa from '@deathnaitsa/wa-api';
|
|
21
40
|
```
|
|
22
41
|
|
|
23
|
-
Danach stehen dir alle Funktionen unter dem Namespace `wa` zur Verfügung.
|
|
24
|
-
|
|
25
42
|
## 🚀 Session Management
|
|
26
43
|
|
|
27
44
|
```js
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
await wa.startSession('session1');
|
|
46
|
+
await wa.startSessionWithPairingCode('session2', { phoneNumber: '491234567890' });
|
|
47
|
+
const all = wa.getAllSession();
|
|
48
|
+
const one = wa.getSession('session1');
|
|
49
|
+
const loaded = await wa.loadSessionsFromStorage();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 💬 Nachrichten senden via `sendMessage`
|
|
53
|
+
|
|
54
|
+
Eine **zentrale** Funktion für **alle** Nachrichtentypen:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
await wa.sendMessage(
|
|
58
|
+
sessionId, // Session-ID
|
|
59
|
+
jidOrPhone, // JID oder Telefonnummer
|
|
60
|
+
content, // AnyMessageContent
|
|
61
|
+
options // MiscMessageGenerationOptions
|
|
62
|
+
);
|
|
63
|
+
```
|
|
30
64
|
|
|
31
|
-
|
|
32
|
-
|
|
65
|
+
### Beispiele
|
|
66
|
+
|
|
67
|
+
| Typ | Kurzbeschreibung | content | options |
|
|
68
|
+
| -------------- | -------------------------- | -------------------------------------------------------------------------------------------- | ----------------------------- |
|
|
69
|
+
| Text | Normale Textnachricht | `{ text: 'Hallo Welt!' }` | `{ quoted, mentions }` |
|
|
70
|
+
| Bild | Sende Bild | `{ image:{url:'./img.png'},caption:'Bild',viewOnce:true }` | `{ quoted }` |
|
|
71
|
+
| Video | Sende Video | `{ video:{url:'./vid.mp4'},caption:'Video' }` | `{ }` |
|
|
72
|
+
| GIF | Sende GIF (MP4 + Playback) | `{ video:{url:'./gif.mp4'},gifPlayback:true }` | `{ }` |
|
|
73
|
+
| Audio | Voice Note (OGG/Opus) | `{ audio: fs.createReadStream('test.ogg'),mimetype:'audio/ogg',ptt:true }` | `{ quoted }` |
|
|
74
|
+
| Dokument | Datei | `{ document:{url:'./doc.pdf',filename:'Doc.pdf'} }` | `{ }` |
|
|
75
|
+
| Poll | Umfrage | `{ pollCreationMessage:{name:'Umfrage',options:[{name:'A'},{name:'B'}],selectableCount:1} }` | `{ quoted }` |
|
|
76
|
+
| React | Emoji-Reaktion | `{ react:{text:'👍',key:msg.key} }` | `{ quoted }` |
|
|
77
|
+
| Delete | Löschen (Revoke) | `{ delete: msg.key }` | `{ }` |
|
|
78
|
+
| Pin | Pin/Unpin | `{ pin:{type:1,time:3600,key:msg.key} }` | `{ }` |
|
|
79
|
+
| Contacts | Kontaktkarte | `{ contacts:{displayName:'Max',contacts:[{vcard}] } }` | `{ }` |
|
|
80
|
+
| Location | Standort | `{ location:{degreesLatitude:52.52,degreesLongitude:13.405} }` | `{ }` |
|
|
81
|
+
| Forward | Weiterleiten | `{ forward: origMsg }` | `{ quoted }` |
|
|
82
|
+
| Status (Story) | Status-Update | `{ video:{url:'story.mp4'},caption:'Status' }` | `{ statusJidList:[...JIDs] }` |
|
|
33
83
|
|
|
34
|
-
|
|
35
|
-
const sessions = wa.getAllSession(); // z.B. ['meineSession']
|
|
84
|
+
---
|
|
36
85
|
|
|
37
|
-
|
|
38
|
-
const data = wa.getSession('meineSession');
|
|
86
|
+
## 🔄 Low-level `relayMessage` Beispiele
|
|
39
87
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
88
|
+
Direktes Senden von WAMessage-Stanzas für Spezialfälle.
|
|
89
|
+
|
|
90
|
+
### ProtocolMessage: Nachricht löschen (Revoke)
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
const deleteNode = {
|
|
94
|
+
protocolMessage: {
|
|
95
|
+
key: { remoteJid: chatJid, fromMe: true, id: targetId },
|
|
96
|
+
type: 7 // MESSAGE_REVOKE
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
await wa.relayMessage(
|
|
100
|
+
sessionId,
|
|
101
|
+
chatJid,
|
|
102
|
+
deleteNode,
|
|
103
|
+
{ messageId: targetId }
|
|
104
|
+
);
|
|
43
105
|
```
|
|
44
106
|
|
|
45
|
-
|
|
107
|
+
### Ephemeral-Modus (Gruppen)
|
|
46
108
|
|
|
47
|
-
|
|
109
|
+
```js
|
|
110
|
+
// 24h Ephemeral ein
|
|
111
|
+
await wa.relayMessage(
|
|
112
|
+
sessionId,
|
|
113
|
+
groupJid,
|
|
114
|
+
{ disappearingMessagesInChat: Defaults.WA_DEFAULT_EPHEMERAL },
|
|
115
|
+
{}
|
|
116
|
+
);
|
|
117
|
+
// Ephemeral aus
|
|
118
|
+
await wa.relayMessage(
|
|
119
|
+
sessionId,
|
|
120
|
+
groupJid,
|
|
121
|
+
{ disappearingMessagesInChat: 0 },
|
|
122
|
+
{}
|
|
123
|
+
);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Status-Update (Story)
|
|
48
127
|
|
|
49
128
|
```js
|
|
50
|
-
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
|
|
54
|
-
|
|
129
|
+
const storyNode = {
|
|
130
|
+
videoMessage: { url: './story.mp4' },
|
|
131
|
+
caption: 'Meine Story'
|
|
132
|
+
};
|
|
133
|
+
await wa.relayMessage(
|
|
134
|
+
sessionId,
|
|
135
|
+
'status@broadcast',
|
|
136
|
+
storyNode,
|
|
137
|
+
{ statusJidList: ['491234567890@s.whatsapp.net'] }
|
|
55
138
|
);
|
|
56
139
|
```
|
|
57
140
|
|
|
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.
|
|
141
|
+
### Weiterleiten (Forward)
|
|
78
142
|
|
|
79
|
-
|
|
143
|
+
```js
|
|
144
|
+
const origMsg = getMessageFromStore();
|
|
145
|
+
const forwardNode = { forward: origMsg };
|
|
146
|
+
await wa.relayMessage(
|
|
147
|
+
sessionId,
|
|
148
|
+
chatJid,
|
|
149
|
+
forwardNode,
|
|
150
|
+
{ messageId: origMsg.key.id }
|
|
151
|
+
);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Profilbild aktualisieren
|
|
80
155
|
|
|
81
156
|
```js
|
|
82
|
-
|
|
83
|
-
|
|
157
|
+
const updateNode = {
|
|
158
|
+
profilePictureChange: {
|
|
159
|
+
displayPicture: fs.readFileSync('./newprofile.jpg')
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
await wa.relayMessage(
|
|
163
|
+
sessionId,
|
|
164
|
+
userJid,
|
|
165
|
+
updateNode,
|
|
166
|
+
{ messageId: 'nishiProfileUpdate' }
|
|
167
|
+
);
|
|
168
|
+
```
|
|
84
169
|
|
|
85
|
-
|
|
86
|
-
wa.onQRUpdated(({ sessionId, qr }) => console.log(`Scan QR (${sessionId}):`, qr));
|
|
170
|
+
### Chat als gelesen markieren
|
|
87
171
|
|
|
88
|
-
|
|
89
|
-
|
|
172
|
+
```js
|
|
173
|
+
const readNode = {
|
|
174
|
+
protocolMessage: {
|
|
175
|
+
key: { remoteJid: chatJid },
|
|
176
|
+
type: 3 // READ
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
await wa.relayMessage(
|
|
180
|
+
sessionId,
|
|
181
|
+
chatJid,
|
|
182
|
+
readNode,
|
|
183
|
+
{ messageId: 'nishiMarkRead' }
|
|
184
|
+
);
|
|
90
185
|
```
|
|
91
186
|
|
|
92
|
-
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## 🎧 Listener
|
|
190
|
+
|
|
191
|
+
```js
|
|
192
|
+
wa.onConnected(id => console.log('Online:', id));
|
|
193
|
+
wa.onQRUpdated(info => console.log('QR:', info));
|
|
194
|
+
wa.onMessageReceived(msg => console.log('Nachricht:', msg));
|
|
195
|
+
```
|
|
93
196
|
|
|
94
|
-
|
|
197
|
+
## ⚠️ Fehlerbehandlung
|
|
95
198
|
|
|
96
199
|
```js
|
|
97
200
|
try {
|
|
98
201
|
await wa.sendMessage(...);
|
|
99
|
-
} catch
|
|
100
|
-
|
|
101
|
-
console.error('WhatsApp-Fehler:', e.message);
|
|
102
|
-
}
|
|
202
|
+
} catch(e) {
|
|
203
|
+
console.error(e);
|
|
103
204
|
}
|
|
104
205
|
```
|
|
105
206
|
|
|
106
207
|
---
|
|
107
208
|
|
|
108
|
-
© 2025 `@deathnaitsa/
|
|
209
|
+
© 2025 `@deathnaitsa/wa-api` • Support: [sebloidl13@gmail.com](mailto:sebloidl13@gmail.com)
|