whatsauto.js 0.0.0

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 (87) hide show
  1. package/README.md +37 -0
  2. package/dist/Defaults/index.d.ts +32 -0
  3. package/dist/Defaults/index.d.ts.map +1 -0
  4. package/dist/Defaults/index.js +37 -0
  5. package/dist/Error/index.d.ts +9 -0
  6. package/dist/Error/index.d.ts.map +1 -0
  7. package/dist/Error/index.js +25 -0
  8. package/dist/Logger/index.d.ts +8 -0
  9. package/dist/Logger/index.d.ts.map +1 -0
  10. package/dist/Logger/index.js +17 -0
  11. package/dist/Messaging/index.d.ts +33 -0
  12. package/dist/Messaging/index.d.ts.map +1 -0
  13. package/dist/Messaging/index.js +245 -0
  14. package/dist/Socket/index.d.ts +29 -0
  15. package/dist/Socket/index.d.ts.map +1 -0
  16. package/dist/Socket/index.js +374 -0
  17. package/dist/Types/index.d.ts +89 -0
  18. package/dist/Types/index.d.ts.map +1 -0
  19. package/dist/Types/index.js +2 -0
  20. package/dist/Utils/create-delay.d.ts +2 -0
  21. package/dist/Utils/create-delay.d.ts.map +1 -0
  22. package/dist/Utils/create-delay.js +18 -0
  23. package/dist/Utils/error.d.ts +4 -0
  24. package/dist/Utils/error.d.ts.map +1 -0
  25. package/dist/Utils/error.js +8 -0
  26. package/dist/Utils/helper.d.ts +22 -0
  27. package/dist/Utils/helper.d.ts.map +1 -0
  28. package/dist/Utils/helper.js +129 -0
  29. package/dist/Utils/index.d.ts +3 -0
  30. package/dist/Utils/index.d.ts.map +1 -0
  31. package/dist/Utils/index.js +18 -0
  32. package/dist/Utils/is-exist.d.ts +3 -0
  33. package/dist/Utils/is-exist.d.ts.map +1 -0
  34. package/dist/Utils/is-exist.js +38 -0
  35. package/dist/Utils/message-status.d.ts +4 -0
  36. package/dist/Utils/message-status.d.ts.map +1 -0
  37. package/dist/Utils/message-status.js +18 -0
  38. package/dist/Utils/phone-to-jid.d.ts +5 -0
  39. package/dist/Utils/phone-to-jid.d.ts.map +1 -0
  40. package/dist/Utils/phone-to-jid.js +30 -0
  41. package/dist/Utils/save-media.d.ts +5 -0
  42. package/dist/Utils/save-media.d.ts.map +1 -0
  43. package/dist/Utils/save-media.js +49 -0
  44. package/dist/Utils/set-credentials-dir.d.ts +3 -0
  45. package/dist/Utils/set-credentials-dir.d.ts.map +1 -0
  46. package/dist/Utils/set-credentials-dir.js +14 -0
  47. package/dist/Utils/tools.d.ts +12 -0
  48. package/dist/Utils/tools.d.ts.map +1 -0
  49. package/dist/Utils/tools.js +34 -0
  50. package/dist/WhatsApp/AutoWA.d.ts +38 -0
  51. package/dist/WhatsApp/AutoWA.d.ts.map +1 -0
  52. package/dist/WhatsApp/AutoWA.js +545 -0
  53. package/dist/WhatsApp/AutoWAEvent.d.ts +28 -0
  54. package/dist/WhatsApp/AutoWAEvent.d.ts.map +1 -0
  55. package/dist/WhatsApp/AutoWAEvent.js +66 -0
  56. package/dist/WhatsApp/AutoWAManager.d.ts +12 -0
  57. package/dist/WhatsApp/AutoWAManager.d.ts.map +1 -0
  58. package/dist/WhatsApp/AutoWAManager.js +68 -0
  59. package/dist/WhatsApp/action.d.ts +1 -0
  60. package/dist/WhatsApp/action.d.ts.map +1 -0
  61. package/dist/WhatsApp/action.js +272 -0
  62. package/dist/WhatsApp/auto-wa-event.d.ts +26 -0
  63. package/dist/WhatsApp/auto-wa-event.d.ts.map +1 -0
  64. package/dist/WhatsApp/auto-wa-event.js +60 -0
  65. package/dist/WhatsApp/auto-wa-manager.d.ts +12 -0
  66. package/dist/WhatsApp/auto-wa-manager.d.ts.map +1 -0
  67. package/dist/WhatsApp/auto-wa-manager.js +68 -0
  68. package/dist/WhatsApp/auto-wa.d.ts +36 -0
  69. package/dist/WhatsApp/auto-wa.d.ts.map +1 -0
  70. package/dist/WhatsApp/auto-wa.js +497 -0
  71. package/dist/WhatsApp/event.d.ts +24 -0
  72. package/dist/WhatsApp/event.d.ts.map +1 -0
  73. package/dist/WhatsApp/event.js +54 -0
  74. package/dist/WhatsApp/index.d.ts +3 -0
  75. package/dist/WhatsApp/index.d.ts.map +1 -0
  76. package/dist/WhatsApp/index.js +18 -0
  77. package/dist/WhatsApp/multi-auto-wa.d.ts +14 -0
  78. package/dist/WhatsApp/multi-auto-wa.d.ts.map +1 -0
  79. package/dist/WhatsApp/multi-auto-wa.js +86 -0
  80. package/dist/WhatsApp/setup.d.ts +1 -0
  81. package/dist/WhatsApp/setup.d.ts.map +1 -0
  82. package/dist/WhatsApp/setup.js +221 -0
  83. package/dist/WhatsApp/undefined.jpeg +0 -0
  84. package/dist/index.d.ts +5 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +20 -0
  87. package/package.json +38 -0
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # WhatsAuto.js - Easy WhatsApp Automation
2
+
3
+ An easy-to-use library for creating WhatsApp Automation App.
4
+
5
+ Stand above [Baileys](https://github.com/WhiskeySockets/Baileys) Library. This library will be lightweight library for WhatsApp. Not require Selenium or any other browser.
6
+
7
+ ## 🚀 Installation
8
+
9
+ Install package using npm
10
+
11
+ ```
12
+ npm i whatsauto.js
13
+ ```
14
+
15
+ Then import the library
16
+
17
+ ```ts
18
+ import * as WhatsAuto from "whatsauto.js";
19
+ ```
20
+
21
+ or
22
+
23
+ ```ts
24
+ const WhatsAuto = require("whatsauto.js");
25
+ ```
26
+
27
+ ## 🗒️ Insight
28
+
29
+ WhatsAuto.js is designed to simplify the process of automating WhatsApp tasks. By leveraging the power of the Baileys library, it provides a robust and efficient way to interact with WhatsApp without the need for browser automation tools like Selenium.
30
+
31
+ This makes it a lightweight and efficient solution for developers looking to integrate WhatsApp functionalities into their applications.
32
+
33
+ Additionally, WhatsAuto.js uses the Object-Oriented Programming (OOP) paradigm, making it an excellent choice for developers who prefer or are accustomed to OOP. This approach enhances code reusability, scalability, and maintainability, which are essential for long-term project development.
34
+
35
+ ## 🪧 Examples
36
+
37
+ Coming soon..
@@ -0,0 +1,32 @@
1
+ export declare abstract class CREDENTIALS {
2
+ static DIR_NAME: string;
3
+ static PREFIX: string;
4
+ }
5
+ export declare enum CALLBACK_KEY {
6
+ ON_MESSAGE = "message",
7
+ ON_GROUP_MESSAGE = "group-message",
8
+ ON_PRIVATE_MESSAGE = "private-message",
9
+ ON_MESSAGE_RECEIVED = "message-received",
10
+ ON_GROUP_MESSAGE_RECEIVED = "group-message-received",
11
+ ON_PRIVATE_MESSAGE_RECEIVED = "private-message-received",
12
+ ON_MESSAGE_SENT = "message-sent",
13
+ ON_GROUP_MESSAGE_SENT = "group-message-sent",
14
+ ON_PRIVATE_MESSAGE_SENT = "private-message-sent",
15
+ ON_STORY_RECEIVED = "story-received",
16
+ ON_STORY_SENT = "story-sent",
17
+ ON_REACTION_RECEIVED = "reaction-received",
18
+ ON_REACTION_SENT = "reaction-sent",
19
+ ON_QR = "qr",
20
+ ON_CONNECTED = "connected",
21
+ ON_DISCONNECTED = "disconnected",
22
+ ON_CONNECTING = "connecting",
23
+ ON_MESSAGE_UPDATED = "message-updated",
24
+ ON_PAIRING_CODE = "pairing-code"
25
+ }
26
+ export declare abstract class Messages {
27
+ static sessionAlreadyExist: (sessionId: string) => string;
28
+ static sessionNotFound: (sessionId: string) => string;
29
+ static paremetersRequired: (props: string[] | string) => string;
30
+ static paremetersNotValid: (props: string[] | string) => string;
31
+ }
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Defaults/index.ts"],"names":[],"mappings":"AAAA,8BAAsB,WAAW;IAC/B,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAc;IACrC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAY;CAClC;AAED,oBAAY,YAAY;IACtB,UAAU,YAAY;IACtB,gBAAgB,kBAAkB;IAClC,kBAAkB,oBAAoB;IACtC,mBAAmB,qBAAqB;IACxC,yBAAyB,2BAA2B;IACpD,2BAA2B,6BAA6B;IACxD,eAAe,iBAAiB;IAChC,qBAAqB,uBAAuB;IAC5C,uBAAuB,yBAAyB;IAChD,iBAAiB,mBAAmB;IACpC,aAAa,eAAe;IAC5B,oBAAoB,sBAAsB;IAC1C,gBAAgB,kBAAkB;IAClC,KAAK,OAAO;IACZ,YAAY,cAAc;IAC1B,eAAe,iBAAiB;IAChC,aAAa,eAAe;IAC5B,kBAAkB,oBAAoB;IACtC,eAAe,iBAAiB;CACjC;AAED,8BAAsB,QAAQ;IAC5B,MAAM,CAAC,mBAAmB,cAAe,MAAM,KAAG,MAAM,CACgB;IAExE,MAAM,CAAC,eAAe,cAAe,MAAM,KAAG,MAAM,CACN;IAE9C,MAAM,CAAC,kBAAkB,UAAW,MAAM,EAAE,GAAG,MAAM,YAGpC;IAEjB,MAAM,CAAC,kBAAkB,UAAW,MAAM,EAAE,GAAG,MAAM,YAGnC;CACnB"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Messages = exports.CALLBACK_KEY = exports.CREDENTIALS = void 0;
4
+ class CREDENTIALS {
5
+ }
6
+ exports.CREDENTIALS = CREDENTIALS;
7
+ CREDENTIALS.DIR_NAME = "wa_creds";
8
+ CREDENTIALS.PREFIX = "_creds";
9
+ var CALLBACK_KEY;
10
+ (function (CALLBACK_KEY) {
11
+ CALLBACK_KEY["ON_MESSAGE"] = "message";
12
+ CALLBACK_KEY["ON_GROUP_MESSAGE"] = "group-message";
13
+ CALLBACK_KEY["ON_PRIVATE_MESSAGE"] = "private-message";
14
+ CALLBACK_KEY["ON_MESSAGE_RECEIVED"] = "message-received";
15
+ CALLBACK_KEY["ON_GROUP_MESSAGE_RECEIVED"] = "group-message-received";
16
+ CALLBACK_KEY["ON_PRIVATE_MESSAGE_RECEIVED"] = "private-message-received";
17
+ CALLBACK_KEY["ON_MESSAGE_SENT"] = "message-sent";
18
+ CALLBACK_KEY["ON_GROUP_MESSAGE_SENT"] = "group-message-sent";
19
+ CALLBACK_KEY["ON_PRIVATE_MESSAGE_SENT"] = "private-message-sent";
20
+ CALLBACK_KEY["ON_STORY_RECEIVED"] = "story-received";
21
+ CALLBACK_KEY["ON_STORY_SENT"] = "story-sent";
22
+ CALLBACK_KEY["ON_REACTION_RECEIVED"] = "reaction-received";
23
+ CALLBACK_KEY["ON_REACTION_SENT"] = "reaction-sent";
24
+ CALLBACK_KEY["ON_QR"] = "qr";
25
+ CALLBACK_KEY["ON_CONNECTED"] = "connected";
26
+ CALLBACK_KEY["ON_DISCONNECTED"] = "disconnected";
27
+ CALLBACK_KEY["ON_CONNECTING"] = "connecting";
28
+ CALLBACK_KEY["ON_MESSAGE_UPDATED"] = "message-updated";
29
+ CALLBACK_KEY["ON_PAIRING_CODE"] = "pairing-code";
30
+ })(CALLBACK_KEY || (exports.CALLBACK_KEY = CALLBACK_KEY = {}));
31
+ class Messages {
32
+ }
33
+ exports.Messages = Messages;
34
+ Messages.sessionAlreadyExist = (sessionId) => `Session ID "${sessionId}" is already exist, Try another Session ID.`;
35
+ Messages.sessionNotFound = (sessionId) => `Session with ID "${sessionId}" Not Exist!`;
36
+ Messages.paremetersRequired = (props) => `Parameter ${typeof props == "string" ? props : props instanceof Array ? props.join(", ") : ""} is required`;
37
+ Messages.paremetersNotValid = (props) => `Parameter ${typeof props == "string" ? props : props instanceof Array ? props.join(", ") : ""} is not valid`;
@@ -0,0 +1,9 @@
1
+ export declare class WhatsAppError extends Error {
2
+ constructor(message: string);
3
+ static isWhatsAppError(error: any): error is WhatsAppError;
4
+ }
5
+ export declare class ValidationError extends Error {
6
+ constructor(message: string);
7
+ static isValidationError(error: any): error is ValidationError;
8
+ }
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Error/index.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;IAM3B,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,aAAa;CAG3D;AAED,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;IAM3B,MAAM,CAAC,iBAAiB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,eAAe;CAG/D"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationError = exports.WhatsAppError = void 0;
4
+ class WhatsAppError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "WhatsAppError";
8
+ Object.setPrototypeOf(this, WhatsAppError.prototype);
9
+ }
10
+ static isWhatsAppError(error) {
11
+ return error instanceof WhatsAppError || error instanceof Error;
12
+ }
13
+ }
14
+ exports.WhatsAppError = WhatsAppError;
15
+ class ValidationError extends Error {
16
+ constructor(message) {
17
+ super(message);
18
+ this.name = "ValidationError";
19
+ Object.setPrototypeOf(this, ValidationError.prototype);
20
+ }
21
+ static isValidationError(error) {
22
+ return error instanceof ValidationError || error instanceof Error;
23
+ }
24
+ }
25
+ exports.ValidationError = ValidationError;
@@ -0,0 +1,8 @@
1
+ export default class Logger {
2
+ private name;
3
+ constructor(name: string);
4
+ debug(message: any): void;
5
+ info(message: any): void;
6
+ error(message: any): void;
7
+ }
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Logger/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,OAAO,CAAC,IAAI,CAAS;gBAET,IAAI,EAAE,MAAM;IAIjB,KAAK,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IAIzB,IAAI,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IAIxB,KAAK,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;CAGjC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Logger {
4
+ constructor(name) {
5
+ this.name = name;
6
+ }
7
+ debug(message) {
8
+ console.debug({ name: this.name, message });
9
+ }
10
+ info(message) {
11
+ console.info({ name: this.name, message });
12
+ }
13
+ error(message) {
14
+ console.error({ name: this.name, message });
15
+ }
16
+ }
17
+ exports.default = Logger;
@@ -0,0 +1,33 @@
1
+ import { proto } from "@whiskeysockets/baileys";
2
+ import { SendMediaTypes, SendMessageTypes, SendReadTypes, SendTypingTypes } from "../Types";
3
+ export declare const sendTextMessage: ({ sessionId, to, text, isGroup, ...props }: SendMessageTypes) => Promise<proto.WebMessageInfo | undefined>;
4
+ export declare const sendImage: ({ sessionId, to, text, isGroup, media, ...props }: SendMediaTypes) => Promise<proto.WebMessageInfo | undefined>;
5
+ export declare const sendVideo: ({ sessionId, to, text, isGroup, media, ...props }: SendMediaTypes) => Promise<proto.WebMessageInfo | undefined>;
6
+ export declare const sendDocument: ({ sessionId, to, text, isGroup, media, filename, ...props }: SendMediaTypes & {
7
+ filename: string;
8
+ }) => Promise<proto.WebMessageInfo | undefined>;
9
+ export declare const sendVoiceNote: ({ sessionId, to, isGroup, media, ...props }: Omit<SendMediaTypes, "text">) => Promise<proto.WebMessageInfo | undefined>;
10
+ export declare const sendSticker: ({ sessionId, to, isGroup, media, ...props }: SendMediaTypes) => Promise<proto.WebMessageInfo | undefined>;
11
+ /**
12
+ * Give typing effect to target
13
+ *
14
+ * Looks like human typing
15
+ *
16
+ *
17
+ * @param sessionId - Session ID
18
+ * @param to - Target
19
+ * @param duration - Duration in miliseconds typing effect will appear
20
+ */
21
+ export declare const sendTyping: ({ sessionId, to, duration, isGroup, }: SendTypingTypes) => Promise<void>;
22
+ /**
23
+ * Give typing effect to target
24
+ *
25
+ * Looks like human typing
26
+ *
27
+ *
28
+ * @param sessionId - Session ID
29
+ * @param to - Target
30
+ * @param duration - Duration in miliseconds typing effect will appear
31
+ */
32
+ export declare const readMessage: ({ sessionId, key }: SendReadTypes) => Promise<void>;
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Messaging/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAGhD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,eAAe,EAChB,MAAM,UAAU,CAAC;AAOlB,eAAO,MAAM,eAAe,+CAMzB,gBAAgB,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CAc7D,CAAC;AACF,eAAO,MAAM,SAAS,sDAOnB,cAAc,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA8B3D,CAAC;AACF,eAAO,MAAM,SAAS,sDAOnB,cAAc,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA8B3D,CAAC;AACF,eAAO,MAAM,YAAY,gEAQtB,cAAc,GAAG;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CAuC3C,CAAC;AAEF,eAAO,MAAM,aAAa,gDAMvB,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CAgCzE,CAAC;AAEF,eAAO,MAAM,WAAW,gDAMrB,cAAc,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA+B3D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,0CAKpB,eAAe,kBAgBjB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,uBAA8B,aAAa,kBAKlE,CAAC"}
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.readMessage = exports.sendTyping = exports.sendSticker = exports.sendVoiceNote = exports.sendDocument = exports.sendVideo = exports.sendImage = exports.sendTextMessage = void 0;
27
+ const Defaults_1 = require("../Defaults");
28
+ const Socket_1 = require("../Socket");
29
+ const Utils_1 = require("../Utils");
30
+ const create_delay_1 = require("../Utils/create-delay");
31
+ const is_exist_1 = require("../Utils/is-exist");
32
+ const mime_1 = __importDefault(require("mime"));
33
+ const Error_1 = require("../Error");
34
+ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
35
+ var { sessionId, to, text = "", isGroup = false } = _a, props = __rest(_a, ["sessionId", "to", "text", "isGroup"]);
36
+ const session = (0, Socket_1.getSession)(sessionId);
37
+ if (!session)
38
+ throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
39
+ to = (0, Utils_1.phoneToJid)({ to, isGroup });
40
+ return yield session.sendMessage(to, {
41
+ text: text,
42
+ }, {
43
+ quoted: props.answering,
44
+ });
45
+ });
46
+ exports.sendTextMessage = sendTextMessage;
47
+ const sendImage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
48
+ var { sessionId, to, text = "", isGroup = false, media } = _a, props = __rest(_a, ["sessionId", "to", "text", "isGroup", "media"]);
49
+ const session = (0, Socket_1.getSession)(sessionId);
50
+ if (!session)
51
+ throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
52
+ const oldPhone = to;
53
+ to = (0, Utils_1.phoneToJid)({ to, isGroup });
54
+ const isRegistered = yield (0, is_exist_1.isExist)({
55
+ sessionId,
56
+ to,
57
+ isGroup,
58
+ });
59
+ if (!isRegistered) {
60
+ throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
61
+ }
62
+ if (!media)
63
+ throw new Error_1.WhatsappError("parameter media must be Buffer or String URL");
64
+ return yield session.sendMessage(to, {
65
+ image: typeof media == "string"
66
+ ? {
67
+ url: media,
68
+ }
69
+ : media,
70
+ caption: text,
71
+ }, {
72
+ quoted: props.answering,
73
+ });
74
+ });
75
+ exports.sendImage = sendImage;
76
+ const sendVideo = (_a) => __awaiter(void 0, void 0, void 0, function* () {
77
+ var { sessionId, to, text = "", isGroup = false, media } = _a, props = __rest(_a, ["sessionId", "to", "text", "isGroup", "media"]);
78
+ const session = (0, Socket_1.getSession)(sessionId);
79
+ if (!session)
80
+ throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
81
+ const oldPhone = to;
82
+ to = (0, Utils_1.phoneToJid)({ to, isGroup });
83
+ const isRegistered = yield (0, is_exist_1.isExist)({
84
+ sessionId,
85
+ to,
86
+ isGroup,
87
+ });
88
+ if (!isRegistered) {
89
+ throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
90
+ }
91
+ if (!media)
92
+ throw new Error_1.WhatsappError("parameter media must be Buffer or String URL");
93
+ return yield session.sendMessage(to, {
94
+ video: typeof media == "string"
95
+ ? {
96
+ url: media,
97
+ }
98
+ : media,
99
+ caption: text,
100
+ }, {
101
+ quoted: props.answering,
102
+ });
103
+ });
104
+ exports.sendVideo = sendVideo;
105
+ const sendDocument = (_a) => __awaiter(void 0, void 0, void 0, function* () {
106
+ var { sessionId, to, text = "", isGroup = false, media, filename } = _a, props = __rest(_a, ["sessionId", "to", "text", "isGroup", "media", "filename"]);
107
+ const session = (0, Socket_1.getSession)(sessionId);
108
+ if (!session)
109
+ throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
110
+ const oldPhone = to;
111
+ to = (0, Utils_1.phoneToJid)({ to, isGroup });
112
+ const isRegistered = yield (0, is_exist_1.isExist)({
113
+ sessionId,
114
+ to,
115
+ isGroup,
116
+ });
117
+ if (!isRegistered) {
118
+ throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
119
+ }
120
+ if (!media) {
121
+ throw new Error_1.WhatsappError(`Invalid Media`);
122
+ }
123
+ const mimetype = mime_1.default.getType(filename);
124
+ if (!mimetype) {
125
+ throw new Error_1.WhatsappError(`Filename must include valid extension`);
126
+ }
127
+ return yield session.sendMessage(to, {
128
+ fileName: filename,
129
+ document: typeof media == "string"
130
+ ? {
131
+ url: media,
132
+ }
133
+ : media,
134
+ mimetype: mimetype,
135
+ caption: text,
136
+ }, {
137
+ quoted: props.answering,
138
+ });
139
+ });
140
+ exports.sendDocument = sendDocument;
141
+ const sendVoiceNote = (_a) => __awaiter(void 0, void 0, void 0, function* () {
142
+ var { sessionId, to, isGroup = false, media } = _a, props = __rest(_a, ["sessionId", "to", "isGroup", "media"]);
143
+ const session = (0, Socket_1.getSession)(sessionId);
144
+ if (!session)
145
+ throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
146
+ const oldPhone = to;
147
+ to = (0, Utils_1.phoneToJid)({ to, isGroup });
148
+ const isRegistered = yield (0, is_exist_1.isExist)({
149
+ sessionId,
150
+ to,
151
+ isGroup,
152
+ });
153
+ if (!isRegistered) {
154
+ throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
155
+ }
156
+ if (!media) {
157
+ throw new Error_1.WhatsappError(`Invalid Media`);
158
+ }
159
+ return yield session.sendMessage(to, {
160
+ audio: typeof media == "string"
161
+ ? {
162
+ url: media,
163
+ }
164
+ : media,
165
+ ptt: true,
166
+ }, {
167
+ quoted: props.answering,
168
+ });
169
+ });
170
+ exports.sendVoiceNote = sendVoiceNote;
171
+ const sendSticker = (_a) => __awaiter(void 0, void 0, void 0, function* () {
172
+ var { sessionId, to, isGroup, media } = _a, props = __rest(_a, ["sessionId", "to", "isGroup", "media"]);
173
+ const session = (0, Socket_1.getSession)(sessionId);
174
+ if (!session)
175
+ throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
176
+ const oldPhone = to;
177
+ to = (0, Utils_1.phoneToJid)({ to, isGroup });
178
+ const isRegistered = yield (0, is_exist_1.isExist)({
179
+ sessionId,
180
+ to,
181
+ isGroup,
182
+ });
183
+ if (!isRegistered) {
184
+ throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
185
+ }
186
+ if (!media) {
187
+ throw new Error_1.WhatsappError(`Invalid Media`);
188
+ }
189
+ return yield session.sendMessage(to, {
190
+ sticker: typeof media == "string"
191
+ ? {
192
+ url: media,
193
+ }
194
+ : media,
195
+ }, {
196
+ quoted: props.answering,
197
+ });
198
+ });
199
+ exports.sendSticker = sendSticker;
200
+ /**
201
+ * Give typing effect to target
202
+ *
203
+ * Looks like human typing
204
+ *
205
+ *
206
+ * @param sessionId - Session ID
207
+ * @param to - Target
208
+ * @param duration - Duration in miliseconds typing effect will appear
209
+ */
210
+ const sendTyping = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, to, duration = 1000, isGroup = false, }) {
211
+ const oldPhone = to;
212
+ to = (0, Utils_1.phoneToJid)({ to, isGroup });
213
+ const session = (0, Socket_1.getSession)(sessionId);
214
+ if (!session)
215
+ throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
216
+ const isRegistered = yield (0, is_exist_1.isExist)({
217
+ sessionId,
218
+ to,
219
+ isGroup,
220
+ });
221
+ if (!isRegistered) {
222
+ throw new Error_1.WhatsappError(`${oldPhone} is not registered on Whatsapp`);
223
+ }
224
+ yield session.sendPresenceUpdate("composing", to);
225
+ yield (0, create_delay_1.createDelay)(duration);
226
+ yield session.sendPresenceUpdate("available", to);
227
+ });
228
+ exports.sendTyping = sendTyping;
229
+ /**
230
+ * Give typing effect to target
231
+ *
232
+ * Looks like human typing
233
+ *
234
+ *
235
+ * @param sessionId - Session ID
236
+ * @param to - Target
237
+ * @param duration - Duration in miliseconds typing effect will appear
238
+ */
239
+ const readMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, key }) {
240
+ const session = (0, Socket_1.getSession)(sessionId);
241
+ if (!session)
242
+ throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
243
+ yield session.readMessages([key]);
244
+ });
245
+ exports.readMessage = readMessage;
@@ -0,0 +1,29 @@
1
+ import { WASocket } from "@whiskeysockets/baileys";
2
+ import type { MessageReceived, MessageUpdated, StartSessionParams } from "../Types";
3
+ /**
4
+ * Start WhatsApp session with QR method
5
+ */
6
+ export declare const startSessionWithQR: (sessionId?: string, options?: StartSessionParams) => Promise<WASocket>;
7
+ /**
8
+ * Start WhatsApp session with pairing code method
9
+ */
10
+ export declare const startSessionWithPairingCode: (sessionId: string, options: StartSessionParams) => Promise<WASocket>;
11
+ /**
12
+ * start WhatsApp session
13
+ */
14
+ export declare const startWhatsapp: (sessionId: string, options?: StartSessionParams) => Promise<WASocket>;
15
+ export declare const deleteSession: (sessionId: string) => Promise<void>;
16
+ export declare const getAllSession: () => string[];
17
+ export declare const getSession: (key: string) => WASocket | undefined;
18
+ export declare const loadSessionsFromStorage: () => void;
19
+ export declare const onMessageReceived: (listener: (msg: MessageReceived) => any) => void;
20
+ export declare const onQRUpdated: (listener: ({ sessionId, qr }: {
21
+ sessionId: string;
22
+ qr: string;
23
+ }) => any) => void;
24
+ export declare const onConnected: (listener: (sessionId: string) => any) => void;
25
+ export declare const onDisconnected: (listener: (sessionId: string) => any) => void;
26
+ export declare const onConnecting: (listener: (sessionId: string) => any) => void;
27
+ export declare const onMessageUpdate: (listener: (data: MessageUpdated) => any) => void;
28
+ export declare const onPairingCode: (listener: (sessionId: string, code: string) => any) => void;
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Socket/index.ts"],"names":[],"mappings":"AAAA,OAAqB,EAMnB,QAAQ,EACT,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAyClB;;GAEG;AACH,eAAO,MAAM,kBAAkB,iCAEpB,kBAAkB,KAC1B,OAAO,CAAC,QAAQ,CA0GlB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,cAC3B,MAAM,WACR,kBAAkB,KAC1B,OAAO,CAAC,QAAQ,CAkHlB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,cACb,MAAM,YACR,kBAAkB,KAC1B,OAAO,CAAC,QAAQ,CAKlB,CAAC;AAEF,eAAO,MAAM,aAAa,cAAqB,MAAM,kBAcpD,CAAC;AACF,eAAO,MAAM,aAAa,QAAO,MAAM,EAAiC,CAAC;AAEzE,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,QAAQ,GAAG,SACrB,CAAC;AAiChC,eAAO,MAAM,uBAAuB,YAcnC,CAAC;AAEF,eAAO,MAAM,iBAAiB,aAAc,CAAC,GAAG,EAAE,eAAe,KAAK,GAAG,SAExE,CAAC;AACF,eAAO,MAAM,WAAW,aACZ,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,KAAK,GAAG,SAGxE,CAAC;AACF,eAAO,MAAM,WAAW,aAAc,CAAC,SAAS,EAAE,MAAM,KAAK,GAAG,SAE/D,CAAC;AACF,eAAO,MAAM,cAAc,aAAc,CAAC,SAAS,EAAE,MAAM,KAAK,GAAG,SAElE,CAAC;AACF,eAAO,MAAM,YAAY,aAAc,CAAC,SAAS,EAAE,MAAM,KAAK,GAAG,SAEhE,CAAC;AAEF,eAAO,MAAM,eAAe,aAAc,CAAC,IAAI,EAAE,cAAc,KAAK,GAAG,SAEtE,CAAC;AAEF,eAAO,MAAM,aAAa,aACd,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,GAAG,SAGnD,CAAC"}