btechworks-sdk 1.0.2 → 1.0.3
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 +96 -94
- package/dist/index.d.mts +116 -2
- package/dist/index.d.ts +116 -2
- package/dist/index.js +64 -0
- package/dist/index.mjs +64 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,146 +40,148 @@ const client = new BTechWorksClient({
|
|
|
40
40
|
|
|
41
41
|
## Methods
|
|
42
42
|
|
|
43
|
-
###
|
|
44
|
-
|
|
45
|
-
Send a text message to a phone number. Contact and conversation are auto-created.
|
|
43
|
+
### Messaging
|
|
46
44
|
|
|
47
45
|
```typescript
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
49
|
+
// Send photo
|
|
50
|
+
await client.sendPhoto({ phone: '+1234567890', imageUrl: 'https://example.com/photo.jpg', caption: 'Photo' });
|
|
56
51
|
|
|
57
|
-
Send
|
|
52
|
+
// Send video
|
|
53
|
+
await client.sendVideo({ phone: '+1234567890', videoUrl: 'https://example.com/video.mp4', caption: 'Video' });
|
|
58
54
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
phone: '+1234567890',
|
|
62
|
-
imageUrl: 'https://example.com/photo.jpg',
|
|
63
|
-
caption: 'Check out this photo!',
|
|
64
|
-
});
|
|
65
|
-
// { success: true, message: 'Photo sent successfully' }
|
|
55
|
+
// Send document
|
|
56
|
+
await client.sendDocument({ phone: '+1234567890', documentUrl: 'https://example.com/file.pdf', filename: 'file.pdf' });
|
|
66
57
|
```
|
|
67
58
|
|
|
68
|
-
###
|
|
69
|
-
|
|
70
|
-
Send a video with an optional caption.
|
|
59
|
+
### Templates
|
|
71
60
|
|
|
72
61
|
```typescript
|
|
73
|
-
|
|
62
|
+
// Check template variables first
|
|
63
|
+
const check = await client.checkTemplate({ templateName: 'order_confirm' });
|
|
64
|
+
console.log(check.variables); // [{ name: 'name', example: 'John' }]
|
|
65
|
+
|
|
66
|
+
// Send template
|
|
67
|
+
const result = await client.sendTemplate({
|
|
74
68
|
phone: '+1234567890',
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
templateName: 'order_confirm',
|
|
70
|
+
templateLanguage: 'en_US',
|
|
71
|
+
templateParams: ['John', 'Order #12345'],
|
|
77
72
|
});
|
|
78
|
-
// { success: true,
|
|
73
|
+
// { success: true, sent_as: 'template', balance: 99 }
|
|
74
|
+
// OR if 24h window open:
|
|
75
|
+
// { success: true, sent_as: 'text', message: 'Service window open - sent as free text' }
|
|
79
76
|
```
|
|
80
77
|
|
|
81
|
-
###
|
|
82
|
-
|
|
83
|
-
Send a document (PDF, DOC, etc.) with an optional caption.
|
|
78
|
+
### Broadcast
|
|
84
79
|
|
|
85
80
|
```typescript
|
|
86
|
-
const result = await client.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
const result = await client.broadcast({
|
|
82
|
+
name: 'Summer Sale',
|
|
83
|
+
templateName: 'summer_offer',
|
|
84
|
+
templateLanguage: 'en_US',
|
|
85
|
+
recipients: ['+1234567890', '+0987654321'],
|
|
91
86
|
});
|
|
92
|
-
// { success: true, message: '
|
|
87
|
+
// { success: true, message: 'Template "summer_offer" processed: 20 sent, 5 failed' }
|
|
93
88
|
```
|
|
94
89
|
|
|
95
|
-
###
|
|
96
|
-
|
|
97
|
-
Send a WhatsApp template message with variables.
|
|
90
|
+
### Wallet
|
|
98
91
|
|
|
99
92
|
```typescript
|
|
100
|
-
//
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
93
|
+
// Check balance
|
|
94
|
+
const balance = await client.getBalance();
|
|
95
|
+
// { success: true, balance: 100, can_send: 100 }
|
|
96
|
+
|
|
97
|
+
// Estimate cost before sending
|
|
98
|
+
const estimate = await client.estimateCost(50);
|
|
99
|
+
// { success: true, balance: 100, can_send: 100, estimated_templates: 50 }
|
|
100
|
+
|
|
101
|
+
// Generate payment link (user opens link to pay)
|
|
102
|
+
const link = await client.rechargeViaLink({
|
|
103
|
+
amount: 500,
|
|
104
|
+
email: 'user@example.com',
|
|
105
|
+
phone: '+919999999999'
|
|
106
106
|
});
|
|
107
|
-
// { success: true,
|
|
107
|
+
// { success: true, link_url: 'https://cashfree.com/pay/...', order_amount: 500 }
|
|
108
|
+
// User opens link_url and pays via Card/UPI
|
|
108
109
|
|
|
109
|
-
//
|
|
110
|
-
const
|
|
111
|
-
|
|
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
|
-
},
|
|
119
|
-
});
|
|
110
|
+
// Get transaction history
|
|
111
|
+
const txns = await client.getTransactions(10, 0);
|
|
112
|
+
// { success: true, transactions: [...] }
|
|
120
113
|
```
|
|
121
114
|
|
|
122
|
-
###
|
|
123
|
-
|
|
124
|
-
Send a template message to multiple recipients.
|
|
115
|
+
### Analytics
|
|
125
116
|
|
|
126
117
|
```typescript
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
//
|
|
137
|
-
|
|
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' }
|
|
118
|
+
const analytics = await client.getAnalytics();
|
|
119
|
+
// {
|
|
120
|
+
// success: true,
|
|
121
|
+
// analytics: {
|
|
122
|
+
// contacts: 1250,
|
|
123
|
+
// conversations: 890,
|
|
124
|
+
// messages: { today: 45, this_week: 312, this_month: 1250 },
|
|
125
|
+
// templates: 15,
|
|
126
|
+
// recent_broadcasts: [...]
|
|
127
|
+
// }
|
|
128
|
+
// }
|
|
144
129
|
```
|
|
145
130
|
|
|
146
131
|
## Response Format
|
|
147
132
|
|
|
148
|
-
All methods return a simple response
|
|
133
|
+
All methods return a simple response object. **No exceptions are thrown.**
|
|
149
134
|
|
|
150
135
|
```typescript
|
|
151
|
-
//
|
|
136
|
+
// Success
|
|
152
137
|
{ success: true, message: 'Message sent successfully' }
|
|
153
138
|
|
|
139
|
+
// Error
|
|
140
|
+
{ success: false, message: 'Invalid phone number format' }
|
|
141
|
+
|
|
142
|
+
// Template with balance
|
|
143
|
+
{ success: true, sent_as: 'template', balance: 99 }
|
|
144
|
+
|
|
154
145
|
// Broadcast
|
|
155
146
|
{ 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' }
|
|
159
147
|
```
|
|
160
148
|
|
|
161
149
|
## Error Handling
|
|
162
150
|
|
|
163
|
-
All methods
|
|
151
|
+
All methods return response objects with `success: false` on error. No try-catch needed:
|
|
164
152
|
|
|
165
153
|
```typescript
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
console.log(error.message); // Error message
|
|
173
|
-
console.log(error.statusCode); // HTTP status code
|
|
174
|
-
}
|
|
154
|
+
const result = await client.sendMessage({ phone: 'invalid', message: 'Hello!' });
|
|
155
|
+
|
|
156
|
+
if (result.success) {
|
|
157
|
+
console.log('Sent!');
|
|
158
|
+
} else {
|
|
159
|
+
console.log('Failed:', result.message);
|
|
175
160
|
}
|
|
176
161
|
```
|
|
177
162
|
|
|
178
|
-
##
|
|
163
|
+
## Template Flow
|
|
164
|
+
|
|
165
|
+
1. **Check template** - See what variables are needed
|
|
166
|
+
2. **Send template** - Auto-deducts balance OR sends as free text if 24h window open
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// Step 1: Check
|
|
170
|
+
const check = await client.checkTemplate({ templateName: 'welcome' });
|
|
171
|
+
if (!check.ready_to_send) {
|
|
172
|
+
console.log('Missing variables:', check.variables);
|
|
173
|
+
}
|
|
179
174
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
175
|
+
// Step 2: Send (handles everything automatically)
|
|
176
|
+
const result = await client.sendTemplate({
|
|
177
|
+
phone: '+1234567890',
|
|
178
|
+
templateName: 'welcome',
|
|
179
|
+
templateParams: ['John']
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// sent_as: 'text' = Free (24h window open)
|
|
183
|
+
// sent_as: 'template' = Paid (balance deducted)
|
|
184
|
+
```
|
|
183
185
|
|
|
184
186
|
## Getting API Keys
|
|
185
187
|
|
package/dist/index.d.mts
CHANGED
|
@@ -60,6 +60,112 @@ interface BroadcastResponse {
|
|
|
60
60
|
success: boolean;
|
|
61
61
|
message: string;
|
|
62
62
|
}
|
|
63
|
+
interface CheckTemplateOptions {
|
|
64
|
+
templateName: string;
|
|
65
|
+
templateLanguage?: string;
|
|
66
|
+
}
|
|
67
|
+
interface TemplateVariable {
|
|
68
|
+
name: string;
|
|
69
|
+
example: string;
|
|
70
|
+
required: boolean;
|
|
71
|
+
}
|
|
72
|
+
interface CheckTemplateResponse {
|
|
73
|
+
success: boolean;
|
|
74
|
+
exists?: boolean;
|
|
75
|
+
template?: {
|
|
76
|
+
name: string;
|
|
77
|
+
language: string;
|
|
78
|
+
status: string;
|
|
79
|
+
};
|
|
80
|
+
variables?: TemplateVariable[];
|
|
81
|
+
ready_to_send?: boolean;
|
|
82
|
+
message: string;
|
|
83
|
+
}
|
|
84
|
+
interface WalletBalanceResponse {
|
|
85
|
+
success: boolean;
|
|
86
|
+
balance?: number;
|
|
87
|
+
template_rate?: number;
|
|
88
|
+
is_active?: boolean;
|
|
89
|
+
message: string;
|
|
90
|
+
}
|
|
91
|
+
interface AddCreditsOptions {
|
|
92
|
+
amount: number;
|
|
93
|
+
description?: string;
|
|
94
|
+
}
|
|
95
|
+
interface AddCreditsResponse {
|
|
96
|
+
success: boolean;
|
|
97
|
+
balance?: number;
|
|
98
|
+
message: string;
|
|
99
|
+
}
|
|
100
|
+
interface Transaction {
|
|
101
|
+
type: 'credit' | 'debit' | 'refund';
|
|
102
|
+
amount: number;
|
|
103
|
+
balance_after: number;
|
|
104
|
+
description: string;
|
|
105
|
+
created_at: string;
|
|
106
|
+
}
|
|
107
|
+
interface TransactionsResponse {
|
|
108
|
+
success: boolean;
|
|
109
|
+
transactions?: Transaction[];
|
|
110
|
+
message: string;
|
|
111
|
+
}
|
|
112
|
+
interface SendTemplateResponse {
|
|
113
|
+
success: boolean;
|
|
114
|
+
sent_as?: 'text' | 'template';
|
|
115
|
+
balance?: number;
|
|
116
|
+
message: string;
|
|
117
|
+
}
|
|
118
|
+
interface RechargeOptions {
|
|
119
|
+
amount: number;
|
|
120
|
+
email?: string;
|
|
121
|
+
phone?: string;
|
|
122
|
+
}
|
|
123
|
+
interface RechargeResponse {
|
|
124
|
+
success: boolean;
|
|
125
|
+
order_id?: string;
|
|
126
|
+
payment_session_id?: string;
|
|
127
|
+
order_amount?: number;
|
|
128
|
+
message: string;
|
|
129
|
+
}
|
|
130
|
+
interface RechargeViaLinkResponse {
|
|
131
|
+
success: boolean;
|
|
132
|
+
link_id?: string;
|
|
133
|
+
link_url?: string;
|
|
134
|
+
link_status?: string;
|
|
135
|
+
order_amount?: number;
|
|
136
|
+
message: string;
|
|
137
|
+
}
|
|
138
|
+
interface EstimateCostResponse {
|
|
139
|
+
success: boolean;
|
|
140
|
+
balance?: number;
|
|
141
|
+
template_rate?: number;
|
|
142
|
+
can_send?: number;
|
|
143
|
+
estimated_templates?: number;
|
|
144
|
+
message: string;
|
|
145
|
+
}
|
|
146
|
+
interface Broadcast {
|
|
147
|
+
name: string;
|
|
148
|
+
status: string;
|
|
149
|
+
sent_count: number;
|
|
150
|
+
failed_count: number;
|
|
151
|
+
created_at: string;
|
|
152
|
+
}
|
|
153
|
+
interface Analytics {
|
|
154
|
+
contacts: number;
|
|
155
|
+
conversations: number;
|
|
156
|
+
messages: {
|
|
157
|
+
today: number;
|
|
158
|
+
this_week: number;
|
|
159
|
+
this_month: number;
|
|
160
|
+
};
|
|
161
|
+
templates: number;
|
|
162
|
+
recent_broadcasts: Broadcast[];
|
|
163
|
+
}
|
|
164
|
+
interface AnalyticsResponse {
|
|
165
|
+
success: boolean;
|
|
166
|
+
analytics?: Analytics;
|
|
167
|
+
message: string;
|
|
168
|
+
}
|
|
63
169
|
|
|
64
170
|
declare class BTechWorksClient {
|
|
65
171
|
private apiKey;
|
|
@@ -68,12 +174,20 @@ declare class BTechWorksClient {
|
|
|
68
174
|
private timeout;
|
|
69
175
|
constructor(config: BTechWorksConfig);
|
|
70
176
|
private request;
|
|
177
|
+
getAnalytics(): Promise<AnalyticsResponse>;
|
|
178
|
+
checkTemplate(options: CheckTemplateOptions): Promise<CheckTemplateResponse>;
|
|
71
179
|
sendMessage(options: SendMessageOptions): Promise<ApiResponse>;
|
|
72
180
|
sendPhoto(options: SendPhotoOptions): Promise<ApiResponse>;
|
|
73
181
|
sendVideo(options: SendVideoOptions): Promise<ApiResponse>;
|
|
74
182
|
sendDocument(options: SendDocumentOptions): Promise<ApiResponse>;
|
|
75
|
-
sendTemplate(options: SendTemplateOptions): Promise<
|
|
183
|
+
sendTemplate(options: SendTemplateOptions): Promise<SendTemplateResponse>;
|
|
76
184
|
broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
|
|
185
|
+
getBalance(): Promise<WalletBalanceResponse>;
|
|
186
|
+
estimateCost(count?: number): Promise<EstimateCostResponse>;
|
|
187
|
+
addCredits(options: AddCreditsOptions): Promise<AddCreditsResponse>;
|
|
188
|
+
recharge(options: RechargeOptions): Promise<RechargeResponse>;
|
|
189
|
+
rechargeViaLink(options: RechargeOptions): Promise<RechargeViaLinkResponse>;
|
|
190
|
+
getTransactions(limit?: number, offset?: number): Promise<TransactionsResponse>;
|
|
77
191
|
}
|
|
78
192
|
|
|
79
|
-
export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
|
|
193
|
+
export { type AddCreditsOptions, type AddCreditsResponse, type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type CheckTemplateOptions, type CheckTemplateResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendTemplateResponse, type SendVideoOptions, type TemplateVariable, type Transaction, type TransactionsResponse, type WalletBalanceResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -60,6 +60,112 @@ interface BroadcastResponse {
|
|
|
60
60
|
success: boolean;
|
|
61
61
|
message: string;
|
|
62
62
|
}
|
|
63
|
+
interface CheckTemplateOptions {
|
|
64
|
+
templateName: string;
|
|
65
|
+
templateLanguage?: string;
|
|
66
|
+
}
|
|
67
|
+
interface TemplateVariable {
|
|
68
|
+
name: string;
|
|
69
|
+
example: string;
|
|
70
|
+
required: boolean;
|
|
71
|
+
}
|
|
72
|
+
interface CheckTemplateResponse {
|
|
73
|
+
success: boolean;
|
|
74
|
+
exists?: boolean;
|
|
75
|
+
template?: {
|
|
76
|
+
name: string;
|
|
77
|
+
language: string;
|
|
78
|
+
status: string;
|
|
79
|
+
};
|
|
80
|
+
variables?: TemplateVariable[];
|
|
81
|
+
ready_to_send?: boolean;
|
|
82
|
+
message: string;
|
|
83
|
+
}
|
|
84
|
+
interface WalletBalanceResponse {
|
|
85
|
+
success: boolean;
|
|
86
|
+
balance?: number;
|
|
87
|
+
template_rate?: number;
|
|
88
|
+
is_active?: boolean;
|
|
89
|
+
message: string;
|
|
90
|
+
}
|
|
91
|
+
interface AddCreditsOptions {
|
|
92
|
+
amount: number;
|
|
93
|
+
description?: string;
|
|
94
|
+
}
|
|
95
|
+
interface AddCreditsResponse {
|
|
96
|
+
success: boolean;
|
|
97
|
+
balance?: number;
|
|
98
|
+
message: string;
|
|
99
|
+
}
|
|
100
|
+
interface Transaction {
|
|
101
|
+
type: 'credit' | 'debit' | 'refund';
|
|
102
|
+
amount: number;
|
|
103
|
+
balance_after: number;
|
|
104
|
+
description: string;
|
|
105
|
+
created_at: string;
|
|
106
|
+
}
|
|
107
|
+
interface TransactionsResponse {
|
|
108
|
+
success: boolean;
|
|
109
|
+
transactions?: Transaction[];
|
|
110
|
+
message: string;
|
|
111
|
+
}
|
|
112
|
+
interface SendTemplateResponse {
|
|
113
|
+
success: boolean;
|
|
114
|
+
sent_as?: 'text' | 'template';
|
|
115
|
+
balance?: number;
|
|
116
|
+
message: string;
|
|
117
|
+
}
|
|
118
|
+
interface RechargeOptions {
|
|
119
|
+
amount: number;
|
|
120
|
+
email?: string;
|
|
121
|
+
phone?: string;
|
|
122
|
+
}
|
|
123
|
+
interface RechargeResponse {
|
|
124
|
+
success: boolean;
|
|
125
|
+
order_id?: string;
|
|
126
|
+
payment_session_id?: string;
|
|
127
|
+
order_amount?: number;
|
|
128
|
+
message: string;
|
|
129
|
+
}
|
|
130
|
+
interface RechargeViaLinkResponse {
|
|
131
|
+
success: boolean;
|
|
132
|
+
link_id?: string;
|
|
133
|
+
link_url?: string;
|
|
134
|
+
link_status?: string;
|
|
135
|
+
order_amount?: number;
|
|
136
|
+
message: string;
|
|
137
|
+
}
|
|
138
|
+
interface EstimateCostResponse {
|
|
139
|
+
success: boolean;
|
|
140
|
+
balance?: number;
|
|
141
|
+
template_rate?: number;
|
|
142
|
+
can_send?: number;
|
|
143
|
+
estimated_templates?: number;
|
|
144
|
+
message: string;
|
|
145
|
+
}
|
|
146
|
+
interface Broadcast {
|
|
147
|
+
name: string;
|
|
148
|
+
status: string;
|
|
149
|
+
sent_count: number;
|
|
150
|
+
failed_count: number;
|
|
151
|
+
created_at: string;
|
|
152
|
+
}
|
|
153
|
+
interface Analytics {
|
|
154
|
+
contacts: number;
|
|
155
|
+
conversations: number;
|
|
156
|
+
messages: {
|
|
157
|
+
today: number;
|
|
158
|
+
this_week: number;
|
|
159
|
+
this_month: number;
|
|
160
|
+
};
|
|
161
|
+
templates: number;
|
|
162
|
+
recent_broadcasts: Broadcast[];
|
|
163
|
+
}
|
|
164
|
+
interface AnalyticsResponse {
|
|
165
|
+
success: boolean;
|
|
166
|
+
analytics?: Analytics;
|
|
167
|
+
message: string;
|
|
168
|
+
}
|
|
63
169
|
|
|
64
170
|
declare class BTechWorksClient {
|
|
65
171
|
private apiKey;
|
|
@@ -68,12 +174,20 @@ declare class BTechWorksClient {
|
|
|
68
174
|
private timeout;
|
|
69
175
|
constructor(config: BTechWorksConfig);
|
|
70
176
|
private request;
|
|
177
|
+
getAnalytics(): Promise<AnalyticsResponse>;
|
|
178
|
+
checkTemplate(options: CheckTemplateOptions): Promise<CheckTemplateResponse>;
|
|
71
179
|
sendMessage(options: SendMessageOptions): Promise<ApiResponse>;
|
|
72
180
|
sendPhoto(options: SendPhotoOptions): Promise<ApiResponse>;
|
|
73
181
|
sendVideo(options: SendVideoOptions): Promise<ApiResponse>;
|
|
74
182
|
sendDocument(options: SendDocumentOptions): Promise<ApiResponse>;
|
|
75
|
-
sendTemplate(options: SendTemplateOptions): Promise<
|
|
183
|
+
sendTemplate(options: SendTemplateOptions): Promise<SendTemplateResponse>;
|
|
76
184
|
broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
|
|
185
|
+
getBalance(): Promise<WalletBalanceResponse>;
|
|
186
|
+
estimateCost(count?: number): Promise<EstimateCostResponse>;
|
|
187
|
+
addCredits(options: AddCreditsOptions): Promise<AddCreditsResponse>;
|
|
188
|
+
recharge(options: RechargeOptions): Promise<RechargeResponse>;
|
|
189
|
+
rechargeViaLink(options: RechargeOptions): Promise<RechargeViaLinkResponse>;
|
|
190
|
+
getTransactions(limit?: number, offset?: number): Promise<TransactionsResponse>;
|
|
77
191
|
}
|
|
78
192
|
|
|
79
|
-
export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
|
|
193
|
+
export { type AddCreditsOptions, type AddCreditsResponse, type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type CheckTemplateOptions, type CheckTemplateResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendTemplateResponse, type SendVideoOptions, type TemplateVariable, type Transaction, type TransactionsResponse, 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",
|
|
@@ -139,6 +154,55 @@ var BTechWorksClient = class {
|
|
|
139
154
|
})
|
|
140
155
|
});
|
|
141
156
|
}
|
|
157
|
+
async getBalance() {
|
|
158
|
+
return this.request("/api/sdk/wallet/balance", {
|
|
159
|
+
method: "GET"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async estimateCost(count = 1) {
|
|
163
|
+
return this.request(`/api/sdk/wallet/balance?count=${count}`, {
|
|
164
|
+
method: "GET"
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
async addCredits(options) {
|
|
168
|
+
return this.request("/api/sdk/wallet/add-credits", {
|
|
169
|
+
method: "POST",
|
|
170
|
+
body: JSON.stringify({
|
|
171
|
+
amount: options.amount,
|
|
172
|
+
description: options.description
|
|
173
|
+
})
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
async recharge(options) {
|
|
177
|
+
return this.request("/api/sdk/wallet/recharge", {
|
|
178
|
+
method: "POST",
|
|
179
|
+
body: JSON.stringify({
|
|
180
|
+
amount: options.amount,
|
|
181
|
+
email: options.email,
|
|
182
|
+
phone: options.phone
|
|
183
|
+
})
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async rechargeViaLink(options) {
|
|
187
|
+
return this.request("/api/sdk/wallet/recharge-via-link", {
|
|
188
|
+
method: "POST",
|
|
189
|
+
body: JSON.stringify({
|
|
190
|
+
amount: options.amount,
|
|
191
|
+
email: options.email,
|
|
192
|
+
phone: options.phone
|
|
193
|
+
})
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async getTransactions(limit, offset) {
|
|
197
|
+
const params = new URLSearchParams();
|
|
198
|
+
if (limit) params.set("limit", limit.toString());
|
|
199
|
+
if (offset) params.set("offset", offset.toString());
|
|
200
|
+
const query = params.toString();
|
|
201
|
+
const path = `/api/sdk/wallet/transactions${query ? `?${query}` : ""}`;
|
|
202
|
+
return this.request(path, {
|
|
203
|
+
method: "GET"
|
|
204
|
+
});
|
|
205
|
+
}
|
|
142
206
|
};
|
|
143
207
|
// Annotate the CommonJS export names for ESM import in node:
|
|
144
208
|
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",
|
|
@@ -113,6 +128,55 @@ var BTechWorksClient = class {
|
|
|
113
128
|
})
|
|
114
129
|
});
|
|
115
130
|
}
|
|
131
|
+
async getBalance() {
|
|
132
|
+
return this.request("/api/sdk/wallet/balance", {
|
|
133
|
+
method: "GET"
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async estimateCost(count = 1) {
|
|
137
|
+
return this.request(`/api/sdk/wallet/balance?count=${count}`, {
|
|
138
|
+
method: "GET"
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async addCredits(options) {
|
|
142
|
+
return this.request("/api/sdk/wallet/add-credits", {
|
|
143
|
+
method: "POST",
|
|
144
|
+
body: JSON.stringify({
|
|
145
|
+
amount: options.amount,
|
|
146
|
+
description: options.description
|
|
147
|
+
})
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
async recharge(options) {
|
|
151
|
+
return this.request("/api/sdk/wallet/recharge", {
|
|
152
|
+
method: "POST",
|
|
153
|
+
body: JSON.stringify({
|
|
154
|
+
amount: options.amount,
|
|
155
|
+
email: options.email,
|
|
156
|
+
phone: options.phone
|
|
157
|
+
})
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async rechargeViaLink(options) {
|
|
161
|
+
return this.request("/api/sdk/wallet/recharge-via-link", {
|
|
162
|
+
method: "POST",
|
|
163
|
+
body: JSON.stringify({
|
|
164
|
+
amount: options.amount,
|
|
165
|
+
email: options.email,
|
|
166
|
+
phone: options.phone
|
|
167
|
+
})
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
async getTransactions(limit, offset) {
|
|
171
|
+
const params = new URLSearchParams();
|
|
172
|
+
if (limit) params.set("limit", limit.toString());
|
|
173
|
+
if (offset) params.set("offset", offset.toString());
|
|
174
|
+
const query = params.toString();
|
|
175
|
+
const path = `/api/sdk/wallet/transactions${query ? `?${query}` : ""}`;
|
|
176
|
+
return this.request(path, {
|
|
177
|
+
method: "GET"
|
|
178
|
+
});
|
|
179
|
+
}
|
|
116
180
|
};
|
|
117
181
|
export {
|
|
118
182
|
BTechWorksClient
|
package/package.json
CHANGED