botcast-sdk 1.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 (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +257 -0
  3. package/dist/client.cjs +91 -0
  4. package/dist/client.d.ts +64 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +87 -0
  7. package/dist/errors.cjs +59 -0
  8. package/dist/errors.d.ts +25 -0
  9. package/dist/errors.d.ts.map +1 -0
  10. package/dist/errors.js +49 -0
  11. package/dist/index.cjs +26 -0
  12. package/dist/index.d.ts +7 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +7 -0
  15. package/dist/modules/base.cjs +113 -0
  16. package/dist/modules/base.d.ts +22 -0
  17. package/dist/modules/base.d.ts.map +1 -0
  18. package/dist/modules/base.js +109 -0
  19. package/dist/modules/broadcast.cjs +30 -0
  20. package/dist/modules/broadcast.d.ts +27 -0
  21. package/dist/modules/broadcast.d.ts.map +1 -0
  22. package/dist/modules/broadcast.js +26 -0
  23. package/dist/modules/chats.cjs +113 -0
  24. package/dist/modules/chats.d.ts +106 -0
  25. package/dist/modules/chats.d.ts.map +1 -0
  26. package/dist/modules/chats.js +109 -0
  27. package/dist/modules/groups.cjs +200 -0
  28. package/dist/modules/groups.d.ts +139 -0
  29. package/dist/modules/groups.d.ts.map +1 -0
  30. package/dist/modules/groups.js +196 -0
  31. package/dist/modules/instances.cjs +138 -0
  32. package/dist/modules/instances.d.ts +91 -0
  33. package/dist/modules/instances.d.ts.map +1 -0
  34. package/dist/modules/instances.js +134 -0
  35. package/dist/modules/messages.cjs +217 -0
  36. package/dist/modules/messages.d.ts +155 -0
  37. package/dist/modules/messages.d.ts.map +1 -0
  38. package/dist/modules/messages.js +213 -0
  39. package/dist/modules/profile.cjs +129 -0
  40. package/dist/modules/profile.d.ts +92 -0
  41. package/dist/modules/profile.d.ts.map +1 -0
  42. package/dist/modules/profile.js +125 -0
  43. package/dist/types/chats.cjs +2 -0
  44. package/dist/types/chats.d.ts +62 -0
  45. package/dist/types/chats.d.ts.map +1 -0
  46. package/dist/types/chats.js +1 -0
  47. package/dist/types/groups.cjs +2 -0
  48. package/dist/types/groups.d.ts +47 -0
  49. package/dist/types/groups.d.ts.map +1 -0
  50. package/dist/types/groups.js +1 -0
  51. package/dist/types/index.cjs +22 -0
  52. package/dist/types/index.d.ts +34 -0
  53. package/dist/types/index.d.ts.map +1 -0
  54. package/dist/types/index.js +6 -0
  55. package/dist/types/instances.cjs +2 -0
  56. package/dist/types/instances.d.ts +65 -0
  57. package/dist/types/instances.d.ts.map +1 -0
  58. package/dist/types/instances.js +1 -0
  59. package/dist/types/messages.cjs +2 -0
  60. package/dist/types/messages.d.ts +86 -0
  61. package/dist/types/messages.d.ts.map +1 -0
  62. package/dist/types/messages.js +1 -0
  63. package/dist/types/profile.cjs +2 -0
  64. package/dist/types/profile.d.ts +25 -0
  65. package/dist/types/profile.d.ts.map +1 -0
  66. package/dist/types/profile.js +1 -0
  67. package/dist/types/webhooks.cjs +2 -0
  68. package/dist/types/webhooks.d.ts +17 -0
  69. package/dist/types/webhooks.d.ts.map +1 -0
  70. package/dist/types/webhooks.js +1 -0
  71. package/dist/webhooks/index.cjs +71 -0
  72. package/dist/webhooks/index.d.ts +26 -0
  73. package/dist/webhooks/index.d.ts.map +1 -0
  74. package/dist/webhooks/index.js +67 -0
  75. package/package.json +61 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,26 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.BotcastWebhook = exports.BotcastClient = void 0;
18
+ var client_js_1 = require("./client.js");
19
+ Object.defineProperty(exports, "BotcastClient", { enumerable: true, get: function () { return client_js_1.BotcastClient; } });
20
+ var index_js_1 = require("./webhooks/index.js");
21
+ Object.defineProperty(exports, "BotcastWebhook", { enumerable: true, get: function () { return index_js_1.BotcastWebhook; } });
22
+ __exportStar(require("./errors.js"), exports);
23
+ __exportStar(require("./types/index.js"), exports);
24
+ // Default export
25
+ const client_js_2 = require("./client.js");
26
+ exports.default = client_js_2.BotcastClient;
@@ -0,0 +1,7 @@
1
+ export { BotcastClient } from './client.js';
2
+ export { BotcastWebhook } from './webhooks/index.js';
3
+ export * from './errors.js';
4
+ export * from './types/index.js';
5
+ import { BotcastClient } from './client.js';
6
+ export default BotcastClient;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;eAC7B,aAAa"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { BotcastClient } from './client.js';
2
+ export { BotcastWebhook } from './webhooks/index.js';
3
+ export * from './errors.js';
4
+ export * from './types/index.js';
5
+ // Default export
6
+ import { BotcastClient } from './client.js';
7
+ export default BotcastClient;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseModule = void 0;
4
+ const errors_js_1 = require("../errors.js");
5
+ class BaseModule {
6
+ config;
7
+ constructor(config) {
8
+ this.config = config;
9
+ }
10
+ /**
11
+ * Builds the instance-specific URL path prefix: `/whatsapp/:instanceId/:instanceToken/...`
12
+ */
13
+ buildPath(subPath) {
14
+ const cleanSubPath = subPath.startsWith('/') ? subPath.slice(1) : subPath;
15
+ return `/whatsapp/${encodeURIComponent(this.config.instanceId)}/${encodeURIComponent(this.config.instanceToken)}/${cleanSubPath}`;
16
+ }
17
+ /**
18
+ * Executes an HTTP request against the Botcast API Gateway with retry & error translation.
19
+ */
20
+ async request(options) {
21
+ const { method = 'GET', path, query, body, headers } = options;
22
+ let urlString = `${this.config.baseUrl.replace(/\/$/, '')}${path.startsWith('/') ? path : '/' + path}`;
23
+ if (query) {
24
+ const url = new URL(urlString);
25
+ for (const [key, value] of Object.entries(query)) {
26
+ if (value !== undefined && value !== null) {
27
+ url.searchParams.append(key, String(value));
28
+ }
29
+ }
30
+ urlString = url.toString();
31
+ }
32
+ const fetchHeaders = {
33
+ 'Content-Type': 'application/json',
34
+ 'Accept': 'application/json',
35
+ ...this.config.headers,
36
+ ...headers,
37
+ };
38
+ let attempts = 0;
39
+ const maxAttempts = (this.config.maxRetries || 0) + 1;
40
+ while (attempts < maxAttempts) {
41
+ attempts++;
42
+ const controller = new AbortController();
43
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
44
+ try {
45
+ const response = await fetch(urlString, {
46
+ method,
47
+ headers: fetchHeaders,
48
+ body: body ? JSON.stringify(body) : undefined,
49
+ signal: controller.signal,
50
+ });
51
+ clearTimeout(timeoutId);
52
+ let responseData;
53
+ const contentType = response.headers.get('content-type');
54
+ if (contentType && contentType.includes('application/json')) {
55
+ responseData = await response.json().catch(() => null);
56
+ }
57
+ else {
58
+ responseData = await response.text().catch(() => '');
59
+ }
60
+ if (!response.ok) {
61
+ this.handleHttpError(response.status, responseData);
62
+ }
63
+ return responseData;
64
+ }
65
+ catch (err) {
66
+ clearTimeout(timeoutId);
67
+ // Don't retry client-side errors or authentication failures
68
+ if (err instanceof errors_js_1.BotcastAuthError ||
69
+ err instanceof errors_js_1.BotcastPaymentRequiredError ||
70
+ err instanceof errors_js_1.BotcastSubscriptionExpiredError ||
71
+ err instanceof errors_js_1.BotcastValidationError ||
72
+ err instanceof errors_js_1.BotcastNotFoundError) {
73
+ throw err;
74
+ }
75
+ if (attempts >= maxAttempts) {
76
+ if (err instanceof errors_js_1.BotcastError) {
77
+ throw err;
78
+ }
79
+ throw new errors_js_1.BotcastError(err.name === 'AbortError'
80
+ ? `Request timed out after ${this.config.timeout}ms`
81
+ : `HTTP Request failed: ${err.message || 'Unknown network error'}`, undefined, err);
82
+ }
83
+ // Exponential backoff before retry (e.g. 500ms, 1000ms)
84
+ const delay = Math.min(500 * Math.pow(2, attempts - 1), 3000);
85
+ await new Promise((resolve) => setTimeout(resolve, delay));
86
+ }
87
+ }
88
+ throw new errors_js_1.BotcastError('Request failed after max retry attempts');
89
+ }
90
+ handleHttpError(status, data) {
91
+ const message = data?.message || data?.error || (typeof data === 'string' ? data : `HTTP ${status}`);
92
+ switch (status) {
93
+ case 400:
94
+ throw new errors_js_1.BotcastValidationError(message, data);
95
+ case 401:
96
+ throw new errors_js_1.BotcastAuthError(message, data);
97
+ case 402:
98
+ throw new errors_js_1.BotcastPaymentRequiredError(message, data);
99
+ case 403:
100
+ if (data?.expired) {
101
+ throw new errors_js_1.BotcastSubscriptionExpiredError(message, data.expires_at, data);
102
+ }
103
+ throw new errors_js_1.BotcastError(message, 403, data);
104
+ case 404:
105
+ throw new errors_js_1.BotcastNotFoundError(message, data);
106
+ case 429:
107
+ throw new errors_js_1.BotcastRateLimitError(message, data);
108
+ default:
109
+ throw new errors_js_1.BotcastError(message, status, data);
110
+ }
111
+ }
112
+ }
113
+ exports.BaseModule = BaseModule;
@@ -0,0 +1,22 @@
1
+ import { BotcastClientConfig } from '../types/index.js';
2
+ export interface RequestOptions {
3
+ method?: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';
4
+ path: string;
5
+ query?: Record<string, string | number | boolean | undefined | null>;
6
+ body?: any;
7
+ headers?: Record<string, string>;
8
+ }
9
+ export declare class BaseModule {
10
+ protected config: Required<BotcastClientConfig>;
11
+ constructor(config: Required<BotcastClientConfig>);
12
+ /**
13
+ * Builds the instance-specific URL path prefix: `/whatsapp/:instanceId/:instanceToken/...`
14
+ */
15
+ protected buildPath(subPath: string): string;
16
+ /**
17
+ * Executes an HTTP request against the Botcast API Gateway with retry & error translation.
18
+ */
19
+ request<T = any>(options: RequestOptions): Promise<T>;
20
+ private handleHttpError;
21
+ }
22
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/modules/base.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;IACrE,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,qBAAa,UAAU;IACrB,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IAEhD,YAAY,MAAM,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAEhD;IAED;;OAEG;IACH,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG3C;IAED;;OAEG;IACU,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAuFjE;IAED,OAAO,CAAC,eAAe;CAuBxB"}
@@ -0,0 +1,109 @@
1
+ import { BotcastError, BotcastAuthError, BotcastPaymentRequiredError, BotcastSubscriptionExpiredError, BotcastRateLimitError, BotcastValidationError, BotcastNotFoundError, } from '../errors.js';
2
+ export class BaseModule {
3
+ config;
4
+ constructor(config) {
5
+ this.config = config;
6
+ }
7
+ /**
8
+ * Builds the instance-specific URL path prefix: `/whatsapp/:instanceId/:instanceToken/...`
9
+ */
10
+ buildPath(subPath) {
11
+ const cleanSubPath = subPath.startsWith('/') ? subPath.slice(1) : subPath;
12
+ return `/whatsapp/${encodeURIComponent(this.config.instanceId)}/${encodeURIComponent(this.config.instanceToken)}/${cleanSubPath}`;
13
+ }
14
+ /**
15
+ * Executes an HTTP request against the Botcast API Gateway with retry & error translation.
16
+ */
17
+ async request(options) {
18
+ const { method = 'GET', path, query, body, headers } = options;
19
+ let urlString = `${this.config.baseUrl.replace(/\/$/, '')}${path.startsWith('/') ? path : '/' + path}`;
20
+ if (query) {
21
+ const url = new URL(urlString);
22
+ for (const [key, value] of Object.entries(query)) {
23
+ if (value !== undefined && value !== null) {
24
+ url.searchParams.append(key, String(value));
25
+ }
26
+ }
27
+ urlString = url.toString();
28
+ }
29
+ const fetchHeaders = {
30
+ 'Content-Type': 'application/json',
31
+ 'Accept': 'application/json',
32
+ ...this.config.headers,
33
+ ...headers,
34
+ };
35
+ let attempts = 0;
36
+ const maxAttempts = (this.config.maxRetries || 0) + 1;
37
+ while (attempts < maxAttempts) {
38
+ attempts++;
39
+ const controller = new AbortController();
40
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
41
+ try {
42
+ const response = await fetch(urlString, {
43
+ method,
44
+ headers: fetchHeaders,
45
+ body: body ? JSON.stringify(body) : undefined,
46
+ signal: controller.signal,
47
+ });
48
+ clearTimeout(timeoutId);
49
+ let responseData;
50
+ const contentType = response.headers.get('content-type');
51
+ if (contentType && contentType.includes('application/json')) {
52
+ responseData = await response.json().catch(() => null);
53
+ }
54
+ else {
55
+ responseData = await response.text().catch(() => '');
56
+ }
57
+ if (!response.ok) {
58
+ this.handleHttpError(response.status, responseData);
59
+ }
60
+ return responseData;
61
+ }
62
+ catch (err) {
63
+ clearTimeout(timeoutId);
64
+ // Don't retry client-side errors or authentication failures
65
+ if (err instanceof BotcastAuthError ||
66
+ err instanceof BotcastPaymentRequiredError ||
67
+ err instanceof BotcastSubscriptionExpiredError ||
68
+ err instanceof BotcastValidationError ||
69
+ err instanceof BotcastNotFoundError) {
70
+ throw err;
71
+ }
72
+ if (attempts >= maxAttempts) {
73
+ if (err instanceof BotcastError) {
74
+ throw err;
75
+ }
76
+ throw new BotcastError(err.name === 'AbortError'
77
+ ? `Request timed out after ${this.config.timeout}ms`
78
+ : `HTTP Request failed: ${err.message || 'Unknown network error'}`, undefined, err);
79
+ }
80
+ // Exponential backoff before retry (e.g. 500ms, 1000ms)
81
+ const delay = Math.min(500 * Math.pow(2, attempts - 1), 3000);
82
+ await new Promise((resolve) => setTimeout(resolve, delay));
83
+ }
84
+ }
85
+ throw new BotcastError('Request failed after max retry attempts');
86
+ }
87
+ handleHttpError(status, data) {
88
+ const message = data?.message || data?.error || (typeof data === 'string' ? data : `HTTP ${status}`);
89
+ switch (status) {
90
+ case 400:
91
+ throw new BotcastValidationError(message, data);
92
+ case 401:
93
+ throw new BotcastAuthError(message, data);
94
+ case 402:
95
+ throw new BotcastPaymentRequiredError(message, data);
96
+ case 403:
97
+ if (data?.expired) {
98
+ throw new BotcastSubscriptionExpiredError(message, data.expires_at, data);
99
+ }
100
+ throw new BotcastError(message, 403, data);
101
+ case 404:
102
+ throw new BotcastNotFoundError(message, data);
103
+ case 429:
104
+ throw new BotcastRateLimitError(message, data);
105
+ default:
106
+ throw new BotcastError(message, status, data);
107
+ }
108
+ }
109
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BroadcastModule = void 0;
4
+ const base_js_1 = require("./base.js");
5
+ class BroadcastModule extends base_js_1.BaseModule {
6
+ /**
7
+ * Publishes a WhatsApp Status / Story (Text, Image, Video, or Audio).
8
+ */
9
+ async sendStatusStory(content, options) {
10
+ return this.request({
11
+ method: 'POST',
12
+ path: this.buildPath('broadcast/status'),
13
+ body: {
14
+ ...content,
15
+ ...options,
16
+ },
17
+ });
18
+ }
19
+ /**
20
+ * Retrieves info about a WhatsApp broadcast list.
21
+ */
22
+ async getListInfo(listJid) {
23
+ return this.request({
24
+ method: 'GET',
25
+ path: this.buildPath('broadcast/list-info'),
26
+ query: { jid: listJid },
27
+ });
28
+ }
29
+ }
30
+ exports.BroadcastModule = BroadcastModule;
@@ -0,0 +1,27 @@
1
+ import { BaseModule } from './base.js';
2
+ import { BroadcastStoryOptions } from '../types/index.js';
3
+ export declare class BroadcastModule extends BaseModule {
4
+ /**
5
+ * Publishes a WhatsApp Status / Story (Text, Image, Video, or Audio).
6
+ */
7
+ sendStatusStory(content: {
8
+ text?: string;
9
+ message?: string;
10
+ url?: string;
11
+ base64?: string;
12
+ type?: 'text' | 'image' | 'video' | 'audio';
13
+ caption?: string;
14
+ }, options?: BroadcastStoryOptions): Promise<{
15
+ success: boolean;
16
+ message: string;
17
+ result?: any;
18
+ }>;
19
+ /**
20
+ * Retrieves info about a WhatsApp broadcast list.
21
+ */
22
+ getListInfo(listJid: string): Promise<{
23
+ success: boolean;
24
+ listInfo: any;
25
+ }>;
26
+ }
27
+ //# sourceMappingURL=broadcast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broadcast.d.ts","sourceRoot":"","sources":["../../../src/modules/broadcast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,qBAAa,eAAgB,SAAQ,UAAU;IAC7C;;OAEG;IACU,eAAe,CAC1B,OAAO,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;QAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,EACD,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC,CAS9D;IAED;;OAEG;IACU,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,GAAG,CAAA;KAAE,CAAC,CAMtF;CACF"}
@@ -0,0 +1,26 @@
1
+ import { BaseModule } from './base.js';
2
+ export class BroadcastModule extends BaseModule {
3
+ /**
4
+ * Publishes a WhatsApp Status / Story (Text, Image, Video, or Audio).
5
+ */
6
+ async sendStatusStory(content, options) {
7
+ return this.request({
8
+ method: 'POST',
9
+ path: this.buildPath('broadcast/status'),
10
+ body: {
11
+ ...content,
12
+ ...options,
13
+ },
14
+ });
15
+ }
16
+ /**
17
+ * Retrieves info about a WhatsApp broadcast list.
18
+ */
19
+ async getListInfo(listJid) {
20
+ return this.request({
21
+ method: 'GET',
22
+ path: this.buildPath('broadcast/list-info'),
23
+ query: { jid: listJid },
24
+ });
25
+ }
26
+ }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatsModule = void 0;
4
+ const base_js_1 = require("./base.js");
5
+ class ChatsModule extends base_js_1.BaseModule {
6
+ /**
7
+ * Lists synced WhatsApp chats with optional search and pagination.
8
+ */
9
+ async list(params) {
10
+ return this.request({
11
+ method: 'GET',
12
+ path: this.buildPath('chats'),
13
+ query: params,
14
+ });
15
+ }
16
+ /**
17
+ * Lists synced WhatsApp contacts.
18
+ */
19
+ async listContacts(params) {
20
+ return this.request({
21
+ method: 'GET',
22
+ path: this.buildPath('contacts'),
23
+ query: params,
24
+ });
25
+ }
26
+ /**
27
+ * Lists synced chat messages.
28
+ */
29
+ async listMessages(params) {
30
+ return this.request({
31
+ method: 'GET',
32
+ path: this.buildPath('messages'),
33
+ query: params,
34
+ });
35
+ }
36
+ /**
37
+ * Modifies a chat state (archive, mute, read, pin, star, delete).
38
+ */
39
+ async modify(options) {
40
+ return this.request({
41
+ method: 'POST',
42
+ path: this.buildPath('chats/modify'),
43
+ body: options,
44
+ });
45
+ }
46
+ /**
47
+ * Archives a chat.
48
+ */
49
+ async archive(targetJid) {
50
+ return this.modify({ jid: targetJid, action: 'archive' });
51
+ }
52
+ /**
53
+ * Unarchives a chat.
54
+ */
55
+ async unarchive(targetJid) {
56
+ return this.modify({ jid: targetJid, action: 'unarchive' });
57
+ }
58
+ /**
59
+ * Mutes chat notifications for a specified duration in milliseconds (default: 8 hours).
60
+ */
61
+ async mute(targetJid, durationMs = 8 * 60 * 60 * 1000) {
62
+ return this.modify({ jid: targetJid, action: 'mute', duration: durationMs });
63
+ }
64
+ /**
65
+ * Unmutes chat notifications.
66
+ */
67
+ async unmute(targetJid) {
68
+ return this.modify({ jid: targetJid, action: 'unmute' });
69
+ }
70
+ /**
71
+ * Pins a chat to the top of the chat list.
72
+ */
73
+ async pin(targetJid) {
74
+ return this.modify({ jid: targetJid, action: 'pin', isPin: true });
75
+ }
76
+ /**
77
+ * Unpins a chat from the top.
78
+ */
79
+ async unpin(targetJid) {
80
+ return this.modify({ jid: targetJid, action: 'unpin' });
81
+ }
82
+ /**
83
+ * Deletes an entire chat conversation.
84
+ */
85
+ async deleteChat(targetJid) {
86
+ return this.modify({ jid: targetJid, action: 'delete_chat' });
87
+ }
88
+ /**
89
+ * Configures disappearing messages for a chat.
90
+ *
91
+ * @param recipient Target chat JID or phone number
92
+ * @param duration Duration in seconds (86400: 24h, 604800: 7d, 7776000: 90d)
93
+ * @param enabled Whether disappearing messages is enabled (default: true)
94
+ */
95
+ async setDisappearing(recipient, duration = 86400, enabled = true) {
96
+ return this.request({
97
+ method: 'POST',
98
+ path: this.buildPath('chats/disappearing'),
99
+ body: { recipient, duration, enabled },
100
+ });
101
+ }
102
+ /**
103
+ * Requests older chat history from the linked phone.
104
+ */
105
+ async fetchHistory(options) {
106
+ return this.request({
107
+ method: 'POST',
108
+ path: this.buildPath('chats/fetch-history'),
109
+ body: options || {},
110
+ });
111
+ }
112
+ }
113
+ exports.ChatsModule = ChatsModule;
@@ -0,0 +1,106 @@
1
+ import { BaseModule } from './base.js';
2
+ import { ChatItem, ContactItem, SyncedMessageItem, ListChatsParams, ListContactsParams, ListMessagesParams, ChatModifyOptions, FetchHistoryOptions } from '../types/index.js';
3
+ export declare class ChatsModule extends BaseModule {
4
+ /**
5
+ * Lists synced WhatsApp chats with optional search and pagination.
6
+ */
7
+ list(params?: ListChatsParams): Promise<{
8
+ instanceId: string;
9
+ chats: ChatItem[];
10
+ total: number;
11
+ }>;
12
+ /**
13
+ * Lists synced WhatsApp contacts.
14
+ */
15
+ listContacts(params?: ListContactsParams): Promise<{
16
+ instanceId: string;
17
+ contacts: ContactItem[];
18
+ total: number;
19
+ }>;
20
+ /**
21
+ * Lists synced chat messages.
22
+ */
23
+ listMessages(params?: ListMessagesParams): Promise<{
24
+ instanceId: string;
25
+ messages: SyncedMessageItem[];
26
+ total: number;
27
+ }>;
28
+ /**
29
+ * Modifies a chat state (archive, mute, read, pin, star, delete).
30
+ */
31
+ modify(options: ChatModifyOptions): Promise<{
32
+ success: boolean;
33
+ message: string;
34
+ result?: any;
35
+ }>;
36
+ /**
37
+ * Archives a chat.
38
+ */
39
+ archive(targetJid: string): Promise<{
40
+ success: boolean;
41
+ message: string;
42
+ }>;
43
+ /**
44
+ * Unarchives a chat.
45
+ */
46
+ unarchive(targetJid: string): Promise<{
47
+ success: boolean;
48
+ message: string;
49
+ }>;
50
+ /**
51
+ * Mutes chat notifications for a specified duration in milliseconds (default: 8 hours).
52
+ */
53
+ mute(targetJid: string, durationMs?: number): Promise<{
54
+ success: boolean;
55
+ message: string;
56
+ }>;
57
+ /**
58
+ * Unmutes chat notifications.
59
+ */
60
+ unmute(targetJid: string): Promise<{
61
+ success: boolean;
62
+ message: string;
63
+ }>;
64
+ /**
65
+ * Pins a chat to the top of the chat list.
66
+ */
67
+ pin(targetJid: string): Promise<{
68
+ success: boolean;
69
+ message: string;
70
+ }>;
71
+ /**
72
+ * Unpins a chat from the top.
73
+ */
74
+ unpin(targetJid: string): Promise<{
75
+ success: boolean;
76
+ message: string;
77
+ }>;
78
+ /**
79
+ * Deletes an entire chat conversation.
80
+ */
81
+ deleteChat(targetJid: string): Promise<{
82
+ success: boolean;
83
+ message: string;
84
+ }>;
85
+ /**
86
+ * Configures disappearing messages for a chat.
87
+ *
88
+ * @param recipient Target chat JID or phone number
89
+ * @param duration Duration in seconds (86400: 24h, 604800: 7d, 7776000: 90d)
90
+ * @param enabled Whether disappearing messages is enabled (default: true)
91
+ */
92
+ setDisappearing(recipient: string, duration?: number, enabled?: boolean): Promise<{
93
+ success: boolean;
94
+ message: string;
95
+ result?: any;
96
+ }>;
97
+ /**
98
+ * Requests older chat history from the linked phone.
99
+ */
100
+ fetchHistory(options?: FetchHistoryOptions): Promise<{
101
+ success: boolean;
102
+ message: string;
103
+ result?: any;
104
+ }>;
105
+ }
106
+ //# sourceMappingURL=chats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chats.d.ts","sourceRoot":"","sources":["../../../src/modules/chats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACL,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,kBAAkB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