whatsauto.js 0.0.1 → 0.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.
Files changed (59) hide show
  1. package/README.md +4 -0
  2. package/dist/Defaults/index.d.ts +2 -0
  3. package/dist/Defaults/index.d.ts.map +1 -1
  4. package/dist/Defaults/index.js +2 -0
  5. package/dist/WhatsApp/AutoWA.d.ts.map +1 -1
  6. package/dist/WhatsApp/AutoWA.js +41 -29
  7. package/dist/WhatsApp/AutoWAEvent.d.ts +10 -11
  8. package/dist/WhatsApp/AutoWAEvent.d.ts.map +1 -1
  9. package/dist/WhatsApp/AutoWAEvent.js +6 -0
  10. package/package.json +1 -1
  11. package/dist/Messaging/index.d.ts +0 -33
  12. package/dist/Messaging/index.d.ts.map +0 -1
  13. package/dist/Messaging/index.js +0 -245
  14. package/dist/Socket/index.d.ts +0 -29
  15. package/dist/Socket/index.d.ts.map +0 -1
  16. package/dist/Socket/index.js +0 -374
  17. package/dist/Utils/create-delay.d.ts +0 -2
  18. package/dist/Utils/create-delay.d.ts.map +0 -1
  19. package/dist/Utils/create-delay.js +0 -18
  20. package/dist/Utils/error.d.ts +0 -4
  21. package/dist/Utils/error.d.ts.map +0 -1
  22. package/dist/Utils/error.js +0 -8
  23. package/dist/Utils/is-exist.d.ts +0 -3
  24. package/dist/Utils/is-exist.d.ts.map +0 -1
  25. package/dist/Utils/is-exist.js +0 -38
  26. package/dist/Utils/message-status.d.ts +0 -4
  27. package/dist/Utils/message-status.d.ts.map +0 -1
  28. package/dist/Utils/message-status.js +0 -18
  29. package/dist/Utils/phone-to-jid.d.ts +0 -5
  30. package/dist/Utils/phone-to-jid.d.ts.map +0 -1
  31. package/dist/Utils/phone-to-jid.js +0 -30
  32. package/dist/Utils/save-media.d.ts +0 -5
  33. package/dist/Utils/save-media.d.ts.map +0 -1
  34. package/dist/Utils/save-media.js +0 -49
  35. package/dist/Utils/tools.d.ts +0 -12
  36. package/dist/Utils/tools.d.ts.map +0 -1
  37. package/dist/Utils/tools.js +0 -34
  38. package/dist/WhatsApp/action.d.ts +0 -1
  39. package/dist/WhatsApp/action.d.ts.map +0 -1
  40. package/dist/WhatsApp/action.js +0 -272
  41. package/dist/WhatsApp/auto-wa-event.d.ts +0 -26
  42. package/dist/WhatsApp/auto-wa-event.d.ts.map +0 -1
  43. package/dist/WhatsApp/auto-wa-event.js +0 -60
  44. package/dist/WhatsApp/auto-wa-manager.d.ts +0 -12
  45. package/dist/WhatsApp/auto-wa-manager.d.ts.map +0 -1
  46. package/dist/WhatsApp/auto-wa-manager.js +0 -68
  47. package/dist/WhatsApp/auto-wa.d.ts +0 -36
  48. package/dist/WhatsApp/auto-wa.d.ts.map +0 -1
  49. package/dist/WhatsApp/auto-wa.js +0 -497
  50. package/dist/WhatsApp/event.d.ts +0 -24
  51. package/dist/WhatsApp/event.d.ts.map +0 -1
  52. package/dist/WhatsApp/event.js +0 -54
  53. package/dist/WhatsApp/multi-auto-wa.d.ts +0 -14
  54. package/dist/WhatsApp/multi-auto-wa.d.ts.map +0 -1
  55. package/dist/WhatsApp/multi-auto-wa.js +0 -86
  56. package/dist/WhatsApp/setup.d.ts +0 -1
  57. package/dist/WhatsApp/setup.d.ts.map +0 -1
  58. package/dist/WhatsApp/setup.js +0 -221
  59. package/dist/WhatsApp/undefined.jpeg +0 -0
@@ -1,497 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __rest = (this && this.__rest) || function (s, e) {
45
- var t = {};
46
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
47
- t[p] = s[p];
48
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
49
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
50
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
51
- t[p[i]] = s[p[i]];
52
- }
53
- return t;
54
- };
55
- var __importDefault = (this && this.__importDefault) || function (mod) {
56
- return (mod && mod.__esModule) ? mod : { "default": mod };
57
- };
58
- Object.defineProperty(exports, "__esModule", { value: true });
59
- exports.AutoWA = void 0;
60
- const path_1 = __importDefault(require("path"));
61
- const fs_1 = __importDefault(require("fs"));
62
- const baileys_1 = __importStar(require("@whiskeysockets/baileys"));
63
- const Defaults_1 = require("../Defaults");
64
- const Error_1 = require("../Error");
65
- const Utils_1 = require("../Utils");
66
- const auto_wa_event_1 = __importDefault(require("./auto-wa-event"));
67
- const auto_wa_manager_1 = require("./auto-wa-manager");
68
- const mime_1 = __importDefault(require("mime"));
69
- const wa_sticker_formatter_1 = __importStar(require("wa-sticker-formatter"));
70
- const Logger_1 = __importDefault(require("../Logger"));
71
- const P = require("pino")({
72
- level: "fatal",
73
- });
74
- class AutoWA {
75
- constructor(sessionId, options = { printQR: true }, manager) {
76
- this.sessionId = sessionId;
77
- this.options = options;
78
- this.myManager = manager;
79
- this.callback = new Map();
80
- this.retryCount = 0;
81
- this.event = new auto_wa_event_1.default(this.callback);
82
- this.logger = new Logger_1.default("AutoWA");
83
- }
84
- initialize() {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- yield this.startWhatsApp(this.sessionId, this.options);
87
- });
88
- }
89
- startWhatsApp() {
90
- return __awaiter(this, arguments, void 0, function* (sessionId = "mySession", options = { printQR: true }) {
91
- if (this.myManager instanceof auto_wa_manager_1.AutoWAManager && this.myManager.isSessionExist(sessionId))
92
- throw new Error_1.ValidationError(Defaults_1.Messages.sessionAlreadyExist(sessionId));
93
- if (typeof options.phoneNumber == "string") {
94
- if (options.phoneNumber === "")
95
- throw new Error_1.ValidationError(Defaults_1.Messages.paremetersNotValid("phoneNumber"));
96
- options.printQR = false;
97
- options.phoneNumber = (0, Utils_1.phoneToJid)({
98
- to: options.phoneNumber,
99
- });
100
- }
101
- return this.startSocket(sessionId, options);
102
- });
103
- }
104
- startSocket(sessionId, options) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- const { version } = yield (0, baileys_1.fetchLatestBaileysVersion)();
107
- const { state, saveCreds } = yield (0, baileys_1.useMultiFileAuthState)(path_1.default.resolve(Defaults_1.CREDENTIALS.DIR_NAME, sessionId + Defaults_1.CREDENTIALS.PREFIX));
108
- this.sock = (0, baileys_1.default)({
109
- version,
110
- printQRInTerminal: options.printQR,
111
- auth: state,
112
- logger: P,
113
- markOnlineOnConnect: false,
114
- browser: baileys_1.Browsers.windows("Desktop"),
115
- });
116
- return this.setupWASocket(saveCreds);
117
- });
118
- }
119
- setupWASocket(saveCreds) {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- var _a, _b, _c;
122
- try {
123
- if (typeof this.options.phoneNumber == "string" &&
124
- !this.options.printQR &&
125
- !this.sock.authState.creds.registered) {
126
- let code = "";
127
- try {
128
- code = yield this.sock.requestPairingCode(this.options.phoneNumber);
129
- }
130
- catch (error) {
131
- this.logger.error(`Request Pair Code: ${error}`);
132
- let shouldRetry = false;
133
- if (this.retryCount < 10) {
134
- shouldRetry = true;
135
- }
136
- if (shouldRetry) {
137
- this.retryCount++;
138
- return this.startSocket(this.sessionId, this.options);
139
- }
140
- else {
141
- this.retryCount = 0;
142
- (_a = this.myManager) === null || _a === void 0 ? void 0 : _a.deleteSession(this.sessionId);
143
- (_b = this.callback.get(Defaults_1.CALLBACK_KEY.ON_DISCONNECTED)) === null || _b === void 0 ? void 0 : _b(this.sessionId);
144
- return;
145
- }
146
- }
147
- (_c = this.callback.get(Defaults_1.CALLBACK_KEY.ON_PAIRING_CODE)) === null || _c === void 0 ? void 0 : _c(this.sessionId, code);
148
- }
149
- this.sock.ev.on("connection.update", (update) => __awaiter(this, void 0, void 0, function* () {
150
- var _a, _b, _c, _d, _e, _f, _g;
151
- const { connection, lastDisconnect, qr } = update;
152
- if (this.options.printQR && qr) {
153
- (_a = this.callback.get(Defaults_1.CALLBACK_KEY.ON_QR)) === null || _a === void 0 ? void 0 : _a({ sessionId: this.sessionId, qr });
154
- }
155
- if (connection == "connecting") {
156
- (_b = this.callback.get(Defaults_1.CALLBACK_KEY.ON_CONNECTING)) === null || _b === void 0 ? void 0 : _b(this.sessionId);
157
- }
158
- if (connection === "close") {
159
- const code = (_d = (_c = lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error) === null || _c === void 0 ? void 0 : _c.output) === null || _d === void 0 ? void 0 : _d.statusCode;
160
- let shouldRetry = false;
161
- if (code != baileys_1.DisconnectReason.loggedOut && this.retryCount < 10) {
162
- shouldRetry = true;
163
- }
164
- if (shouldRetry) {
165
- this.retryCount++;
166
- return this.startSocket(this.sessionId, this.options);
167
- }
168
- else {
169
- this.retryCount = 0;
170
- (_e = this.myManager) === null || _e === void 0 ? void 0 : _e.deleteSession(this.sessionId);
171
- (_f = this.callback.get(Defaults_1.CALLBACK_KEY.ON_DISCONNECTED)) === null || _f === void 0 ? void 0 : _f(this.sessionId);
172
- return;
173
- }
174
- }
175
- if (connection == "open") {
176
- this.retryCount = 0;
177
- (_g = this.callback.get(Defaults_1.CALLBACK_KEY.ON_CONNECTED)) === null || _g === void 0 ? void 0 : _g(this.sessionId);
178
- }
179
- }));
180
- this.sock.ev.on("creds.update", () => __awaiter(this, void 0, void 0, function* () {
181
- yield saveCreds();
182
- }));
183
- this.sock.ev.on("messages.update", (message) => __awaiter(this, void 0, void 0, function* () {
184
- var _a;
185
- const msg = message[0];
186
- const data = Object.assign({ sessionId: this.sessionId, messageStatus: (0, Utils_1.parseMessageStatusCodeToReadable)(msg.update.status) }, msg);
187
- (_a = this.callback.get(Defaults_1.CALLBACK_KEY.ON_MESSAGE_UPDATED)) === null || _a === void 0 ? void 0 : _a(data);
188
- }));
189
- this.sock.ev.on("messages.upsert", (new_message) => __awaiter(this, void 0, void 0, function* () {
190
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
191
- let msg = (_a = new_message.messages) === null || _a === void 0 ? void 0 : _a[0];
192
- if ((_b = msg.message) === null || _b === void 0 ? void 0 : _b.documentWithCaptionMessage)
193
- msg = Object.assign(Object.assign({}, msg), { message: msg.message.documentWithCaptionMessage.message });
194
- msg.sessionId = this.sessionId;
195
- let quotedMessage = null;
196
- const msgContextInfo = ((_d = (_c = msg.message) === null || _c === void 0 ? void 0 : _c.extendedTextMessage) === null || _d === void 0 ? void 0 : _d.contextInfo) ||
197
- ((_f = (_e = msg.message) === null || _e === void 0 ? void 0 : _e.imageMessage) === null || _f === void 0 ? void 0 : _f.contextInfo) ||
198
- ((_h = (_g = msg.message) === null || _g === void 0 ? void 0 : _g.videoMessage) === null || _h === void 0 ? void 0 : _h.contextInfo) ||
199
- ((_k = (_j = msg.message) === null || _j === void 0 ? void 0 : _j.documentMessage) === null || _k === void 0 ? void 0 : _k.contextInfo);
200
- if (msgContextInfo === null || msgContextInfo === void 0 ? void 0 : msgContextInfo.quotedMessage) {
201
- quotedMessage = {
202
- key: {
203
- remoteJid: msgContextInfo === null || msgContextInfo === void 0 ? void 0 : msgContextInfo.participant,
204
- id: msgContextInfo === null || msgContextInfo === void 0 ? void 0 : msgContextInfo.stanzaId,
205
- },
206
- message: msgContextInfo === null || msgContextInfo === void 0 ? void 0 : msgContextInfo.quotedMessage,
207
- };
208
- }
209
- if ((_l = quotedMessage === null || quotedMessage === void 0 ? void 0 : quotedMessage.message) === null || _l === void 0 ? void 0 : _l.documentWithCaptionMessage) {
210
- quotedMessage = Object.assign(Object.assign({}, quotedMessage), { message: quotedMessage.message.documentWithCaptionMessage.message });
211
- }
212
- msg.quotedMessage = quotedMessage;
213
- msg.downloadQuotedMessageMedia = (path) => ((path) => __awaiter(this, void 0, void 0, function* () { return (path = ""); }))(path);
214
- if (msg.quotedMessage)
215
- msg.downloadQuotedMessageMedia = (path = "my_media") => this.downloadMedia(quotedMessage, path + "." + ext);
216
- const text = ((_m = msg.message) === null || _m === void 0 ? void 0 : _m.conversation) ||
217
- ((_p = (_o = msg.message) === null || _o === void 0 ? void 0 : _o.extendedTextMessage) === null || _p === void 0 ? void 0 : _p.text) ||
218
- ((_r = (_q = msg.message) === null || _q === void 0 ? void 0 : _q.imageMessage) === null || _r === void 0 ? void 0 : _r.caption) ||
219
- ((_t = (_s = msg.message) === null || _s === void 0 ? void 0 : _s.videoMessage) === null || _t === void 0 ? void 0 : _t.caption) ||
220
- ((_v = (_u = msg.message) === null || _u === void 0 ? void 0 : _u.documentMessage) === null || _v === void 0 ? void 0 : _v.caption) ||
221
- "";
222
- msg.text = text;
223
- const mediaTypes = ["image", "audio", "video", "document"];
224
- const mimeType = (0, Utils_1.getMediaMimeType)(msg);
225
- const ext = mime_1.default.getExtension(mimeType);
226
- msg.hasMedia = mimeType !== "";
227
- msg.mediaType = "";
228
- if (mimeType)
229
- msg.mediaType =
230
- mediaTypes[mediaTypes.indexOf(mimeType.split("/")[0]) !== -1
231
- ? mediaTypes.indexOf(mimeType.split("/")[0])
232
- : 3];
233
- msg.downloadMedia = (path) => ((path) => __awaiter(this, void 0, void 0, function* () { return (path = ""); }))(path);
234
- if (msg.hasMedia)
235
- msg.downloadMedia = (path = "my_media") => this.downloadMedia(msg, path + "." + ext);
236
- const from = msg.key.remoteJid || "";
237
- const participant = msg.key.participant || "";
238
- const isGroup = from.includes("@g.us");
239
- const isStory = from.includes("status@broadcast");
240
- const isReaction = (_w = msg.message) === null || _w === void 0 ? void 0 : _w.reactionMessage;
241
- const myJid = (0, Utils_1.phoneToJid)({ to: this.sock.user.id.split(":")[0] });
242
- msg.author = from;
243
- if (isStory || isGroup)
244
- msg.author = participant;
245
- (_x = this.callback.get(Defaults_1.CALLBACK_KEY.ON_MESSAGE)) === null || _x === void 0 ? void 0 : _x(msg);
246
- if (isStory) {
247
- if ((_y = msg.key) === null || _y === void 0 ? void 0 : _y.fromMe)
248
- (_z = this.callback.get(Defaults_1.CALLBACK_KEY.ON_STORY_SENT)) === null || _z === void 0 ? void 0 : _z(msg);
249
- else
250
- (_0 = this.callback.get(Defaults_1.CALLBACK_KEY.ON_STORY_RECEIVED)) === null || _0 === void 0 ? void 0 : _0(msg);
251
- return;
252
- }
253
- // if (isReaction) return;
254
- if (isGroup) {
255
- (_1 = this.callback.get(Defaults_1.CALLBACK_KEY.ON_GROUP_MESSAGE)) === null || _1 === void 0 ? void 0 : _1(msg);
256
- }
257
- else {
258
- (_2 = this.callback.get(Defaults_1.CALLBACK_KEY.ON_PRIVATE_MESSAGE)) === null || _2 === void 0 ? void 0 : _2(msg);
259
- }
260
- if (msg.key.fromMe) {
261
- msg = Object.assign(Object.assign({}, msg), { receiver: from, author: myJid });
262
- (_3 = this.callback.get(Defaults_1.CALLBACK_KEY.ON_MESSAGE_SENT)) === null || _3 === void 0 ? void 0 : _3(msg);
263
- if (isGroup) {
264
- (_4 = this.callback.get(Defaults_1.CALLBACK_KEY.ON_GROUP_MESSAGE_SENT)) === null || _4 === void 0 ? void 0 : _4(Object.assign({}, msg));
265
- }
266
- else {
267
- (_5 = this.callback.get(Defaults_1.CALLBACK_KEY.ON_PRIVATE_MESSAGE_SENT)) === null || _5 === void 0 ? void 0 : _5(Object.assign({}, msg));
268
- }
269
- }
270
- else {
271
- msg = Object.assign(Object.assign({}, msg), { from });
272
- if (isStory)
273
- msg.from = participant;
274
- (_6 = this.callback.get(Defaults_1.CALLBACK_KEY.ON_MESSAGE_RECEIVED)) === null || _6 === void 0 ? void 0 : _6(msg);
275
- if (isGroup) {
276
- (_7 = this.callback.get(Defaults_1.CALLBACK_KEY.ON_GROUP_MESSAGE_RECEIVED)) === null || _7 === void 0 ? void 0 : _7(Object.assign({}, msg));
277
- }
278
- else {
279
- (_8 = this.callback.get(Defaults_1.CALLBACK_KEY.ON_PRIVATE_MESSAGE_RECEIVED)) === null || _8 === void 0 ? void 0 : _8(Object.assign({}, msg));
280
- }
281
- }
282
- }));
283
- return this.sock;
284
- }
285
- catch (error) {
286
- throw error;
287
- }
288
- });
289
- }
290
- logout() {
291
- return __awaiter(this, void 0, void 0, function* () {
292
- return yield this.sock.logout();
293
- });
294
- }
295
- end() {
296
- return this.sock.end(undefined);
297
- }
298
- isExist(_a) {
299
- return __awaiter(this, arguments, void 0, function* ({ to, isGroup = false }) {
300
- var _b, _c;
301
- try {
302
- const receiver = (0, Utils_1.phoneToJid)({
303
- to: to,
304
- isGroup: isGroup,
305
- });
306
- if (!isGroup) {
307
- const one = Boolean((_c = (_b = (yield this.sock.onWhatsApp(receiver))) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.exists);
308
- return one;
309
- }
310
- else {
311
- return Boolean((yield this.sock.groupMetadata(receiver)).id);
312
- }
313
- }
314
- catch (error) {
315
- throw error;
316
- }
317
- });
318
- }
319
- downloadMedia(msg, mediaPath) {
320
- return __awaiter(this, void 0, void 0, function* () {
321
- const filePath = path_1.default.join(process.cwd(), mediaPath);
322
- const buf = yield (0, baileys_1.downloadMediaMessage)(msg, "buffer", {});
323
- fs_1.default.writeFileSync(filePath, buf.toString("base64"), "base64");
324
- return Promise.resolve(filePath);
325
- });
326
- }
327
- validateReceiver(_a) {
328
- return __awaiter(this, arguments, void 0, function* ({ to, isGroup = false }) {
329
- const oldPhone = to;
330
- to = (0, Utils_1.phoneToJid)({ to, isGroup });
331
- const isRegistered = yield this.isExist({
332
- to,
333
- isGroup,
334
- });
335
- if (!isRegistered) {
336
- return {
337
- msg: `${oldPhone} is not registered on Whatsapp`,
338
- };
339
- }
340
- return {
341
- receiver: to,
342
- };
343
- });
344
- }
345
- sendTextMessage(_a) {
346
- return __awaiter(this, void 0, void 0, function* () {
347
- var { to, text = "", isGroup = false } = _a, props = __rest(_a, ["to", "text", "isGroup"]);
348
- const { receiver, msg } = yield this.validateReceiver({
349
- to,
350
- isGroup,
351
- });
352
- if (msg)
353
- throw new Error_1.WhatsAppError(msg);
354
- return yield this.sock.sendMessage(receiver, {
355
- text: text,
356
- }, {
357
- quoted: props.answering,
358
- });
359
- });
360
- }
361
- sendImage(_a) {
362
- return __awaiter(this, void 0, void 0, function* () {
363
- var { to, text = "", isGroup = false, media } = _a, props = __rest(_a, ["to", "text", "isGroup", "media"]);
364
- if (!media)
365
- throw new Error_1.WhatsAppError("parameter media must be Buffer or String URL");
366
- const { receiver, msg } = yield this.validateReceiver({
367
- to,
368
- isGroup,
369
- });
370
- if (msg)
371
- throw new Error_1.WhatsAppError(msg);
372
- return yield this.sock.sendMessage(receiver, {
373
- image: typeof media == "string"
374
- ? {
375
- url: media,
376
- }
377
- : media,
378
- caption: text,
379
- }, {
380
- quoted: props.answering,
381
- });
382
- });
383
- }
384
- sendVideo(_a) {
385
- return __awaiter(this, void 0, void 0, function* () {
386
- var { to, text = "", isGroup = false, media } = _a, props = __rest(_a, ["to", "text", "isGroup", "media"]);
387
- if (!media)
388
- throw new Error_1.WhatsAppError("parameter media must be Buffer or String URL");
389
- const { receiver, msg } = yield this.validateReceiver({
390
- to,
391
- isGroup,
392
- });
393
- if (msg)
394
- throw new Error_1.WhatsAppError(msg);
395
- return yield this.sock.sendMessage(receiver, {
396
- video: typeof media == "string"
397
- ? {
398
- url: media,
399
- }
400
- : media,
401
- caption: text,
402
- }, {
403
- quoted: props.answering,
404
- });
405
- });
406
- }
407
- sendDocument(_a) {
408
- return __awaiter(this, void 0, void 0, function* () {
409
- var { to, text = "", isGroup = false, media, filename } = _a, props = __rest(_a, ["to", "text", "isGroup", "media", "filename"]);
410
- if (!media)
411
- throw new Error_1.WhatsAppError("parameter media must be Buffer or String URL");
412
- const mimetype = mime_1.default.getType(filename);
413
- if (!mimetype)
414
- throw new Error_1.WhatsAppError(`Filename must include valid extension`);
415
- const { receiver, msg } = yield this.validateReceiver({
416
- to,
417
- isGroup,
418
- });
419
- if (msg)
420
- throw new Error_1.WhatsAppError(msg);
421
- return yield this.sock.sendMessage(receiver, {
422
- fileName: filename,
423
- document: typeof media == "string"
424
- ? {
425
- url: media,
426
- }
427
- : media,
428
- mimetype: mimetype,
429
- caption: text,
430
- }, {
431
- quoted: props.answering,
432
- });
433
- });
434
- }
435
- sendVoiceNote(_a) {
436
- return __awaiter(this, void 0, void 0, function* () {
437
- var { to, isGroup = false, media } = _a, props = __rest(_a, ["to", "isGroup", "media"]);
438
- if (!media)
439
- throw new Error_1.WhatsAppError("parameter media must be Buffer or String URL");
440
- const { receiver, msg } = yield this.validateReceiver({
441
- to,
442
- isGroup,
443
- });
444
- if (msg)
445
- throw new Error_1.WhatsAppError(msg);
446
- return yield this.sock.sendMessage(receiver, {
447
- audio: typeof media == "string"
448
- ? {
449
- url: media,
450
- }
451
- : media,
452
- ptt: true,
453
- }, {
454
- quoted: props.answering,
455
- });
456
- });
457
- }
458
- sendSticker(_a) {
459
- return __awaiter(this, void 0, void 0, function* () {
460
- var { to, isGroup, media, pack = "WhatsAuto.js", author = "freack21", type = wa_sticker_formatter_1.StickerTypes.DEFAULT, categories = ["❤️"], quality = 100 } = _a, props = __rest(_a, ["to", "isGroup", "media", "pack", "author", "type", "categories", "quality"]);
461
- if (!media)
462
- throw new Error_1.WhatsAppError("parameter media must be Buffer or String URL");
463
- const { receiver, msg } = yield this.validateReceiver({
464
- to,
465
- isGroup,
466
- });
467
- if (msg)
468
- throw new Error_1.WhatsAppError(msg);
469
- const sticker = new wa_sticker_formatter_1.default(media, Object.assign({ pack,
470
- author,
471
- type,
472
- categories }, props));
473
- return yield this.sock.sendMessage(receiver, yield sticker.toMessage(), {
474
- quoted: props.answering,
475
- });
476
- });
477
- }
478
- sendTyping(_a) {
479
- return __awaiter(this, arguments, void 0, function* ({ to, duration = 1000, isGroup = false }) {
480
- const { receiver, msg } = yield this.validateReceiver({
481
- to,
482
- isGroup,
483
- });
484
- if (msg)
485
- throw new Error_1.WhatsAppError(msg);
486
- yield this.sock.sendPresenceUpdate("composing", receiver);
487
- yield (0, Utils_1.createDelay)(duration);
488
- yield this.sock.sendPresenceUpdate("available", receiver);
489
- });
490
- }
491
- readMessage(_a) {
492
- return __awaiter(this, arguments, void 0, function* ({ key }) {
493
- yield this.sock.readMessages([key]);
494
- });
495
- }
496
- }
497
- exports.AutoWA = AutoWA;
@@ -1,24 +0,0 @@
1
- import { MessageReceived, MessageUpdated } from "../Types";
2
- export default class Event {
3
- private callback;
4
- constructor(callback: Map<string, Function>);
5
- onMessage: (listener: (msg: MessageReceived) => any) => void;
6
- onGroupMessage: (listener: (msg: MessageReceived) => any) => void;
7
- onPrivateMessage: (listener: (msg: MessageReceived) => any) => void;
8
- onMessageReceived: (listener: (msg: MessageReceived) => any) => void;
9
- onGroupMessageReceived: (listener: (msg: MessageReceived) => any) => void;
10
- onPrivateMessageReceived: (listener: (msg: MessageReceived) => any) => void;
11
- onMessageSent: (listener: (msg: MessageReceived) => any) => void;
12
- onGroupMessageSent: (listener: (msg: MessageReceived) => any) => void;
13
- onPrivateMessageSent: (listener: (msg: MessageReceived) => any) => void;
14
- onQRUpdated: (listener: ({ sessionId, qr }: {
15
- sessionId: string;
16
- qr: string;
17
- }) => any) => void;
18
- onConnected: (listener: (sessionId: string) => any) => void;
19
- onDisconnected: (listener: (sessionId: string) => any) => void;
20
- onConnecting: (listener: (sessionId: string) => any) => void;
21
- onMessageUpdate: (listener: (data: MessageUpdated) => any) => void;
22
- onPairingCode: (listener: (sessionId: string, code: string) => any) => void;
23
- }
24
- //# sourceMappingURL=event.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/WhatsApp/event.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE3D,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB,OAAO,CAAC,QAAQ,CAAwB;gBAE5B,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;IAI3C,SAAS,aAAc,CAAC,GAAG,EAAE,eAAe,KAAK,GAAG,UAElD;IAEF,cAAc,aAAc,CAAC,GAAG,EAAE,eAAe,KAAK,GAAG,UAEvD;IAEF,gBAAgB,aAAc,CAAC,GAAG,EAAE,eAAe,KAAK,GAAG,UAEzD;IAEF,iBAAiB,aAAc,CAAC,GAAG,EAAE,eAAe,KAAK,GAAG,UAE1D;IAEF,sBAAsB,aAAc,CAAC,GAAG,EAAE,eAAe,KAAK,GAAG,UAE/D;IAEF,wBAAwB,aAAc,CAAC,GAAG,EAAE,eAAe,KAAK,GAAG,UAEjE;IAEF,aAAa,aAAc,CAAC,GAAG,EAAE,eAAe,KAAK,GAAG,UAEtD;IAEF,kBAAkB,aAAc,CAAC,GAAG,EAAE,eAAe,KAAK,GAAG,UAE3D;IAEF,oBAAoB,aAAc,CAAC,GAAG,EAAE,eAAe,KAAK,GAAG,UAE7D;IAEF,WAAW,aAAc,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,KAAK,GAAG,UAEpF;IAEF,WAAW,aAAc,CAAC,SAAS,EAAE,MAAM,KAAK,GAAG,UAEjD;IAEF,cAAc,aAAc,CAAC,SAAS,EAAE,MAAM,KAAK,GAAG,UAEpD;IAEF,YAAY,aAAc,CAAC,SAAS,EAAE,MAAM,KAAK,GAAG,UAElD;IAEF,eAAe,aAAc,CAAC,IAAI,EAAE,cAAc,KAAK,GAAG,UAExD;IAEF,aAAa,aAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,GAAG,UAEjE;CACH"}
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Defaults_1 = require("../Defaults");
4
- class Event {
5
- constructor(callback) {
6
- this.onMessage = (listener) => {
7
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_MESSAGE, listener);
8
- };
9
- this.onGroupMessage = (listener) => {
10
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_GROUP_MESSAGE, listener);
11
- };
12
- this.onPrivateMessage = (listener) => {
13
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_PRIVATE_MESSAGE, listener);
14
- };
15
- this.onMessageReceived = (listener) => {
16
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_MESSAGE_RECEIVED, listener);
17
- };
18
- this.onGroupMessageReceived = (listener) => {
19
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_GROUP_MESSAGE_RECEIVED, listener);
20
- };
21
- this.onPrivateMessageReceived = (listener) => {
22
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_PRIVATE_MESSAGE_RECEIVED, listener);
23
- };
24
- this.onMessageSent = (listener) => {
25
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_MESSAGE_SENT, listener);
26
- };
27
- this.onGroupMessageSent = (listener) => {
28
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_GROUP_MESSAGE_SENT, listener);
29
- };
30
- this.onPrivateMessageSent = (listener) => {
31
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_PRIVATE_MESSAGE_SENT, listener);
32
- };
33
- this.onQRUpdated = (listener) => {
34
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_QR, listener);
35
- };
36
- this.onConnected = (listener) => {
37
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_CONNECTED, listener);
38
- };
39
- this.onDisconnected = (listener) => {
40
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_DISCONNECTED, listener);
41
- };
42
- this.onConnecting = (listener) => {
43
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_CONNECTING, listener);
44
- };
45
- this.onMessageUpdate = (listener) => {
46
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_MESSAGE_UPDATED, listener);
47
- };
48
- this.onPairingCode = (listener) => {
49
- this.callback.set(Defaults_1.CALLBACK_KEY.ON_PAIRING_CODE, listener);
50
- };
51
- this.callback = callback;
52
- }
53
- }
54
- exports.default = Event;
@@ -1,14 +0,0 @@
1
- import { AutoWA } from "./auto-wa";
2
- import { StartWhatsAppParams } from "../Types";
3
- export declare class MultiAutoWA {
4
- private sessions;
5
- saveSessions(autoWAs: AutoWA[]): void;
6
- saveSession(autoWA: AutoWA): void;
7
- private shouldLoadSession;
8
- isSessionExistAndRunning(sessionId: string): boolean;
9
- startSessions(options: StartWhatsAppParams): void;
10
- deleteSession(sessionId: string): Promise<void>;
11
- getSessions(): string[];
12
- getSession(sessionId: string): AutoWA;
13
- }
14
- //# sourceMappingURL=multi-auto-wa.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multi-auto-wa.d.ts","sourceRoot":"","sources":["../../src/WhatsApp/multi-auto-wa.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAsB;IAE/B,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE;IAM9B,WAAW,CAAC,MAAM,EAAE,MAAM;IAIjC,OAAO,CAAC,iBAAiB;IAYlB,wBAAwB,CAAC,SAAS,EAAE,MAAM;IAY1C,aAAa,CAAC,OAAO,EAAE,mBAAmB;IAiBpC,aAAa,CAAC,SAAS,EAAE,MAAM;IAarC,WAAW;IAIX,UAAU,CAAC,SAAS,EAAE,MAAM;CAGpC"}