btechworks-sdk 1.0.2 → 1.0.6

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/README.md CHANGED
@@ -40,146 +40,184 @@ const client = new BTechWorksClient({
40
40
 
41
41
  ## Methods
42
42
 
43
- ### sendMessage
44
-
45
- Send a text message to a phone number. Contact and conversation are auto-created.
43
+ ### Messaging
46
44
 
47
45
  ```typescript
48
- const result = await client.sendMessage({
49
- phone: '+1234567890',
50
- message: 'Hello World!',
51
- });
52
- // { success: true, message: 'Message sent successfully' }
53
- ```
46
+ // Send text message
47
+ await client.sendMessage({ phone: '+1234567890', message: 'Hello!' });
54
48
 
55
- ### sendPhoto
49
+ // Send photo
50
+ await client.sendPhoto({ phone: '+1234567890', imageUrl: 'https://example.com/photo.jpg', caption: 'Photo' });
56
51
 
57
- Send an image with an optional caption.
52
+ // Send video
53
+ await client.sendVideo({ phone: '+1234567890', videoUrl: 'https://example.com/video.mp4', caption: 'Video' });
58
54
 
59
- ```typescript
60
- const result = await client.sendPhoto({
55
+ // Send document
56
+ await client.sendDocument({ phone: '+1234567890', documentUrl: 'https://example.com/file.pdf', filename: 'file.pdf' });
57
+
58
+ // Send CTA URL button (Click-to-Chat)
59
+ await client.sendCtcUrl({
61
60
  phone: '+1234567890',
62
- imageUrl: 'https://example.com/photo.jpg',
63
- caption: 'Check out this photo!',
61
+ bodyText: 'Need help? Chat with us on WhatsApp!',
62
+ displayText: 'Chat Now',
63
+ url: 'https://wa.me/919999999999?text=Hi%20I%20need%20help',
64
+ footerText: 'We reply within 5 minutes',
64
65
  });
65
- // { success: true, message: 'Photo sent successfully' }
66
66
  ```
67
67
 
68
- ### sendVideo
69
-
70
- Send a video with an optional caption.
68
+ ### Templates
71
69
 
72
70
  ```typescript
73
- const result = await client.sendVideo({
71
+ // Check template variables first
72
+ const check = await client.checkTemplate({ templateName: 'order_confirm' });
73
+ console.log(check.variables); // [{ name: 'name', example: 'John' }]
74
+
75
+ // Send template
76
+ const result = await client.sendTemplate({
74
77
  phone: '+1234567890',
75
- videoUrl: 'https://example.com/video.mp4',
76
- caption: 'Watch this video!',
78
+ templateName: 'order_confirm',
79
+ templateLanguage: 'en_US',
80
+ templateParams: ['John', 'Order #12345'],
77
81
  });
78
- // { success: true, message: 'Video sent successfully' }
82
+ // { success: true, sent_as: 'template', balance: 99 }
83
+ // OR if 24h window open:
84
+ // { success: true, sent_as: 'text', message: 'Service window open - sent as free text' }
79
85
  ```
80
86
 
81
- ### sendDocument
82
-
83
- Send a document (PDF, DOC, etc.) with an optional caption.
87
+ ### Broadcast
84
88
 
85
89
  ```typescript
86
- const result = await client.sendDocument({
87
- phone: '+1234567890',
88
- documentUrl: 'https://example.com/invoice.pdf',
89
- filename: 'invoice.pdf',
90
- caption: 'Your invoice for this month',
90
+ // Send to specific phone numbers
91
+ const result = await client.broadcast({
92
+ name: 'Summer Sale',
93
+ templateName: 'summer_offer',
94
+ templateLanguage: 'en_US',
95
+ recipients: ['+1234567890', '+0987654321'],
96
+ templateVariables: { name: 'User', offer: '50% OFF' },
91
97
  });
92
- // { success: true, message: 'Document sent successfully' }
93
- ```
98
+ // { success: true, message: 'Template "summer_offer" processed: 20 sent, 5 failed', sent: 20, failed: 5 }
94
99
 
95
- ### sendTemplate
96
-
97
- Send a WhatsApp template message with variables.
100
+ // Send to contacts filtered by tags
101
+ await client.broadcast({
102
+ name: 'Premium Users',
103
+ templateName: 'vip_offer',
104
+ templateVariables: { name: 'VIP User' },
105
+ audienceFilter: { tags: ['premium', 'vip'] },
106
+ });
98
107
 
99
- ```typescript
100
- // Simple template with body variables
101
- const result = await client.sendTemplate({
102
- phone: '+1234567890',
103
- templateName: 'order_confirmation',
104
- templateLanguage: 'en_US',
105
- templateParams: ['John', 'Order #12345'],
108
+ // Broadcast from Excel/CSV file
109
+ import { readFileSync } from 'fs';
110
+ const file = new File([readFileSync('contacts.xlsx')], 'contacts.xlsx', {
111
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
106
112
  });
107
- // { success: true, message: 'Template sent successfully' }
108
113
 
109
- // Template with header media and button params
110
- const result2 = await client.sendTemplate({
111
- phone: '+1234567890',
112
- templateName: 'promo_template',
113
- templateLanguage: 'en_US',
114
- templateMessageParams: {
115
- header: { type: 'image', url: 'https://example.com/promo.jpg' },
116
- body: ['John', '50%'],
117
- buttons: [{ type: 'url', suffix: 'promo50' }],
118
- },
114
+ await client.broadcastFromSheet({
115
+ name: 'Bulk Broadcast',
116
+ templateName: 'offer',
117
+ templateVariables: { name: 'User' },
118
+ file,
119
119
  });
120
120
  ```
121
121
 
122
- ### broadcast
123
-
124
- Send a template message to multiple recipients.
122
+ ### Wallet
125
123
 
126
124
  ```typescript
127
- const result = await client.broadcast({
128
- name: 'Summer Sale Campaign',
129
- templateName: 'summer_sale',
130
- templateLanguage: 'en_US',
131
- templateVariables: { code: 'SUMMER50' },
132
- recipients: ['+1234567890', '+0987654321', '+1122334455'],
125
+ // Check balance
126
+ const balance = await client.getBalance();
127
+ // { success: true, balance: 100, template_rate: 1, can_send: 100 }
128
+
129
+ // Estimate cost before sending
130
+ const estimate = await client.estimateCost(50);
131
+ // { success: true, balance: 100, can_send: 100, estimated_templates: 50, estimated_cost: 50 }
132
+
133
+ // Generate payment link (user opens link to pay)
134
+ const link = await client.rechargeViaLink({
135
+ amount: 500,
136
+ email: 'user@example.com',
137
+ phone: '+919999999999'
133
138
  });
134
- // { success: true, message: 'Template "summer_sale" processed: 20 sent, 5 failed' }
139
+ // { success: true, link_url: 'https://cashfree.com/pay/...', order_amount: 500 }
140
+ // User opens link_url and pays via Card/UPI
135
141
 
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
- // { success: true, message: 'Template "vip_offer" processed: 50 sent, 10 skipped, 3 failed' }
142
+ // Verify payment after Cashfree redirect
143
+ const verify = await client.verifyOrder('wallet_1234567890_abc123');
144
+ // { success: true, status: 'PAID', balance: 500, message: '₹500 added to your wallet' }
145
+
146
+ // Get transaction history
147
+ const txns = await client.getTransactions(10, 0);
148
+ // { success: true, transactions: [...] }
149
+ ```
150
+
151
+ ### Analytics
152
+
153
+ ```typescript
154
+ const analytics = await client.getAnalytics();
155
+ // {
156
+ // success: true,
157
+ // analytics: {
158
+ // contacts: 1250,
159
+ // conversations: 890,
160
+ // messages: { today: 45, this_week: 312, this_month: 1250 },
161
+ // templates: 15,
162
+ // recent_broadcasts: [...]
163
+ // }
164
+ // }
144
165
  ```
145
166
 
146
167
  ## Response Format
147
168
 
148
- All methods return a simple response:
169
+ All methods return a simple response object. **No exceptions are thrown.**
149
170
 
150
171
  ```typescript
151
- // Single message
172
+ // Success
152
173
  { success: true, message: 'Message sent successfully' }
153
174
 
154
- // Broadcast
155
- { success: true, message: 'Template "promo" processed: 20 sent, 10 skipped, 5 failed' }
156
-
157
- // Error (throws BTechWorksError)
175
+ // Error
158
176
  { success: false, message: 'Invalid phone number format' }
177
+
178
+ // Template with balance
179
+ { success: true, sent_as: 'template', balance: 99 }
180
+
181
+ // Broadcast
182
+ { success: true, message: 'Template "promo" processed: 20 sent, 5 failed', sent: 20, failed: 5, refunded: 5 }
159
183
  ```
160
184
 
161
185
  ## Error Handling
162
186
 
163
- All methods throw `BTechWorksError` on failure:
187
+ All methods return response objects with `success: false` on error. No try-catch needed:
164
188
 
165
189
  ```typescript
166
- import { BTechWorksClient, BTechWorksError } from 'btechworks-sdk';
167
-
168
- try {
169
- await client.sendMessage({ phone: '+1234567890', message: 'Hello!' });
170
- } catch (error) {
171
- if (error instanceof BTechWorksError) {
172
- console.log(error.message); // Error message
173
- console.log(error.statusCode); // HTTP status code
174
- }
190
+ const result = await client.sendMessage({ phone: 'invalid', message: 'Hello!' });
191
+
192
+ if (result.success) {
193
+ console.log('Sent!');
194
+ } else {
195
+ console.log('Failed:', result.message);
175
196
  }
176
197
  ```
177
198
 
178
- ## How It Works
199
+ ## Template Flow
179
200
 
180
- 1. **Phone number se sab kuch hota hai** - Contact aur conversation automatically create ho jaate hain
181
- 2. **API key + Secret key se auth hota hai** - Dashboard se API key banao, SDK mein daalo, kaam shuru
182
- 3. **Server sab handle karta hai** - Contact lookup, conversation creation, Meta API calls, message storage
201
+ 1. **Check template** - See what variables are needed
202
+ 2. **Send template** - Auto-deducts balance OR sends as free text if 24h window open
203
+
204
+ ```typescript
205
+ // Step 1: Check
206
+ const check = await client.checkTemplate({ templateName: 'welcome' });
207
+ if (!check.ready_to_send) {
208
+ console.log('Missing variables:', check.variables);
209
+ }
210
+
211
+ // Step 2: Send (handles everything automatically)
212
+ const result = await client.sendTemplate({
213
+ phone: '+1234567890',
214
+ templateName: 'welcome',
215
+ templateParams: ['John']
216
+ });
217
+
218
+ // sent_as: 'text' = Free (24h window open)
219
+ // sent_as: 'template' = Paid (balance deducted)
220
+ ```
183
221
 
184
222
  ## Getting API Keys
185
223
 
package/dist/index.d.mts CHANGED
@@ -24,6 +24,13 @@ interface SendDocumentOptions {
24
24
  filename?: string;
25
25
  caption?: string;
26
26
  }
27
+ interface SendCtcUrlOptions {
28
+ phone: string;
29
+ bodyText: string;
30
+ displayText: string;
31
+ url: string;
32
+ footerText?: string;
33
+ }
27
34
  interface SendTemplateOptions {
28
35
  phone: string;
29
36
  templateName: string;
@@ -59,6 +66,126 @@ interface ApiResponse {
59
66
  interface BroadcastResponse {
60
67
  success: boolean;
61
68
  message: string;
69
+ sent?: number;
70
+ failed?: number;
71
+ skipped?: number;
72
+ refunded?: number;
73
+ }
74
+ interface BroadcastSheetResponse {
75
+ success: boolean;
76
+ message: string;
77
+ total_rows?: number;
78
+ valid_recipients?: number;
79
+ new_contacts?: number;
80
+ sent?: number;
81
+ failed?: number;
82
+ skipped?: number;
83
+ refunded?: number;
84
+ }
85
+ interface CheckTemplateOptions {
86
+ templateName: string;
87
+ templateLanguage?: string;
88
+ }
89
+ interface TemplateVariable {
90
+ name: string;
91
+ example: string;
92
+ required: boolean;
93
+ }
94
+ interface CheckTemplateResponse {
95
+ success: boolean;
96
+ exists?: boolean;
97
+ template?: {
98
+ name: string;
99
+ language: string;
100
+ status: string;
101
+ };
102
+ variables?: TemplateVariable[];
103
+ ready_to_send?: boolean;
104
+ message: string;
105
+ }
106
+ interface WalletBalanceResponse {
107
+ success: boolean;
108
+ balance?: number;
109
+ template_rate?: number;
110
+ is_active?: boolean;
111
+ message: string;
112
+ }
113
+ interface Transaction {
114
+ type: 'credit' | 'debit' | 'refund';
115
+ amount: number;
116
+ balance_after: number;
117
+ description: string;
118
+ created_at: string;
119
+ }
120
+ interface TransactionsResponse {
121
+ success: boolean;
122
+ transactions?: Transaction[];
123
+ message: string;
124
+ }
125
+ interface SendTemplateResponse {
126
+ success: boolean;
127
+ sent_as?: 'text' | 'template';
128
+ balance?: number;
129
+ message: string;
130
+ }
131
+ interface RechargeOptions {
132
+ amount: number;
133
+ email?: string;
134
+ phone?: string;
135
+ }
136
+ interface RechargeResponse {
137
+ success: boolean;
138
+ order_id?: string;
139
+ payment_session_id?: string;
140
+ order_amount?: number;
141
+ message: string;
142
+ }
143
+ interface RechargeViaLinkResponse {
144
+ success: boolean;
145
+ link_id?: string;
146
+ link_url?: string;
147
+ link_status?: string;
148
+ order_amount?: number;
149
+ message: string;
150
+ }
151
+ interface EstimateCostResponse {
152
+ success: boolean;
153
+ balance?: number;
154
+ template_rate?: number;
155
+ can_send?: number;
156
+ estimated_templates?: number;
157
+ estimated_cost?: number;
158
+ can_send_templates?: number;
159
+ message: string;
160
+ }
161
+ interface VerifyOrderResponse {
162
+ success: boolean;
163
+ status?: string;
164
+ balance?: number;
165
+ message: string;
166
+ }
167
+ interface Broadcast {
168
+ name: string;
169
+ status: string;
170
+ sent_count: number;
171
+ failed_count: number;
172
+ created_at: string;
173
+ }
174
+ interface Analytics {
175
+ contacts: number;
176
+ conversations: number;
177
+ messages: {
178
+ today: number;
179
+ this_week: number;
180
+ this_month: number;
181
+ };
182
+ templates: number;
183
+ recent_broadcasts: Broadcast[];
184
+ }
185
+ interface AnalyticsResponse {
186
+ success: boolean;
187
+ analytics?: Analytics;
188
+ message: string;
62
189
  }
63
190
 
64
191
  declare class BTechWorksClient {
@@ -68,12 +195,28 @@ declare class BTechWorksClient {
68
195
  private timeout;
69
196
  constructor(config: BTechWorksConfig);
70
197
  private request;
198
+ getAnalytics(): Promise<AnalyticsResponse>;
199
+ checkTemplate(options: CheckTemplateOptions): Promise<CheckTemplateResponse>;
71
200
  sendMessage(options: SendMessageOptions): Promise<ApiResponse>;
72
201
  sendPhoto(options: SendPhotoOptions): Promise<ApiResponse>;
73
202
  sendVideo(options: SendVideoOptions): Promise<ApiResponse>;
74
203
  sendDocument(options: SendDocumentOptions): Promise<ApiResponse>;
75
- sendTemplate(options: SendTemplateOptions): Promise<ApiResponse>;
204
+ sendCtcUrl(options: SendCtcUrlOptions): Promise<ApiResponse>;
205
+ sendTemplate(options: SendTemplateOptions): Promise<SendTemplateResponse>;
76
206
  broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
207
+ broadcastFromSheet(options: {
208
+ name: string;
209
+ templateName: string;
210
+ templateLanguage?: string;
211
+ templateVariables?: Record<string, string>;
212
+ file: File;
213
+ }): Promise<BroadcastSheetResponse>;
214
+ getBalance(): Promise<WalletBalanceResponse>;
215
+ estimateCost(count?: number): Promise<EstimateCostResponse>;
216
+ recharge(options: RechargeOptions): Promise<RechargeResponse>;
217
+ rechargeViaLink(options: RechargeOptions): Promise<RechargeViaLinkResponse>;
218
+ verifyOrder(orderId: string): Promise<VerifyOrderResponse>;
219
+ getTransactions(limit?: number, offset?: number): Promise<TransactionsResponse>;
77
220
  }
78
221
 
79
- export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
222
+ export { type Analytics, type AnalyticsResponse, type ApiResponse, BTechWorksClient, type BTechWorksConfig, type Broadcast, type BroadcastOptions, type BroadcastResponse, type BroadcastSheetResponse, type CheckTemplateOptions, type CheckTemplateResponse, type EstimateCostResponse, type RechargeOptions, type RechargeResponse, type RechargeViaLinkResponse, type SendCtcUrlOptions, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendTemplateResponse, type SendVideoOptions, type TemplateVariable, type Transaction, type TransactionsResponse, type VerifyOrderResponse, type WalletBalanceResponse };
package/dist/index.d.ts CHANGED
@@ -24,6 +24,13 @@ interface SendDocumentOptions {
24
24
  filename?: string;
25
25
  caption?: string;
26
26
  }
27
+ interface SendCtcUrlOptions {
28
+ phone: string;
29
+ bodyText: string;
30
+ displayText: string;
31
+ url: string;
32
+ footerText?: string;
33
+ }
27
34
  interface SendTemplateOptions {
28
35
  phone: string;
29
36
  templateName: string;
@@ -59,6 +66,126 @@ interface ApiResponse {
59
66
  interface BroadcastResponse {
60
67
  success: boolean;
61
68
  message: string;
69
+ sent?: number;
70
+ failed?: number;
71
+ skipped?: number;
72
+ refunded?: number;
73
+ }
74
+ interface BroadcastSheetResponse {
75
+ success: boolean;
76
+ message: string;
77
+ total_rows?: number;
78
+ valid_recipients?: number;
79
+ new_contacts?: number;
80
+ sent?: number;
81
+ failed?: number;
82
+ skipped?: number;
83
+ refunded?: number;
84
+ }
85
+ interface CheckTemplateOptions {
86
+ templateName: string;
87
+ templateLanguage?: string;
88
+ }
89
+ interface TemplateVariable {
90
+ name: string;
91
+ example: string;
92
+ required: boolean;
93
+ }
94
+ interface CheckTemplateResponse {
95
+ success: boolean;
96
+ exists?: boolean;
97
+ template?: {
98
+ name: string;
99
+ language: string;
100
+ status: string;
101
+ };
102
+ variables?: TemplateVariable[];
103
+ ready_to_send?: boolean;
104
+ message: string;
105
+ }
106
+ interface WalletBalanceResponse {
107
+ success: boolean;
108
+ balance?: number;
109
+ template_rate?: number;
110
+ is_active?: boolean;
111
+ message: string;
112
+ }
113
+ interface Transaction {
114
+ type: 'credit' | 'debit' | 'refund';
115
+ amount: number;
116
+ balance_after: number;
117
+ description: string;
118
+ created_at: string;
119
+ }
120
+ interface TransactionsResponse {
121
+ success: boolean;
122
+ transactions?: Transaction[];
123
+ message: string;
124
+ }
125
+ interface SendTemplateResponse {
126
+ success: boolean;
127
+ sent_as?: 'text' | 'template';
128
+ balance?: number;
129
+ message: string;
130
+ }
131
+ interface RechargeOptions {
132
+ amount: number;
133
+ email?: string;
134
+ phone?: string;
135
+ }
136
+ interface RechargeResponse {
137
+ success: boolean;
138
+ order_id?: string;
139
+ payment_session_id?: string;
140
+ order_amount?: number;
141
+ message: string;
142
+ }
143
+ interface RechargeViaLinkResponse {
144
+ success: boolean;
145
+ link_id?: string;
146
+ link_url?: string;
147
+ link_status?: string;
148
+ order_amount?: number;
149
+ message: string;
150
+ }
151
+ interface EstimateCostResponse {
152
+ success: boolean;
153
+ balance?: number;
154
+ template_rate?: number;
155
+ can_send?: number;
156
+ estimated_templates?: number;
157
+ estimated_cost?: number;
158
+ can_send_templates?: number;
159
+ message: string;
160
+ }
161
+ interface VerifyOrderResponse {
162
+ success: boolean;
163
+ status?: string;
164
+ balance?: number;
165
+ message: string;
166
+ }
167
+ interface Broadcast {
168
+ name: string;
169
+ status: string;
170
+ sent_count: number;
171
+ failed_count: number;
172
+ created_at: string;
173
+ }
174
+ interface Analytics {
175
+ contacts: number;
176
+ conversations: number;
177
+ messages: {
178
+ today: number;
179
+ this_week: number;
180
+ this_month: number;
181
+ };
182
+ templates: number;
183
+ recent_broadcasts: Broadcast[];
184
+ }
185
+ interface AnalyticsResponse {
186
+ success: boolean;
187
+ analytics?: Analytics;
188
+ message: string;
62
189
  }
63
190
 
64
191
  declare class BTechWorksClient {
@@ -68,12 +195,28 @@ declare class BTechWorksClient {
68
195
  private timeout;
69
196
  constructor(config: BTechWorksConfig);
70
197
  private request;
198
+ getAnalytics(): Promise<AnalyticsResponse>;
199
+ checkTemplate(options: CheckTemplateOptions): Promise<CheckTemplateResponse>;
71
200
  sendMessage(options: SendMessageOptions): Promise<ApiResponse>;
72
201
  sendPhoto(options: SendPhotoOptions): Promise<ApiResponse>;
73
202
  sendVideo(options: SendVideoOptions): Promise<ApiResponse>;
74
203
  sendDocument(options: SendDocumentOptions): Promise<ApiResponse>;
75
- sendTemplate(options: SendTemplateOptions): Promise<ApiResponse>;
204
+ sendCtcUrl(options: SendCtcUrlOptions): Promise<ApiResponse>;
205
+ sendTemplate(options: SendTemplateOptions): Promise<SendTemplateResponse>;
76
206
  broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
207
+ broadcastFromSheet(options: {
208
+ name: string;
209
+ templateName: string;
210
+ templateLanguage?: string;
211
+ templateVariables?: Record<string, string>;
212
+ file: File;
213
+ }): Promise<BroadcastSheetResponse>;
214
+ getBalance(): Promise<WalletBalanceResponse>;
215
+ estimateCost(count?: number): Promise<EstimateCostResponse>;
216
+ recharge(options: RechargeOptions): Promise<RechargeResponse>;
217
+ rechargeViaLink(options: RechargeOptions): Promise<RechargeViaLinkResponse>;
218
+ verifyOrder(orderId: string): Promise<VerifyOrderResponse>;
219
+ getTransactions(limit?: number, offset?: number): Promise<TransactionsResponse>;
77
220
  }
78
221
 
79
- export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
222
+ export { type Analytics, type AnalyticsResponse, type ApiResponse, BTechWorksClient, type BTechWorksConfig, type Broadcast, type BroadcastOptions, type BroadcastResponse, type BroadcastSheetResponse, type CheckTemplateOptions, type CheckTemplateResponse, type EstimateCostResponse, type RechargeOptions, type RechargeResponse, type RechargeViaLinkResponse, type SendCtcUrlOptions, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendTemplateResponse, type SendVideoOptions, type TemplateVariable, type Transaction, type TransactionsResponse, type VerifyOrderResponse, type WalletBalanceResponse };
package/dist/index.js CHANGED
@@ -38,6 +38,7 @@ var BTechWorksClient = class {
38
38
  this.baseUrl = (config.baseUrl || "https://api.btechworks.io").replace(/\/+$/, "");
39
39
  this.timeout = config.timeout || 3e4;
40
40
  }
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
42
  async request(path, options = {}) {
42
43
  const url = `${this.baseUrl}${path}`;
43
44
  const headers = {
@@ -74,6 +75,20 @@ var BTechWorksClient = class {
74
75
  clearTimeout(timeoutId);
75
76
  }
76
77
  }
78
+ async getAnalytics() {
79
+ return this.request("/api/sdk/analytics", {
80
+ method: "GET"
81
+ });
82
+ }
83
+ async checkTemplate(options) {
84
+ return this.request("/api/sdk/check-template", {
85
+ method: "POST",
86
+ body: JSON.stringify({
87
+ template_name: options.templateName,
88
+ template_language: options.templateLanguage
89
+ })
90
+ });
91
+ }
77
92
  async sendMessage(options) {
78
93
  return this.request("/api/sdk/send-message", {
79
94
  method: "POST",
@@ -114,6 +129,18 @@ var BTechWorksClient = class {
114
129
  })
115
130
  });
116
131
  }
132
+ async sendCtcUrl(options) {
133
+ return this.request("/api/sdk/send-ctc-url", {
134
+ method: "POST",
135
+ body: JSON.stringify({
136
+ phone: options.phone,
137
+ body_text: options.bodyText,
138
+ display_text: options.displayText,
139
+ url: options.url,
140
+ footer_text: options.footerText
141
+ })
142
+ });
143
+ }
117
144
  async sendTemplate(options) {
118
145
  return this.request("/api/sdk/send-template", {
119
146
  method: "POST",
@@ -139,6 +166,85 @@ var BTechWorksClient = class {
139
166
  })
140
167
  });
141
168
  }
169
+ async broadcastFromSheet(options) {
170
+ const formData = new FormData();
171
+ formData.append("name", options.name);
172
+ formData.append("template_name", options.templateName);
173
+ if (options.templateLanguage) formData.append("template_language", options.templateLanguage);
174
+ if (options.templateVariables) formData.append("template_variables", JSON.stringify(options.templateVariables));
175
+ formData.append("file", options.file);
176
+ const url = `${this.baseUrl}/api/sdk/broadcast-sheet`;
177
+ const controller = new AbortController();
178
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
179
+ try {
180
+ const response = await globalThis.fetch(url, {
181
+ method: "POST",
182
+ headers: {
183
+ "x-api-key": this.apiKey,
184
+ "x-secret-key": this.secretKey
185
+ },
186
+ body: formData,
187
+ signal: controller.signal
188
+ });
189
+ const data = await response.json();
190
+ return data;
191
+ } catch (error) {
192
+ if (error instanceof DOMException && error.name === "AbortError") {
193
+ return { success: false, message: "Request timeout" };
194
+ }
195
+ return {
196
+ success: false,
197
+ message: error instanceof Error ? error.message : "Unknown error"
198
+ };
199
+ } finally {
200
+ clearTimeout(timeoutId);
201
+ }
202
+ }
203
+ async getBalance() {
204
+ return this.request("/api/sdk/wallet/balance", {
205
+ method: "GET"
206
+ });
207
+ }
208
+ async estimateCost(count = 1) {
209
+ return this.request(`/api/sdk/wallet/balance?count=${count}`, {
210
+ method: "GET"
211
+ });
212
+ }
213
+ async recharge(options) {
214
+ return this.request("/api/sdk/wallet/recharge", {
215
+ method: "POST",
216
+ body: JSON.stringify({
217
+ amount: options.amount,
218
+ email: options.email,
219
+ phone: options.phone
220
+ })
221
+ });
222
+ }
223
+ async rechargeViaLink(options) {
224
+ return this.request("/api/sdk/wallet/recharge-via-link", {
225
+ method: "POST",
226
+ body: JSON.stringify({
227
+ amount: options.amount,
228
+ email: options.email,
229
+ phone: options.phone
230
+ })
231
+ });
232
+ }
233
+ async verifyOrder(orderId) {
234
+ return this.request(`/api/sdk/wallet/verify-order?order_id=${encodeURIComponent(orderId)}`, {
235
+ method: "GET"
236
+ });
237
+ }
238
+ async getTransactions(limit, offset) {
239
+ const params = new URLSearchParams();
240
+ if (limit) params.set("limit", limit.toString());
241
+ if (offset) params.set("offset", offset.toString());
242
+ const query = params.toString();
243
+ const path = `/api/sdk/wallet/transactions${query ? `?${query}` : ""}`;
244
+ return this.request(path, {
245
+ method: "GET"
246
+ });
247
+ }
142
248
  };
143
249
  // Annotate the CommonJS export names for ESM import in node:
144
250
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -12,6 +12,7 @@ var BTechWorksClient = class {
12
12
  this.baseUrl = (config.baseUrl || "https://api.btechworks.io").replace(/\/+$/, "");
13
13
  this.timeout = config.timeout || 3e4;
14
14
  }
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
16
  async request(path, options = {}) {
16
17
  const url = `${this.baseUrl}${path}`;
17
18
  const headers = {
@@ -48,6 +49,20 @@ var BTechWorksClient = class {
48
49
  clearTimeout(timeoutId);
49
50
  }
50
51
  }
52
+ async getAnalytics() {
53
+ return this.request("/api/sdk/analytics", {
54
+ method: "GET"
55
+ });
56
+ }
57
+ async checkTemplate(options) {
58
+ return this.request("/api/sdk/check-template", {
59
+ method: "POST",
60
+ body: JSON.stringify({
61
+ template_name: options.templateName,
62
+ template_language: options.templateLanguage
63
+ })
64
+ });
65
+ }
51
66
  async sendMessage(options) {
52
67
  return this.request("/api/sdk/send-message", {
53
68
  method: "POST",
@@ -88,6 +103,18 @@ var BTechWorksClient = class {
88
103
  })
89
104
  });
90
105
  }
106
+ async sendCtcUrl(options) {
107
+ return this.request("/api/sdk/send-ctc-url", {
108
+ method: "POST",
109
+ body: JSON.stringify({
110
+ phone: options.phone,
111
+ body_text: options.bodyText,
112
+ display_text: options.displayText,
113
+ url: options.url,
114
+ footer_text: options.footerText
115
+ })
116
+ });
117
+ }
91
118
  async sendTemplate(options) {
92
119
  return this.request("/api/sdk/send-template", {
93
120
  method: "POST",
@@ -113,6 +140,85 @@ var BTechWorksClient = class {
113
140
  })
114
141
  });
115
142
  }
143
+ async broadcastFromSheet(options) {
144
+ const formData = new FormData();
145
+ formData.append("name", options.name);
146
+ formData.append("template_name", options.templateName);
147
+ if (options.templateLanguage) formData.append("template_language", options.templateLanguage);
148
+ if (options.templateVariables) formData.append("template_variables", JSON.stringify(options.templateVariables));
149
+ formData.append("file", options.file);
150
+ const url = `${this.baseUrl}/api/sdk/broadcast-sheet`;
151
+ const controller = new AbortController();
152
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
153
+ try {
154
+ const response = await globalThis.fetch(url, {
155
+ method: "POST",
156
+ headers: {
157
+ "x-api-key": this.apiKey,
158
+ "x-secret-key": this.secretKey
159
+ },
160
+ body: formData,
161
+ signal: controller.signal
162
+ });
163
+ const data = await response.json();
164
+ return data;
165
+ } catch (error) {
166
+ if (error instanceof DOMException && error.name === "AbortError") {
167
+ return { success: false, message: "Request timeout" };
168
+ }
169
+ return {
170
+ success: false,
171
+ message: error instanceof Error ? error.message : "Unknown error"
172
+ };
173
+ } finally {
174
+ clearTimeout(timeoutId);
175
+ }
176
+ }
177
+ async getBalance() {
178
+ return this.request("/api/sdk/wallet/balance", {
179
+ method: "GET"
180
+ });
181
+ }
182
+ async estimateCost(count = 1) {
183
+ return this.request(`/api/sdk/wallet/balance?count=${count}`, {
184
+ method: "GET"
185
+ });
186
+ }
187
+ async recharge(options) {
188
+ return this.request("/api/sdk/wallet/recharge", {
189
+ method: "POST",
190
+ body: JSON.stringify({
191
+ amount: options.amount,
192
+ email: options.email,
193
+ phone: options.phone
194
+ })
195
+ });
196
+ }
197
+ async rechargeViaLink(options) {
198
+ return this.request("/api/sdk/wallet/recharge-via-link", {
199
+ method: "POST",
200
+ body: JSON.stringify({
201
+ amount: options.amount,
202
+ email: options.email,
203
+ phone: options.phone
204
+ })
205
+ });
206
+ }
207
+ async verifyOrder(orderId) {
208
+ return this.request(`/api/sdk/wallet/verify-order?order_id=${encodeURIComponent(orderId)}`, {
209
+ method: "GET"
210
+ });
211
+ }
212
+ async getTransactions(limit, offset) {
213
+ const params = new URLSearchParams();
214
+ if (limit) params.set("limit", limit.toString());
215
+ if (offset) params.set("offset", offset.toString());
216
+ const query = params.toString();
217
+ const path = `/api/sdk/wallet/transactions${query ? `?${query}` : ""}`;
218
+ return this.request(path, {
219
+ method: "GET"
220
+ });
221
+ }
116
222
  };
117
223
  export {
118
224
  BTechWorksClient
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
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",
3
+ "version": "1.0.6",
4
+ "description": "Official BatchWorks WhatsApp CRM SDK - Send messages, photos, videos, documents, templates, broadcasts, and wallet management via API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",