btechworks-sdk 1.0.0 → 1.0.1

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 CHANGED
@@ -1,21 +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.
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 CHANGED
@@ -18,14 +18,13 @@ const client = new BTechWorksClient({
18
18
  secretKey: 'ws_your_secret_key_here',
19
19
  });
20
20
 
21
- // Send a text message - bas phone aur message do, baaki SDK sambhalega
22
21
  const result = await client.sendMessage({
23
22
  phone: '+1234567890',
24
23
  message: 'Hello from BTechWorks SDK!',
25
24
  });
26
25
 
27
26
  console.log(result);
28
- // { success: true, messageId: '...', whatsappMessageId: '...' }
27
+ // { success: true, message: 'Message sent successfully' }
29
28
  ```
30
29
 
31
30
  ## Configuration
@@ -43,13 +42,14 @@ const client = new BTechWorksClient({
43
42
 
44
43
  ### sendMessage
45
44
 
46
- Send a text message to a phone number. Contact and conversation are auto-created if they don't exist.
45
+ Send a text message to a phone number. Contact and conversation are auto-created.
47
46
 
48
47
  ```typescript
49
48
  const result = await client.sendMessage({
50
49
  phone: '+1234567890',
51
50
  message: 'Hello World!',
52
51
  });
52
+ // { success: true, message: 'Message sent successfully' }
53
53
  ```
54
54
 
55
55
  ### sendPhoto
@@ -62,6 +62,7 @@ const result = await client.sendPhoto({
62
62
  imageUrl: 'https://example.com/photo.jpg',
63
63
  caption: 'Check out this photo!',
64
64
  });
65
+ // { success: true, message: 'Photo sent successfully' }
65
66
  ```
66
67
 
67
68
  ### sendVideo
@@ -74,6 +75,7 @@ const result = await client.sendVideo({
74
75
  videoUrl: 'https://example.com/video.mp4',
75
76
  caption: 'Watch this video!',
76
77
  });
78
+ // { success: true, message: 'Video sent successfully' }
77
79
  ```
78
80
 
79
81
  ### sendDocument
@@ -87,6 +89,7 @@ const result = await client.sendDocument({
87
89
  filename: 'invoice.pdf',
88
90
  caption: 'Your invoice for this month',
89
91
  });
92
+ // { success: true, message: 'Document sent successfully' }
90
93
  ```
91
94
 
92
95
  ### sendTemplate
@@ -101,6 +104,7 @@ const result = await client.sendTemplate({
101
104
  templateLanguage: 'en_US',
102
105
  templateParams: ['John', 'Order #12345'],
103
106
  });
107
+ // { success: true, message: 'Template sent successfully' }
104
108
 
105
109
  // Template with header media and button params
106
110
  const result2 = await client.sendTemplate({
@@ -108,14 +112,9 @@ const result2 = await client.sendTemplate({
108
112
  templateName: 'promo_template',
109
113
  templateLanguage: 'en_US',
110
114
  templateMessageParams: {
111
- header: {
112
- type: 'image',
113
- url: 'https://example.com/promo.jpg',
114
- },
115
+ header: { type: 'image', url: 'https://example.com/promo.jpg' },
115
116
  body: ['John', '50%'],
116
- buttons: [
117
- { type: 'url', suffix: 'promo50' },
118
- ],
117
+ buttons: [{ type: 'url', suffix: 'promo50' }],
119
118
  },
120
119
  });
121
120
  ```
@@ -132,6 +131,7 @@ const result = await client.broadcast({
132
131
  templateVariables: { code: 'SUMMER50' },
133
132
  recipients: ['+1234567890', '+0987654321', '+1122334455'],
134
133
  });
134
+ // { success: true, message: 'Template "summer_sale" processed: 20 sent, 5 failed' }
135
135
 
136
136
  // Or use audience filter by tags
137
137
  const result2 = await client.broadcast({
@@ -140,6 +140,22 @@ const result2 = await client.broadcast({
140
140
  recipients: [],
141
141
  audienceFilter: { tags: ['vip', 'premium'] },
142
142
  });
143
+ // { success: true, message: 'Template "vip_offer" processed: 50 sent, 10 skipped, 3 failed' }
144
+ ```
145
+
146
+ ## Response Format
147
+
148
+ All methods return a simple response:
149
+
150
+ ```typescript
151
+ // Single message
152
+ { success: true, message: 'Message sent successfully' }
153
+
154
+ // Broadcast
155
+ { success: true, message: 'Template "promo" processed: 20 sent, 10 skipped, 5 failed' }
156
+
157
+ // Error (throws BTechWorksError)
158
+ { success: false, message: 'Invalid phone number format' }
143
159
  ```
144
160
 
145
161
  ## Error Handling
@@ -150,15 +166,11 @@ All methods throw `BTechWorksError` on failure:
150
166
  import { BTechWorksClient, BTechWorksError } from 'btechworks-sdk';
151
167
 
152
168
  try {
153
- await client.sendMessage({
154
- phone: '+1234567890',
155
- message: 'Hello!',
156
- });
169
+ await client.sendMessage({ phone: '+1234567890', message: 'Hello!' });
157
170
  } catch (error) {
158
171
  if (error instanceof BTechWorksError) {
159
172
  console.log(error.message); // Error message
160
173
  console.log(error.statusCode); // HTTP status code
161
- console.log(error.details); // Additional error details
162
174
  }
163
175
  }
164
176
  ```
@@ -172,7 +184,7 @@ try {
172
184
  ## Getting API Keys
173
185
 
174
186
  1. Login to your BTechWorks dashboard
175
- 2. Go to Settings > API Keys
187
+ 2. Go to Settings > API Key
176
188
  3. Click "Create API Key"
177
189
  4. Copy both the API Key and Secret Key (secret is shown only once)
178
190
 
package/dist/index.d.mts CHANGED
@@ -54,21 +54,11 @@ interface BroadcastOptions {
54
54
  }
55
55
  interface ApiResponse {
56
56
  success: boolean;
57
- message_id?: string;
58
- whatsapp_message_id?: string;
59
- error?: string;
57
+ message: string;
60
58
  }
61
59
  interface BroadcastResponse {
62
60
  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>;
61
+ message: string;
72
62
  }
73
63
 
74
64
  declare class BTechWorksError extends Error {
@@ -91,4 +81,4 @@ declare class BTechWorksClient {
91
81
  broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
92
82
  }
93
83
 
94
- export { type ApiError, type ApiResponse, BTechWorksClient, type BTechWorksConfig, BTechWorksError, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
84
+ export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, BTechWorksError, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
package/dist/index.d.ts CHANGED
@@ -54,21 +54,11 @@ interface BroadcastOptions {
54
54
  }
55
55
  interface ApiResponse {
56
56
  success: boolean;
57
- message_id?: string;
58
- whatsapp_message_id?: string;
59
- error?: string;
57
+ message: string;
60
58
  }
61
59
  interface BroadcastResponse {
62
60
  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>;
61
+ message: string;
72
62
  }
73
63
 
74
64
  declare class BTechWorksError extends Error {
@@ -91,4 +81,4 @@ declare class BTechWorksClient {
91
81
  broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
92
82
  }
93
83
 
94
- export { type ApiError, type ApiResponse, BTechWorksClient, type BTechWorksConfig, BTechWorksError, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
84
+ export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, BTechWorksError, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
package/dist/index.js CHANGED
@@ -67,7 +67,7 @@ var BTechWorksClient = class {
67
67
  const data = await response.json();
68
68
  if (!response.ok) {
69
69
  throw new BTechWorksError(
70
- data.error || `Request failed with status ${response.status}`,
70
+ data.message || data.error || `Request failed with status ${response.status}`,
71
71
  response.status,
72
72
  data
73
73
  );
@@ -87,21 +87,16 @@ var BTechWorksClient = class {
87
87
  }
88
88
  }
89
89
  async sendMessage(options) {
90
- const data = await this.request("/api/sdk/send-message", {
90
+ return this.request("/api/sdk/send-message", {
91
91
  method: "POST",
92
92
  body: JSON.stringify({
93
93
  phone: options.phone,
94
94
  message: options.message
95
95
  })
96
96
  });
97
- return {
98
- success: data.success,
99
- message_id: data.message_id,
100
- whatsapp_message_id: data.whatsapp_message_id
101
- };
102
97
  }
103
98
  async sendPhoto(options) {
104
- const data = await this.request("/api/sdk/send-photo", {
99
+ return this.request("/api/sdk/send-photo", {
105
100
  method: "POST",
106
101
  body: JSON.stringify({
107
102
  phone: options.phone,
@@ -109,14 +104,9 @@ var BTechWorksClient = class {
109
104
  caption: options.caption
110
105
  })
111
106
  });
112
- return {
113
- success: data.success,
114
- message_id: data.message_id,
115
- whatsapp_message_id: data.whatsapp_message_id
116
- };
117
107
  }
118
108
  async sendVideo(options) {
119
- const data = await this.request("/api/sdk/send-video", {
109
+ return this.request("/api/sdk/send-video", {
120
110
  method: "POST",
121
111
  body: JSON.stringify({
122
112
  phone: options.phone,
@@ -124,14 +114,9 @@ var BTechWorksClient = class {
124
114
  caption: options.caption
125
115
  })
126
116
  });
127
- return {
128
- success: data.success,
129
- message_id: data.message_id,
130
- whatsapp_message_id: data.whatsapp_message_id
131
- };
132
117
  }
133
118
  async sendDocument(options) {
134
- const data = await this.request("/api/sdk/send-document", {
119
+ return this.request("/api/sdk/send-document", {
135
120
  method: "POST",
136
121
  body: JSON.stringify({
137
122
  phone: options.phone,
@@ -140,14 +125,9 @@ var BTechWorksClient = class {
140
125
  caption: options.caption
141
126
  })
142
127
  });
143
- return {
144
- success: data.success,
145
- message_id: data.message_id,
146
- whatsapp_message_id: data.whatsapp_message_id
147
- };
148
128
  }
149
129
  async sendTemplate(options) {
150
- const data = await this.request("/api/sdk/send-template", {
130
+ return this.request("/api/sdk/send-template", {
151
131
  method: "POST",
152
132
  body: JSON.stringify({
153
133
  phone: options.phone,
@@ -157,14 +137,9 @@ var BTechWorksClient = class {
157
137
  template_message_params: options.templateMessageParams
158
138
  })
159
139
  });
160
- return {
161
- success: data.success,
162
- message_id: data.message_id,
163
- whatsapp_message_id: data.whatsapp_message_id
164
- };
165
140
  }
166
141
  async broadcast(options) {
167
- const data = await this.request("/api/sdk/broadcast", {
142
+ return this.request("/api/sdk/broadcast", {
168
143
  method: "POST",
169
144
  body: JSON.stringify({
170
145
  name: options.name,
@@ -175,12 +150,6 @@ var BTechWorksClient = class {
175
150
  audience_filter: options.audienceFilter
176
151
  })
177
152
  });
178
- return {
179
- success: data.success,
180
- broadcast_id: data.broadcast_id,
181
- total_recipients: data.total_recipients,
182
- status: data.status
183
- };
184
153
  }
185
154
  };
186
155
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -40,7 +40,7 @@ var BTechWorksClient = class {
40
40
  const data = await response.json();
41
41
  if (!response.ok) {
42
42
  throw new BTechWorksError(
43
- data.error || `Request failed with status ${response.status}`,
43
+ data.message || data.error || `Request failed with status ${response.status}`,
44
44
  response.status,
45
45
  data
46
46
  );
@@ -60,21 +60,16 @@ var BTechWorksClient = class {
60
60
  }
61
61
  }
62
62
  async sendMessage(options) {
63
- const data = await this.request("/api/sdk/send-message", {
63
+ return this.request("/api/sdk/send-message", {
64
64
  method: "POST",
65
65
  body: JSON.stringify({
66
66
  phone: options.phone,
67
67
  message: options.message
68
68
  })
69
69
  });
70
- return {
71
- success: data.success,
72
- message_id: data.message_id,
73
- whatsapp_message_id: data.whatsapp_message_id
74
- };
75
70
  }
76
71
  async sendPhoto(options) {
77
- const data = await this.request("/api/sdk/send-photo", {
72
+ return this.request("/api/sdk/send-photo", {
78
73
  method: "POST",
79
74
  body: JSON.stringify({
80
75
  phone: options.phone,
@@ -82,14 +77,9 @@ var BTechWorksClient = class {
82
77
  caption: options.caption
83
78
  })
84
79
  });
85
- return {
86
- success: data.success,
87
- message_id: data.message_id,
88
- whatsapp_message_id: data.whatsapp_message_id
89
- };
90
80
  }
91
81
  async sendVideo(options) {
92
- const data = await this.request("/api/sdk/send-video", {
82
+ return this.request("/api/sdk/send-video", {
93
83
  method: "POST",
94
84
  body: JSON.stringify({
95
85
  phone: options.phone,
@@ -97,14 +87,9 @@ var BTechWorksClient = class {
97
87
  caption: options.caption
98
88
  })
99
89
  });
100
- return {
101
- success: data.success,
102
- message_id: data.message_id,
103
- whatsapp_message_id: data.whatsapp_message_id
104
- };
105
90
  }
106
91
  async sendDocument(options) {
107
- const data = await this.request("/api/sdk/send-document", {
92
+ return this.request("/api/sdk/send-document", {
108
93
  method: "POST",
109
94
  body: JSON.stringify({
110
95
  phone: options.phone,
@@ -113,14 +98,9 @@ var BTechWorksClient = class {
113
98
  caption: options.caption
114
99
  })
115
100
  });
116
- return {
117
- success: data.success,
118
- message_id: data.message_id,
119
- whatsapp_message_id: data.whatsapp_message_id
120
- };
121
101
  }
122
102
  async sendTemplate(options) {
123
- const data = await this.request("/api/sdk/send-template", {
103
+ return this.request("/api/sdk/send-template", {
124
104
  method: "POST",
125
105
  body: JSON.stringify({
126
106
  phone: options.phone,
@@ -130,14 +110,9 @@ var BTechWorksClient = class {
130
110
  template_message_params: options.templateMessageParams
131
111
  })
132
112
  });
133
- return {
134
- success: data.success,
135
- message_id: data.message_id,
136
- whatsapp_message_id: data.whatsapp_message_id
137
- };
138
113
  }
139
114
  async broadcast(options) {
140
- const data = await this.request("/api/sdk/broadcast", {
115
+ return this.request("/api/sdk/broadcast", {
141
116
  method: "POST",
142
117
  body: JSON.stringify({
143
118
  name: options.name,
@@ -148,12 +123,6 @@ var BTechWorksClient = class {
148
123
  audience_filter: options.audienceFilter
149
124
  })
150
125
  });
151
- return {
152
- success: data.success,
153
- broadcast_id: data.broadcast_id,
154
- total_recipients: data.total_recipients,
155
- status: data.status
156
- };
157
126
  }
158
127
  };
159
128
  export {
package/package.json CHANGED
@@ -1,43 +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
- }
1
+ {
2
+ "name": "btechworks-sdk",
3
+ "version": "1.0.1",
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
+ }