btechworks-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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BatchWorks
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # BTechWorks SDK
2
+
3
+ Official BTechWorks WhatsApp CRM SDK for Node.js. Send messages, photos, videos, documents, templates, and broadcasts via the BTechWorks API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install btechworks-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { BTechWorksClient } from 'btechworks-sdk';
15
+
16
+ const client = new BTechWorksClient({
17
+ apiKey: 'wk_your_api_key_here',
18
+ secretKey: 'ws_your_secret_key_here',
19
+ });
20
+
21
+ // Send a text message - bas phone aur message do, baaki SDK sambhalega
22
+ const result = await client.sendMessage({
23
+ phone: '+1234567890',
24
+ message: 'Hello from BTechWorks SDK!',
25
+ });
26
+
27
+ console.log(result);
28
+ // { success: true, messageId: '...', whatsappMessageId: '...' }
29
+ ```
30
+
31
+ ## Configuration
32
+
33
+ ```typescript
34
+ const client = new BTechWorksClient({
35
+ apiKey: 'wk_...', // Required: Your API key
36
+ secretKey: 'ws_...', // Required: Your secret key
37
+ baseUrl: 'https://api.btechworks.io', // Optional: Custom API URL
38
+ timeout: 30000, // Optional: Request timeout in ms (default: 30000)
39
+ });
40
+ ```
41
+
42
+ ## Methods
43
+
44
+ ### sendMessage
45
+
46
+ Send a text message to a phone number. Contact and conversation are auto-created if they don't exist.
47
+
48
+ ```typescript
49
+ const result = await client.sendMessage({
50
+ phone: '+1234567890',
51
+ message: 'Hello World!',
52
+ });
53
+ ```
54
+
55
+ ### sendPhoto
56
+
57
+ Send an image with an optional caption.
58
+
59
+ ```typescript
60
+ const result = await client.sendPhoto({
61
+ phone: '+1234567890',
62
+ imageUrl: 'https://example.com/photo.jpg',
63
+ caption: 'Check out this photo!',
64
+ });
65
+ ```
66
+
67
+ ### sendVideo
68
+
69
+ Send a video with an optional caption.
70
+
71
+ ```typescript
72
+ const result = await client.sendVideo({
73
+ phone: '+1234567890',
74
+ videoUrl: 'https://example.com/video.mp4',
75
+ caption: 'Watch this video!',
76
+ });
77
+ ```
78
+
79
+ ### sendDocument
80
+
81
+ Send a document (PDF, DOC, etc.) with an optional caption.
82
+
83
+ ```typescript
84
+ const result = await client.sendDocument({
85
+ phone: '+1234567890',
86
+ documentUrl: 'https://example.com/invoice.pdf',
87
+ filename: 'invoice.pdf',
88
+ caption: 'Your invoice for this month',
89
+ });
90
+ ```
91
+
92
+ ### sendTemplate
93
+
94
+ Send a WhatsApp template message with variables.
95
+
96
+ ```typescript
97
+ // Simple template with body variables
98
+ const result = await client.sendTemplate({
99
+ phone: '+1234567890',
100
+ templateName: 'order_confirmation',
101
+ templateLanguage: 'en_US',
102
+ templateParams: ['John', 'Order #12345'],
103
+ });
104
+
105
+ // Template with header media and button params
106
+ const result2 = await client.sendTemplate({
107
+ phone: '+1234567890',
108
+ templateName: 'promo_template',
109
+ templateLanguage: 'en_US',
110
+ templateMessageParams: {
111
+ header: {
112
+ type: 'image',
113
+ url: 'https://example.com/promo.jpg',
114
+ },
115
+ body: ['John', '50%'],
116
+ buttons: [
117
+ { type: 'url', suffix: 'promo50' },
118
+ ],
119
+ },
120
+ });
121
+ ```
122
+
123
+ ### broadcast
124
+
125
+ Send a template message to multiple recipients.
126
+
127
+ ```typescript
128
+ const result = await client.broadcast({
129
+ name: 'Summer Sale Campaign',
130
+ templateName: 'summer_sale',
131
+ templateLanguage: 'en_US',
132
+ templateVariables: { code: 'SUMMER50' },
133
+ recipients: ['+1234567890', '+0987654321', '+1122334455'],
134
+ });
135
+
136
+ // Or use audience filter by tags
137
+ const result2 = await client.broadcast({
138
+ name: 'VIP Customers',
139
+ templateName: 'vip_offer',
140
+ recipients: [],
141
+ audienceFilter: { tags: ['vip', 'premium'] },
142
+ });
143
+ ```
144
+
145
+ ## Error Handling
146
+
147
+ All methods throw `BTechWorksError` on failure:
148
+
149
+ ```typescript
150
+ import { BTechWorksClient, BTechWorksError } from 'btechworks-sdk';
151
+
152
+ try {
153
+ await client.sendMessage({
154
+ phone: '+1234567890',
155
+ message: 'Hello!',
156
+ });
157
+ } catch (error) {
158
+ if (error instanceof BTechWorksError) {
159
+ console.log(error.message); // Error message
160
+ console.log(error.statusCode); // HTTP status code
161
+ console.log(error.details); // Additional error details
162
+ }
163
+ }
164
+ ```
165
+
166
+ ## How It Works
167
+
168
+ 1. **Phone number se sab kuch hota hai** - Contact aur conversation automatically create ho jaate hain
169
+ 2. **API key + Secret key se auth hota hai** - Dashboard se API key banao, SDK mein daalo, kaam shuru
170
+ 3. **Server sab handle karta hai** - Contact lookup, conversation creation, Meta API calls, message storage
171
+
172
+ ## Getting API Keys
173
+
174
+ 1. Login to your BTechWorks dashboard
175
+ 2. Go to Settings > API Keys
176
+ 3. Click "Create API Key"
177
+ 4. Copy both the API Key and Secret Key (secret is shown only once)
178
+
179
+ ## License
180
+
181
+ MIT
@@ -0,0 +1,94 @@
1
+ interface BTechWorksConfig {
2
+ apiKey: string;
3
+ secretKey: string;
4
+ baseUrl?: string;
5
+ timeout?: number;
6
+ }
7
+ interface SendMessageOptions {
8
+ phone: string;
9
+ message: string;
10
+ }
11
+ interface SendPhotoOptions {
12
+ phone: string;
13
+ imageUrl: string;
14
+ caption?: string;
15
+ }
16
+ interface SendVideoOptions {
17
+ phone: string;
18
+ videoUrl: string;
19
+ caption?: string;
20
+ }
21
+ interface SendDocumentOptions {
22
+ phone: string;
23
+ documentUrl: string;
24
+ filename?: string;
25
+ caption?: string;
26
+ }
27
+ interface SendTemplateOptions {
28
+ phone: string;
29
+ templateName: string;
30
+ templateLanguage?: string;
31
+ templateParams?: string[];
32
+ templateMessageParams?: {
33
+ header?: {
34
+ type: 'image' | 'video' | 'document';
35
+ url: string;
36
+ filename?: string;
37
+ };
38
+ body?: string[];
39
+ buttons?: Array<{
40
+ type: string;
41
+ suffix?: string;
42
+ }>;
43
+ };
44
+ }
45
+ interface BroadcastOptions {
46
+ name: string;
47
+ templateName: string;
48
+ templateLanguage?: string;
49
+ templateVariables?: Record<string, string>;
50
+ recipients?: string[];
51
+ audienceFilter?: {
52
+ tags?: string[];
53
+ };
54
+ }
55
+ interface ApiResponse {
56
+ success: boolean;
57
+ message_id?: string;
58
+ whatsapp_message_id?: string;
59
+ error?: string;
60
+ }
61
+ interface BroadcastResponse {
62
+ success: boolean;
63
+ broadcast_id?: string;
64
+ total_recipients?: number;
65
+ status?: string;
66
+ error?: string;
67
+ }
68
+ interface ApiError {
69
+ error: string;
70
+ statusCode: number;
71
+ details?: Record<string, unknown>;
72
+ }
73
+
74
+ declare class BTechWorksError extends Error {
75
+ statusCode: number;
76
+ details?: Record<string, unknown>;
77
+ constructor(message: string, statusCode: number, details?: Record<string, unknown>);
78
+ }
79
+ declare class BTechWorksClient {
80
+ private apiKey;
81
+ private secretKey;
82
+ private baseUrl;
83
+ private timeout;
84
+ constructor(config: BTechWorksConfig);
85
+ private request;
86
+ sendMessage(options: SendMessageOptions): Promise<ApiResponse>;
87
+ sendPhoto(options: SendPhotoOptions): Promise<ApiResponse>;
88
+ sendVideo(options: SendVideoOptions): Promise<ApiResponse>;
89
+ sendDocument(options: SendDocumentOptions): Promise<ApiResponse>;
90
+ sendTemplate(options: SendTemplateOptions): Promise<ApiResponse>;
91
+ broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
92
+ }
93
+
94
+ export { type ApiError, type ApiResponse, BTechWorksClient, type BTechWorksConfig, BTechWorksError, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
@@ -0,0 +1,94 @@
1
+ interface BTechWorksConfig {
2
+ apiKey: string;
3
+ secretKey: string;
4
+ baseUrl?: string;
5
+ timeout?: number;
6
+ }
7
+ interface SendMessageOptions {
8
+ phone: string;
9
+ message: string;
10
+ }
11
+ interface SendPhotoOptions {
12
+ phone: string;
13
+ imageUrl: string;
14
+ caption?: string;
15
+ }
16
+ interface SendVideoOptions {
17
+ phone: string;
18
+ videoUrl: string;
19
+ caption?: string;
20
+ }
21
+ interface SendDocumentOptions {
22
+ phone: string;
23
+ documentUrl: string;
24
+ filename?: string;
25
+ caption?: string;
26
+ }
27
+ interface SendTemplateOptions {
28
+ phone: string;
29
+ templateName: string;
30
+ templateLanguage?: string;
31
+ templateParams?: string[];
32
+ templateMessageParams?: {
33
+ header?: {
34
+ type: 'image' | 'video' | 'document';
35
+ url: string;
36
+ filename?: string;
37
+ };
38
+ body?: string[];
39
+ buttons?: Array<{
40
+ type: string;
41
+ suffix?: string;
42
+ }>;
43
+ };
44
+ }
45
+ interface BroadcastOptions {
46
+ name: string;
47
+ templateName: string;
48
+ templateLanguage?: string;
49
+ templateVariables?: Record<string, string>;
50
+ recipients?: string[];
51
+ audienceFilter?: {
52
+ tags?: string[];
53
+ };
54
+ }
55
+ interface ApiResponse {
56
+ success: boolean;
57
+ message_id?: string;
58
+ whatsapp_message_id?: string;
59
+ error?: string;
60
+ }
61
+ interface BroadcastResponse {
62
+ success: boolean;
63
+ broadcast_id?: string;
64
+ total_recipients?: number;
65
+ status?: string;
66
+ error?: string;
67
+ }
68
+ interface ApiError {
69
+ error: string;
70
+ statusCode: number;
71
+ details?: Record<string, unknown>;
72
+ }
73
+
74
+ declare class BTechWorksError extends Error {
75
+ statusCode: number;
76
+ details?: Record<string, unknown>;
77
+ constructor(message: string, statusCode: number, details?: Record<string, unknown>);
78
+ }
79
+ declare class BTechWorksClient {
80
+ private apiKey;
81
+ private secretKey;
82
+ private baseUrl;
83
+ private timeout;
84
+ constructor(config: BTechWorksConfig);
85
+ private request;
86
+ sendMessage(options: SendMessageOptions): Promise<ApiResponse>;
87
+ sendPhoto(options: SendPhotoOptions): Promise<ApiResponse>;
88
+ sendVideo(options: SendVideoOptions): Promise<ApiResponse>;
89
+ sendDocument(options: SendDocumentOptions): Promise<ApiResponse>;
90
+ sendTemplate(options: SendTemplateOptions): Promise<ApiResponse>;
91
+ broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
92
+ }
93
+
94
+ export { type ApiError, type ApiResponse, BTechWorksClient, type BTechWorksConfig, BTechWorksError, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
package/dist/index.js ADDED
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BTechWorksClient: () => BTechWorksClient,
24
+ BTechWorksError: () => BTechWorksError
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/client.ts
29
+ var BTechWorksError = class extends Error {
30
+ constructor(message, statusCode, details) {
31
+ super(message);
32
+ this.name = "BTechWorksError";
33
+ this.statusCode = statusCode;
34
+ this.details = details;
35
+ }
36
+ };
37
+ var BTechWorksClient = class {
38
+ constructor(config) {
39
+ if (!config.apiKey) {
40
+ throw new Error("apiKey is required");
41
+ }
42
+ if (!config.secretKey) {
43
+ throw new Error("secretKey is required");
44
+ }
45
+ this.apiKey = config.apiKey;
46
+ this.secretKey = config.secretKey;
47
+ this.baseUrl = (config.baseUrl || "https://api.btechworks.io").replace(/\/+$/, "");
48
+ this.timeout = config.timeout || 3e4;
49
+ }
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ async request(path, options = {}) {
52
+ const url = `${this.baseUrl}${path}`;
53
+ const headers = {
54
+ "x-api-key": this.apiKey,
55
+ "x-secret-key": this.secretKey,
56
+ "Content-Type": "application/json",
57
+ ...options.headers
58
+ };
59
+ const controller = new AbortController();
60
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
61
+ try {
62
+ const response = await globalThis.fetch(url, {
63
+ ...options,
64
+ headers,
65
+ signal: controller.signal
66
+ });
67
+ const data = await response.json();
68
+ if (!response.ok) {
69
+ throw new BTechWorksError(
70
+ data.error || `Request failed with status ${response.status}`,
71
+ response.status,
72
+ data
73
+ );
74
+ }
75
+ return data;
76
+ } catch (error) {
77
+ if (error instanceof BTechWorksError) throw error;
78
+ if (error instanceof DOMException && error.name === "AbortError") {
79
+ throw new BTechWorksError("Request timeout", 408);
80
+ }
81
+ throw new BTechWorksError(
82
+ error instanceof Error ? error.message : "Unknown error",
83
+ 500
84
+ );
85
+ } finally {
86
+ clearTimeout(timeoutId);
87
+ }
88
+ }
89
+ async sendMessage(options) {
90
+ const data = await this.request("/api/sdk/send-message", {
91
+ method: "POST",
92
+ body: JSON.stringify({
93
+ phone: options.phone,
94
+ message: options.message
95
+ })
96
+ });
97
+ return {
98
+ success: data.success,
99
+ message_id: data.message_id,
100
+ whatsapp_message_id: data.whatsapp_message_id
101
+ };
102
+ }
103
+ async sendPhoto(options) {
104
+ const data = await this.request("/api/sdk/send-photo", {
105
+ method: "POST",
106
+ body: JSON.stringify({
107
+ phone: options.phone,
108
+ image_url: options.imageUrl,
109
+ caption: options.caption
110
+ })
111
+ });
112
+ return {
113
+ success: data.success,
114
+ message_id: data.message_id,
115
+ whatsapp_message_id: data.whatsapp_message_id
116
+ };
117
+ }
118
+ async sendVideo(options) {
119
+ const data = await this.request("/api/sdk/send-video", {
120
+ method: "POST",
121
+ body: JSON.stringify({
122
+ phone: options.phone,
123
+ video_url: options.videoUrl,
124
+ caption: options.caption
125
+ })
126
+ });
127
+ return {
128
+ success: data.success,
129
+ message_id: data.message_id,
130
+ whatsapp_message_id: data.whatsapp_message_id
131
+ };
132
+ }
133
+ async sendDocument(options) {
134
+ const data = await this.request("/api/sdk/send-document", {
135
+ method: "POST",
136
+ body: JSON.stringify({
137
+ phone: options.phone,
138
+ document_url: options.documentUrl,
139
+ filename: options.filename,
140
+ caption: options.caption
141
+ })
142
+ });
143
+ return {
144
+ success: data.success,
145
+ message_id: data.message_id,
146
+ whatsapp_message_id: data.whatsapp_message_id
147
+ };
148
+ }
149
+ async sendTemplate(options) {
150
+ const data = await this.request("/api/sdk/send-template", {
151
+ method: "POST",
152
+ body: JSON.stringify({
153
+ phone: options.phone,
154
+ template_name: options.templateName,
155
+ template_language: options.templateLanguage,
156
+ template_params: options.templateParams,
157
+ template_message_params: options.templateMessageParams
158
+ })
159
+ });
160
+ return {
161
+ success: data.success,
162
+ message_id: data.message_id,
163
+ whatsapp_message_id: data.whatsapp_message_id
164
+ };
165
+ }
166
+ async broadcast(options) {
167
+ const data = await this.request("/api/sdk/broadcast", {
168
+ method: "POST",
169
+ body: JSON.stringify({
170
+ name: options.name,
171
+ template_name: options.templateName,
172
+ template_language: options.templateLanguage,
173
+ template_variables: options.templateVariables,
174
+ recipients: options.recipients,
175
+ audience_filter: options.audienceFilter
176
+ })
177
+ });
178
+ return {
179
+ success: data.success,
180
+ broadcast_id: data.broadcast_id,
181
+ total_recipients: data.total_recipients,
182
+ status: data.status
183
+ };
184
+ }
185
+ };
186
+ // Annotate the CommonJS export names for ESM import in node:
187
+ 0 && (module.exports = {
188
+ BTechWorksClient,
189
+ BTechWorksError
190
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,162 @@
1
+ // src/client.ts
2
+ var BTechWorksError = class extends Error {
3
+ constructor(message, statusCode, details) {
4
+ super(message);
5
+ this.name = "BTechWorksError";
6
+ this.statusCode = statusCode;
7
+ this.details = details;
8
+ }
9
+ };
10
+ var BTechWorksClient = class {
11
+ constructor(config) {
12
+ if (!config.apiKey) {
13
+ throw new Error("apiKey is required");
14
+ }
15
+ if (!config.secretKey) {
16
+ throw new Error("secretKey is required");
17
+ }
18
+ this.apiKey = config.apiKey;
19
+ this.secretKey = config.secretKey;
20
+ this.baseUrl = (config.baseUrl || "https://api.btechworks.io").replace(/\/+$/, "");
21
+ this.timeout = config.timeout || 3e4;
22
+ }
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ async request(path, options = {}) {
25
+ const url = `${this.baseUrl}${path}`;
26
+ const headers = {
27
+ "x-api-key": this.apiKey,
28
+ "x-secret-key": this.secretKey,
29
+ "Content-Type": "application/json",
30
+ ...options.headers
31
+ };
32
+ const controller = new AbortController();
33
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
34
+ try {
35
+ const response = await globalThis.fetch(url, {
36
+ ...options,
37
+ headers,
38
+ signal: controller.signal
39
+ });
40
+ const data = await response.json();
41
+ if (!response.ok) {
42
+ throw new BTechWorksError(
43
+ data.error || `Request failed with status ${response.status}`,
44
+ response.status,
45
+ data
46
+ );
47
+ }
48
+ return data;
49
+ } catch (error) {
50
+ if (error instanceof BTechWorksError) throw error;
51
+ if (error instanceof DOMException && error.name === "AbortError") {
52
+ throw new BTechWorksError("Request timeout", 408);
53
+ }
54
+ throw new BTechWorksError(
55
+ error instanceof Error ? error.message : "Unknown error",
56
+ 500
57
+ );
58
+ } finally {
59
+ clearTimeout(timeoutId);
60
+ }
61
+ }
62
+ async sendMessage(options) {
63
+ const data = await this.request("/api/sdk/send-message", {
64
+ method: "POST",
65
+ body: JSON.stringify({
66
+ phone: options.phone,
67
+ message: options.message
68
+ })
69
+ });
70
+ return {
71
+ success: data.success,
72
+ message_id: data.message_id,
73
+ whatsapp_message_id: data.whatsapp_message_id
74
+ };
75
+ }
76
+ async sendPhoto(options) {
77
+ const data = await this.request("/api/sdk/send-photo", {
78
+ method: "POST",
79
+ body: JSON.stringify({
80
+ phone: options.phone,
81
+ image_url: options.imageUrl,
82
+ caption: options.caption
83
+ })
84
+ });
85
+ return {
86
+ success: data.success,
87
+ message_id: data.message_id,
88
+ whatsapp_message_id: data.whatsapp_message_id
89
+ };
90
+ }
91
+ async sendVideo(options) {
92
+ const data = await this.request("/api/sdk/send-video", {
93
+ method: "POST",
94
+ body: JSON.stringify({
95
+ phone: options.phone,
96
+ video_url: options.videoUrl,
97
+ caption: options.caption
98
+ })
99
+ });
100
+ return {
101
+ success: data.success,
102
+ message_id: data.message_id,
103
+ whatsapp_message_id: data.whatsapp_message_id
104
+ };
105
+ }
106
+ async sendDocument(options) {
107
+ const data = await this.request("/api/sdk/send-document", {
108
+ method: "POST",
109
+ body: JSON.stringify({
110
+ phone: options.phone,
111
+ document_url: options.documentUrl,
112
+ filename: options.filename,
113
+ caption: options.caption
114
+ })
115
+ });
116
+ return {
117
+ success: data.success,
118
+ message_id: data.message_id,
119
+ whatsapp_message_id: data.whatsapp_message_id
120
+ };
121
+ }
122
+ async sendTemplate(options) {
123
+ const data = await this.request("/api/sdk/send-template", {
124
+ method: "POST",
125
+ body: JSON.stringify({
126
+ phone: options.phone,
127
+ template_name: options.templateName,
128
+ template_language: options.templateLanguage,
129
+ template_params: options.templateParams,
130
+ template_message_params: options.templateMessageParams
131
+ })
132
+ });
133
+ return {
134
+ success: data.success,
135
+ message_id: data.message_id,
136
+ whatsapp_message_id: data.whatsapp_message_id
137
+ };
138
+ }
139
+ async broadcast(options) {
140
+ const data = await this.request("/api/sdk/broadcast", {
141
+ method: "POST",
142
+ body: JSON.stringify({
143
+ name: options.name,
144
+ template_name: options.templateName,
145
+ template_language: options.templateLanguage,
146
+ template_variables: options.templateVariables,
147
+ recipients: options.recipients,
148
+ audience_filter: options.audienceFilter
149
+ })
150
+ });
151
+ return {
152
+ success: data.success,
153
+ broadcast_id: data.broadcast_id,
154
+ total_recipients: data.total_recipients,
155
+ status: data.status
156
+ };
157
+ }
158
+ };
159
+ export {
160
+ BTechWorksClient,
161
+ BTechWorksError
162
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "btechworks-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Official BatchWorks WhatsApp CRM SDK - Send messages, photos, videos, documents, templates, and broadcasts via API",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsup src/index.ts --format cjs,esm --dts",
22
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch"
23
+ },
24
+ "keywords": [
25
+ "whatsapp",
26
+ "crm",
27
+ "api",
28
+ "sdk",
29
+ "messaging",
30
+ "broadcast",
31
+ "template",
32
+ "batchworks"
33
+ ],
34
+ "author": "BatchWorks",
35
+ "license": "MIT",
36
+ "devDependencies": {
37
+ "tsup": "^8.0.0",
38
+ "typescript": "^5.3.0"
39
+ },
40
+ "engines": {
41
+ "node": ">=18.0.0"
42
+ }
43
+ }