btechworks-sdk 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +28 -16
- package/dist/index.d.mts +3 -18
- package/dist/index.d.ts +3 -18
- package/dist/index.js +17 -61
- package/dist/index.mjs +16 -59
- package/package.json +43 -43
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,
|
|
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
|
|
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
|
|
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,28 +54,13 @@ interface BroadcastOptions {
|
|
|
54
54
|
}
|
|
55
55
|
interface ApiResponse {
|
|
56
56
|
success: boolean;
|
|
57
|
-
|
|
58
|
-
whatsapp_message_id?: string;
|
|
59
|
-
error?: string;
|
|
57
|
+
message: string;
|
|
60
58
|
}
|
|
61
59
|
interface BroadcastResponse {
|
|
62
60
|
success: boolean;
|
|
63
|
-
|
|
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
|
-
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
64
|
declare class BTechWorksClient {
|
|
80
65
|
private apiKey;
|
|
81
66
|
private secretKey;
|
|
@@ -91,4 +76,4 @@ declare class BTechWorksClient {
|
|
|
91
76
|
broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
|
|
92
77
|
}
|
|
93
78
|
|
|
94
|
-
export { type
|
|
79
|
+
export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -54,28 +54,13 @@ interface BroadcastOptions {
|
|
|
54
54
|
}
|
|
55
55
|
interface ApiResponse {
|
|
56
56
|
success: boolean;
|
|
57
|
-
|
|
58
|
-
whatsapp_message_id?: string;
|
|
59
|
-
error?: string;
|
|
57
|
+
message: string;
|
|
60
58
|
}
|
|
61
59
|
interface BroadcastResponse {
|
|
62
60
|
success: boolean;
|
|
63
|
-
|
|
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
|
-
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
64
|
declare class BTechWorksClient {
|
|
80
65
|
private apiKey;
|
|
81
66
|
private secretKey;
|
|
@@ -91,4 +76,4 @@ declare class BTechWorksClient {
|
|
|
91
76
|
broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
|
|
92
77
|
}
|
|
93
78
|
|
|
94
|
-
export { type
|
|
79
|
+
export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
|
package/dist/index.js
CHANGED
|
@@ -20,20 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
BTechWorksClient: () => BTechWorksClient
|
|
24
|
-
BTechWorksError: () => BTechWorksError
|
|
23
|
+
BTechWorksClient: () => BTechWorksClient
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(index_exports);
|
|
27
26
|
|
|
28
27
|
// 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
28
|
var BTechWorksClient = class {
|
|
38
29
|
constructor(config) {
|
|
39
30
|
if (!config.apiKey) {
|
|
@@ -47,7 +38,6 @@ var BTechWorksClient = class {
|
|
|
47
38
|
this.baseUrl = (config.baseUrl || "https://api.btechworks.io").replace(/\/+$/, "");
|
|
48
39
|
this.timeout = config.timeout || 3e4;
|
|
49
40
|
}
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
41
|
async request(path, options = {}) {
|
|
52
42
|
const url = `${this.baseUrl}${path}`;
|
|
53
43
|
const headers = {
|
|
@@ -66,42 +56,35 @@ var BTechWorksClient = class {
|
|
|
66
56
|
});
|
|
67
57
|
const data = await response.json();
|
|
68
58
|
if (!response.ok) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
response.status
|
|
72
|
-
|
|
73
|
-
);
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
message: data.message || data.error || `Request failed with status ${response.status}`
|
|
62
|
+
};
|
|
74
63
|
}
|
|
75
64
|
return data;
|
|
76
65
|
} catch (error) {
|
|
77
|
-
if (error instanceof BTechWorksError) throw error;
|
|
78
66
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
79
|
-
|
|
67
|
+
return { success: false, message: "Request timeout" };
|
|
80
68
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
72
|
+
};
|
|
85
73
|
} finally {
|
|
86
74
|
clearTimeout(timeoutId);
|
|
87
75
|
}
|
|
88
76
|
}
|
|
89
77
|
async sendMessage(options) {
|
|
90
|
-
|
|
78
|
+
return this.request("/api/sdk/send-message", {
|
|
91
79
|
method: "POST",
|
|
92
80
|
body: JSON.stringify({
|
|
93
81
|
phone: options.phone,
|
|
94
82
|
message: options.message
|
|
95
83
|
})
|
|
96
84
|
});
|
|
97
|
-
return {
|
|
98
|
-
success: data.success,
|
|
99
|
-
message_id: data.message_id,
|
|
100
|
-
whatsapp_message_id: data.whatsapp_message_id
|
|
101
|
-
};
|
|
102
85
|
}
|
|
103
86
|
async sendPhoto(options) {
|
|
104
|
-
|
|
87
|
+
return this.request("/api/sdk/send-photo", {
|
|
105
88
|
method: "POST",
|
|
106
89
|
body: JSON.stringify({
|
|
107
90
|
phone: options.phone,
|
|
@@ -109,14 +92,9 @@ var BTechWorksClient = class {
|
|
|
109
92
|
caption: options.caption
|
|
110
93
|
})
|
|
111
94
|
});
|
|
112
|
-
return {
|
|
113
|
-
success: data.success,
|
|
114
|
-
message_id: data.message_id,
|
|
115
|
-
whatsapp_message_id: data.whatsapp_message_id
|
|
116
|
-
};
|
|
117
95
|
}
|
|
118
96
|
async sendVideo(options) {
|
|
119
|
-
|
|
97
|
+
return this.request("/api/sdk/send-video", {
|
|
120
98
|
method: "POST",
|
|
121
99
|
body: JSON.stringify({
|
|
122
100
|
phone: options.phone,
|
|
@@ -124,14 +102,9 @@ var BTechWorksClient = class {
|
|
|
124
102
|
caption: options.caption
|
|
125
103
|
})
|
|
126
104
|
});
|
|
127
|
-
return {
|
|
128
|
-
success: data.success,
|
|
129
|
-
message_id: data.message_id,
|
|
130
|
-
whatsapp_message_id: data.whatsapp_message_id
|
|
131
|
-
};
|
|
132
105
|
}
|
|
133
106
|
async sendDocument(options) {
|
|
134
|
-
|
|
107
|
+
return this.request("/api/sdk/send-document", {
|
|
135
108
|
method: "POST",
|
|
136
109
|
body: JSON.stringify({
|
|
137
110
|
phone: options.phone,
|
|
@@ -140,14 +113,9 @@ var BTechWorksClient = class {
|
|
|
140
113
|
caption: options.caption
|
|
141
114
|
})
|
|
142
115
|
});
|
|
143
|
-
return {
|
|
144
|
-
success: data.success,
|
|
145
|
-
message_id: data.message_id,
|
|
146
|
-
whatsapp_message_id: data.whatsapp_message_id
|
|
147
|
-
};
|
|
148
116
|
}
|
|
149
117
|
async sendTemplate(options) {
|
|
150
|
-
|
|
118
|
+
return this.request("/api/sdk/send-template", {
|
|
151
119
|
method: "POST",
|
|
152
120
|
body: JSON.stringify({
|
|
153
121
|
phone: options.phone,
|
|
@@ -157,14 +125,9 @@ var BTechWorksClient = class {
|
|
|
157
125
|
template_message_params: options.templateMessageParams
|
|
158
126
|
})
|
|
159
127
|
});
|
|
160
|
-
return {
|
|
161
|
-
success: data.success,
|
|
162
|
-
message_id: data.message_id,
|
|
163
|
-
whatsapp_message_id: data.whatsapp_message_id
|
|
164
|
-
};
|
|
165
128
|
}
|
|
166
129
|
async broadcast(options) {
|
|
167
|
-
|
|
130
|
+
return this.request("/api/sdk/broadcast", {
|
|
168
131
|
method: "POST",
|
|
169
132
|
body: JSON.stringify({
|
|
170
133
|
name: options.name,
|
|
@@ -175,16 +138,9 @@ var BTechWorksClient = class {
|
|
|
175
138
|
audience_filter: options.audienceFilter
|
|
176
139
|
})
|
|
177
140
|
});
|
|
178
|
-
return {
|
|
179
|
-
success: data.success,
|
|
180
|
-
broadcast_id: data.broadcast_id,
|
|
181
|
-
total_recipients: data.total_recipients,
|
|
182
|
-
status: data.status
|
|
183
|
-
};
|
|
184
141
|
}
|
|
185
142
|
};
|
|
186
143
|
// Annotate the CommonJS export names for ESM import in node:
|
|
187
144
|
0 && (module.exports = {
|
|
188
|
-
BTechWorksClient
|
|
189
|
-
BTechWorksError
|
|
145
|
+
BTechWorksClient
|
|
190
146
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
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
2
|
var BTechWorksClient = class {
|
|
11
3
|
constructor(config) {
|
|
12
4
|
if (!config.apiKey) {
|
|
@@ -20,7 +12,6 @@ var BTechWorksClient = class {
|
|
|
20
12
|
this.baseUrl = (config.baseUrl || "https://api.btechworks.io").replace(/\/+$/, "");
|
|
21
13
|
this.timeout = config.timeout || 3e4;
|
|
22
14
|
}
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
15
|
async request(path, options = {}) {
|
|
25
16
|
const url = `${this.baseUrl}${path}`;
|
|
26
17
|
const headers = {
|
|
@@ -39,42 +30,35 @@ var BTechWorksClient = class {
|
|
|
39
30
|
});
|
|
40
31
|
const data = await response.json();
|
|
41
32
|
if (!response.ok) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
response.status
|
|
45
|
-
|
|
46
|
-
);
|
|
33
|
+
return {
|
|
34
|
+
success: false,
|
|
35
|
+
message: data.message || data.error || `Request failed with status ${response.status}`
|
|
36
|
+
};
|
|
47
37
|
}
|
|
48
38
|
return data;
|
|
49
39
|
} catch (error) {
|
|
50
|
-
if (error instanceof BTechWorksError) throw error;
|
|
51
40
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
52
|
-
|
|
41
|
+
return { success: false, message: "Request timeout" };
|
|
53
42
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
46
|
+
};
|
|
58
47
|
} finally {
|
|
59
48
|
clearTimeout(timeoutId);
|
|
60
49
|
}
|
|
61
50
|
}
|
|
62
51
|
async sendMessage(options) {
|
|
63
|
-
|
|
52
|
+
return this.request("/api/sdk/send-message", {
|
|
64
53
|
method: "POST",
|
|
65
54
|
body: JSON.stringify({
|
|
66
55
|
phone: options.phone,
|
|
67
56
|
message: options.message
|
|
68
57
|
})
|
|
69
58
|
});
|
|
70
|
-
return {
|
|
71
|
-
success: data.success,
|
|
72
|
-
message_id: data.message_id,
|
|
73
|
-
whatsapp_message_id: data.whatsapp_message_id
|
|
74
|
-
};
|
|
75
59
|
}
|
|
76
60
|
async sendPhoto(options) {
|
|
77
|
-
|
|
61
|
+
return this.request("/api/sdk/send-photo", {
|
|
78
62
|
method: "POST",
|
|
79
63
|
body: JSON.stringify({
|
|
80
64
|
phone: options.phone,
|
|
@@ -82,14 +66,9 @@ var BTechWorksClient = class {
|
|
|
82
66
|
caption: options.caption
|
|
83
67
|
})
|
|
84
68
|
});
|
|
85
|
-
return {
|
|
86
|
-
success: data.success,
|
|
87
|
-
message_id: data.message_id,
|
|
88
|
-
whatsapp_message_id: data.whatsapp_message_id
|
|
89
|
-
};
|
|
90
69
|
}
|
|
91
70
|
async sendVideo(options) {
|
|
92
|
-
|
|
71
|
+
return this.request("/api/sdk/send-video", {
|
|
93
72
|
method: "POST",
|
|
94
73
|
body: JSON.stringify({
|
|
95
74
|
phone: options.phone,
|
|
@@ -97,14 +76,9 @@ var BTechWorksClient = class {
|
|
|
97
76
|
caption: options.caption
|
|
98
77
|
})
|
|
99
78
|
});
|
|
100
|
-
return {
|
|
101
|
-
success: data.success,
|
|
102
|
-
message_id: data.message_id,
|
|
103
|
-
whatsapp_message_id: data.whatsapp_message_id
|
|
104
|
-
};
|
|
105
79
|
}
|
|
106
80
|
async sendDocument(options) {
|
|
107
|
-
|
|
81
|
+
return this.request("/api/sdk/send-document", {
|
|
108
82
|
method: "POST",
|
|
109
83
|
body: JSON.stringify({
|
|
110
84
|
phone: options.phone,
|
|
@@ -113,14 +87,9 @@ var BTechWorksClient = class {
|
|
|
113
87
|
caption: options.caption
|
|
114
88
|
})
|
|
115
89
|
});
|
|
116
|
-
return {
|
|
117
|
-
success: data.success,
|
|
118
|
-
message_id: data.message_id,
|
|
119
|
-
whatsapp_message_id: data.whatsapp_message_id
|
|
120
|
-
};
|
|
121
90
|
}
|
|
122
91
|
async sendTemplate(options) {
|
|
123
|
-
|
|
92
|
+
return this.request("/api/sdk/send-template", {
|
|
124
93
|
method: "POST",
|
|
125
94
|
body: JSON.stringify({
|
|
126
95
|
phone: options.phone,
|
|
@@ -130,14 +99,9 @@ var BTechWorksClient = class {
|
|
|
130
99
|
template_message_params: options.templateMessageParams
|
|
131
100
|
})
|
|
132
101
|
});
|
|
133
|
-
return {
|
|
134
|
-
success: data.success,
|
|
135
|
-
message_id: data.message_id,
|
|
136
|
-
whatsapp_message_id: data.whatsapp_message_id
|
|
137
|
-
};
|
|
138
102
|
}
|
|
139
103
|
async broadcast(options) {
|
|
140
|
-
|
|
104
|
+
return this.request("/api/sdk/broadcast", {
|
|
141
105
|
method: "POST",
|
|
142
106
|
body: JSON.stringify({
|
|
143
107
|
name: options.name,
|
|
@@ -148,15 +112,8 @@ var BTechWorksClient = class {
|
|
|
148
112
|
audience_filter: options.audienceFilter
|
|
149
113
|
})
|
|
150
114
|
});
|
|
151
|
-
return {
|
|
152
|
-
success: data.success,
|
|
153
|
-
broadcast_id: data.broadcast_id,
|
|
154
|
-
total_recipients: data.total_recipients,
|
|
155
|
-
status: data.status
|
|
156
|
-
};
|
|
157
115
|
}
|
|
158
116
|
};
|
|
159
117
|
export {
|
|
160
|
-
BTechWorksClient
|
|
161
|
-
BTechWorksError
|
|
118
|
+
BTechWorksClient
|
|
162
119
|
};
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "btechworks-sdk",
|
|
3
|
-
"version": "1.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.2",
|
|
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
|
+
}
|