@unchainedshop/plugins 4.0.0-rc.8 → 4.0.0-rc.9

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.
@@ -9,7 +9,9 @@ import '../payment/datatrans-v2/index.js';
9
9
  import '../payment/payrexx/index.js';
10
10
  import '../filters/strict-equal.js';
11
11
  import '../filters/local-search.js';
12
- import '../worker/sms.js';
12
+ import '../worker/twilio.js';
13
+ import '../worker/bulkgate.js';
14
+ import '../worker/budgetsms.js';
13
15
  import '../worker/push-notification.js';
14
16
  import '../worker/enrollment-order-generator.js';
15
17
  declare const modules: {
@@ -1 +1 @@
1
- {"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../src/presets/all.ts"],"names":[],"mappings":"AACA,OAAO,mBAAmB,CAAC;AAI3B,OAAO,6BAA6B,CAAC;AACrC,OAAO,uBAAuB,CAAC;AAG/B,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AAGvC,OAAO,4BAA4B,CAAC;AACpC,OAAO,0CAA0C,CAAC;AAClD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,6BAA6B,CAAC;AAGrC,OAAO,4BAA4B,CAAC;AACpC,OAAO,4BAA4B,CAAC;AAGpC,OAAO,kBAAkB,CAAC;AAC1B,OAAO,gCAAgC,CAAC;AACxC,OAAO,yCAAyC,CAAC;AAEjD,QAAA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAQs0C,CAAC;;;;;;wBAD70C,CAAA;;;;;;;;;;;;;;;;;;CAFN,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../src/presets/all.ts"],"names":[],"mappings":"AACA,OAAO,mBAAmB,CAAC;AAI3B,OAAO,6BAA6B,CAAC;AACrC,OAAO,uBAAuB,CAAC;AAG/B,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AAGvC,OAAO,4BAA4B,CAAC;AACpC,OAAO,0CAA0C,CAAC;AAClD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,6BAA6B,CAAC;AAGrC,OAAO,4BAA4B,CAAC;AACpC,OAAO,4BAA4B,CAAC;AAGpC,OAAO,qBAAqB,CAAC;AAC7B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wBAAwB,CAAC;AAChC,OAAO,gCAAgC,CAAC;AACxC,OAAO,yCAAyC,CAAC;AAEjD,QAAA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAQkwC,CAAC;;;;;;wBALzwC,CAAC;;;;;;;;;;;;;;;;;;CAEP,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -17,7 +17,9 @@ import '../payment/payrexx/index.js';
17
17
  import '../filters/strict-equal.js';
18
18
  import '../filters/local-search.js';
19
19
  // Workers
20
- import '../worker/sms.js';
20
+ import '../worker/twilio.js';
21
+ import '../worker/bulkgate.js';
22
+ import '../worker/budgetsms.js';
21
23
  import '../worker/push-notification.js';
22
24
  import '../worker/enrollment-order-generator.js';
23
25
  const modules = {
@@ -1 +1 @@
1
- {"version":3,"file":"all.js","sourceRoot":"","sources":["../../src/presets/all.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,WAAW,CAAC;AACpC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,aAAa,MAAM,aAAa,CAAC;AAExC,WAAW;AACX,OAAO,6BAA6B,CAAC;AACrC,OAAO,uBAAuB,CAAC;AAE/B,UAAU;AACV,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AACvC,OAAO,wBAAwB,MAAM,+BAA+B,CAAC;AACrE,OAAO,2BAA2B,MAAM,8BAA8B,CAAC;AACvE,OAAO,4BAA4B,CAAC;AACpC,OAAO,0CAA0C,CAAC;AAClD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,6BAA6B,CAAC;AAErC,kBAAkB;AAClB,OAAO,4BAA4B,CAAC;AACpC,OAAO,4BAA4B,CAAC;AAEpC,UAAU;AACV,OAAO,kBAAkB,CAAC;AAC1B,OAAO,gCAAgC,CAAC;AACxC,OAAO,yCAAyC,CAAC;AAEjD,MAAM,OAAO,GAAG;IACd,GAAG,WAAW;IACd,GAAG,aAAa;IAChB,GAAG,wBAAwB;IAC3B,GAAG,2BAA2B;CAC/B,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"all.js","sourceRoot":"","sources":["../../src/presets/all.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,WAAW,CAAC;AACpC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,aAAa,MAAM,aAAa,CAAC;AAExC,WAAW;AACX,OAAO,6BAA6B,CAAC;AACrC,OAAO,uBAAuB,CAAC;AAE/B,UAAU;AACV,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AACvC,OAAO,wBAAwB,MAAM,+BAA+B,CAAC;AACrE,OAAO,2BAA2B,MAAM,8BAA8B,CAAC;AACvE,OAAO,4BAA4B,CAAC;AACpC,OAAO,0CAA0C,CAAC;AAClD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,6BAA6B,CAAC;AAErC,kBAAkB;AAClB,OAAO,4BAA4B,CAAC;AACpC,OAAO,4BAA4B,CAAC;AAEpC,UAAU;AACV,OAAO,qBAAqB,CAAC;AAC7B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wBAAwB,CAAC;AAChC,OAAO,gCAAgC,CAAC;AACxC,OAAO,yCAAyC,CAAC;AAEjD,MAAM,OAAO,GAAG;IACd,GAAG,WAAW;IACd,GAAG,aAAa;IAChB,GAAG,wBAAwB;IAC3B,GAAG,2BAA2B;CAC/B,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare function checkBudgetSmsCredentials(): Promise<{
2
+ success: boolean;
3
+ credit: number;
4
+ error?: undefined;
5
+ } | {
6
+ error: any;
7
+ success?: undefined;
8
+ credit?: undefined;
9
+ }>;
10
+ //# sourceMappingURL=budgetsms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"budgetsms.d.ts","sourceRoot":"","sources":["../../src/worker/budgetsms.ts"],"names":[],"mappings":"AA8OA,wBAAsB,yBAAyB;;;;;;;;GA6B9C"}
@@ -0,0 +1,217 @@
1
+ import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
+ const { BUDGETSMS_USERNAME, BUDGETSMS_USERID, BUDGETSMS_HANDLE } = process.env;
3
+ // BudgetSMS Plugin - Verified against official API documentation
4
+ // Note: BudgetSMS API has a quirk where it returns error 1001 (authentication failed)
5
+ // when you have insufficient credit, instead of the correct error 1003.
6
+ const BudgetSMSWorker = {
7
+ ...WorkerAdapter,
8
+ key: 'shop.unchained.worker-plugin.budgetsms',
9
+ label: 'Send Messages through BudgetSMS',
10
+ version: '1.0.0',
11
+ type: 'BUDGETSMS',
12
+ doWork: async ({ from, to, text, test = false, customid, price = false, mccmnc = false, credit = false, ...params }) => {
13
+ try {
14
+ // Validate credentials
15
+ if (!BUDGETSMS_USERNAME || !BUDGETSMS_USERID || !BUDGETSMS_HANDLE) {
16
+ throw new Error('Missing BudgetSMS credentials. Please set BUDGETSMS_USERNAME, BUDGETSMS_USERID, and BUDGETSMS_HANDLE');
17
+ }
18
+ // Trim credentials to remove any whitespace
19
+ const username = BUDGETSMS_USERNAME.trim();
20
+ const userid = BUDGETSMS_USERID.trim();
21
+ const handle = BUDGETSMS_HANDLE.trim();
22
+ // Validate userid is numeric only
23
+ if (!/^\d+$/.test(userid)) {
24
+ throw new Error('BUDGETSMS_USERID must be numeric only. Found: ' + userid);
25
+ }
26
+ // Choose endpoint based on test mode
27
+ const url = test ? 'https://api.budgetsms.net/testsms/' : 'https://api.budgetsms.net/sendsms/';
28
+ // Format phone number according to E.164 (no + or 00, no spaces/dashes)
29
+ const formattedTo = to.replace(/^\+|^00/, '').replace(/[\s-]/g, '');
30
+ // Build query parameters
31
+ const queryParams = new URLSearchParams({
32
+ username: username,
33
+ userid: userid,
34
+ handle: handle,
35
+ msg: text || '', // Note: parameter is 'msg' not 'text'
36
+ from: from || '',
37
+ to: formattedTo,
38
+ ...(customid && { customid }),
39
+ ...(!test && price && { price: '1' }), // Price info only for real sends
40
+ ...(!test && mccmnc && { mccmnc: '1' }), // Carrier info only for real sends
41
+ ...(!test && credit && { credit: '1' }), // Credit info only for real sends
42
+ ...params,
43
+ });
44
+ // Make GET request
45
+ const fullUrl = `${url}?${queryParams.toString()}`;
46
+ const response = await fetch(fullUrl, {
47
+ method: 'GET',
48
+ headers: {
49
+ Accept: 'text/plain',
50
+ 'User-Agent': 'Unchained/BudgetSMS-Plugin',
51
+ },
52
+ });
53
+ const responseText = await response.text().then((text) => text.trim());
54
+ // Parse response: "OK <smsid> [price] [parts] [mccmnc] [credit]" or "ERR <errorcode>"
55
+ if (responseText.startsWith('OK')) {
56
+ const parts = responseText.split(' ');
57
+ const result = {
58
+ sms_id: parts[1] || null,
59
+ status: test ? 'test_successful' : 'sent',
60
+ test_mode: test,
61
+ };
62
+ if (test) {
63
+ result.message = 'Test SMS validated successfully (no credit deducted)';
64
+ }
65
+ else {
66
+ // Parse additional info based on parameters used
67
+ let index = 2;
68
+ if (price && parts[index] && parts[index + 1]) {
69
+ result.price = parseFloat(parts[index]);
70
+ result.parts = parseInt(parts[index + 1]);
71
+ index += 2;
72
+ }
73
+ if (mccmnc && parts[index]) {
74
+ result.mccmnc = parts[index];
75
+ index += 1;
76
+ }
77
+ if (credit && parts[index]) {
78
+ result.remaining_credit = parseFloat(parts[index]);
79
+ }
80
+ }
81
+ return {
82
+ success: true,
83
+ result,
84
+ error: null,
85
+ };
86
+ }
87
+ if (responseText.startsWith('ERR')) {
88
+ const parts = responseText.split(' ');
89
+ const errorCode = parts[1] || 'UNKNOWN';
90
+ // Error code mappings from documentation
91
+ const errorMessages = {
92
+ '1001': 'Authentication failed OR insufficient credit (BudgetSMS returns 1001 for both)',
93
+ '1002': 'Account not active',
94
+ '1003': 'Insufficient credit',
95
+ '1004': 'No access to this API',
96
+ '1005': 'No handle provided',
97
+ '1006': 'No UserID provided',
98
+ '1007': 'No Username provided',
99
+ '2001': 'SMS message text is empty',
100
+ '2002': 'SMS numeric senderid can be max. 16 numbers',
101
+ '2003': 'SMS alphanumeric sender can be max. 11 characters',
102
+ '2004': 'SMS senderid is empty or invalid',
103
+ '2005': 'Destination number is too short',
104
+ '2006': 'Destination is not numeric',
105
+ '2007': 'Destination is empty',
106
+ '2008': 'SMS text is not OK (check encoding?)',
107
+ '2009': 'Parameter issue',
108
+ '2010': 'Destination number is invalidly formatted',
109
+ '2011': 'Destination is invalid',
110
+ '2012': 'SMS message text is too long',
111
+ '2013': 'SMS message is invalid',
112
+ '2014': 'SMS CustomID is used before',
113
+ '2015': 'Charset problem',
114
+ '2016': 'Invalid UTF-8 encoding',
115
+ '3001': 'No route to destination',
116
+ '3002': 'No routes are setup',
117
+ '3003': 'Invalid destination',
118
+ '4001': 'System error, related to customid',
119
+ '4002': 'System error, temporary issue',
120
+ };
121
+ // Special handling for 1001 error
122
+ let message = errorMessages[errorCode] || `Unknown error code: ${errorCode}`;
123
+ if (errorCode === '1001') {
124
+ message += '. Note: Check your account balance - BudgetSMS may return 1001 when credit is 0.';
125
+ }
126
+ return {
127
+ success: false,
128
+ error: {
129
+ name: 'BUDGETSMS_ERROR',
130
+ code: errorCode,
131
+ message,
132
+ },
133
+ };
134
+ }
135
+ // Unexpected response
136
+ return {
137
+ success: false,
138
+ error: {
139
+ name: 'BUDGETSMS_ERROR',
140
+ message: 'Unexpected response format from BudgetSMS API',
141
+ response: responseText,
142
+ },
143
+ };
144
+ }
145
+ catch (err) {
146
+ return {
147
+ success: false,
148
+ error: {
149
+ name: err.name,
150
+ message: err.message,
151
+ stack: err.stack,
152
+ },
153
+ };
154
+ }
155
+ },
156
+ };
157
+ WorkerDirector.registerAdapter(BudgetSMSWorker);
158
+ // Environment variables needed:
159
+ // BUDGETSMS_USERNAME=your_username (alphanumeric)
160
+ // BUDGETSMS_USERID=your_userid (NUMERIC ONLY - found in BudgetSMS control panel)
161
+ // BUDGETSMS_HANDLE=your_api_handle (alphanumeric - found in BudgetSMS control panel)
162
+ // IMPORTANT: The userid MUST be numeric only. You can find it in the BudgetSMS control panel after login.
163
+ // Example: BUDGETSMS_USERID=12345 (NOT "user12345" or any non-numeric value)
164
+ // Usage examples:
165
+ //
166
+ // Send real SMS (requires credits):
167
+ // await WorkerDirector.doWork({
168
+ // type: 'BUDGETSMS',
169
+ // from: 'YourCompany',
170
+ // to: '+41791234567',
171
+ // text: 'Your message here',
172
+ // price: true, // Get price info
173
+ // credit: true, // Get remaining credit
174
+ // });
175
+ //
176
+ // Test SMS (no credit deducted):
177
+ // await WorkerDirector.doWork({
178
+ // type: 'BUDGETSMS',
179
+ // test: true,
180
+ // from: 'YourCompany',
181
+ // to: '+41791234567',
182
+ // text: 'Test message',
183
+ // });
184
+ //
185
+ // IMPORTANT: If you get error 1001, it could mean either:
186
+ // 1. Authentication failed (wrong credentials)
187
+ // 2. Insufficient credit (0 balance)
188
+ // Use the checkBudgetSmsCredentials() helper to verify which one it is.
189
+ // Helper function to check credentials and balance
190
+ export async function checkBudgetSmsCredentials() {
191
+ const url = 'https://api.budgetsms.net/checkcredit/';
192
+ const username = process.env.BUDGETSMS_USERNAME?.trim();
193
+ const userid = process.env.BUDGETSMS_USERID?.trim();
194
+ const handle = process.env.BUDGETSMS_HANDLE?.trim();
195
+ if (!username || !userid || !handle) {
196
+ return { error: 'Missing credentials' };
197
+ }
198
+ if (!/^\d+$/.test(userid)) {
199
+ return { error: 'UserID must be numeric only' };
200
+ }
201
+ const queryParams = new URLSearchParams({ username, userid, handle });
202
+ try {
203
+ const response = await fetch(`${url}?${queryParams.toString()}`, { method: 'GET' });
204
+ const text = await response.text();
205
+ if (text.startsWith('OK')) {
206
+ const credit = parseFloat(text.split(' ')[1]) || 0;
207
+ return { success: true, credit };
208
+ }
209
+ else {
210
+ return { error: text };
211
+ }
212
+ }
213
+ catch (err) {
214
+ return { error: err.message };
215
+ }
216
+ }
217
+ //# sourceMappingURL=budgetsms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"budgetsms.js","sourceRoot":"","sources":["../../src/worker/budgetsms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEpF,MAAM,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE/E,iEAAiE;AACjE,sFAAsF;AACtF,wEAAwE;AACxE,MAAM,eAAe,GAajB;IACF,GAAG,aAAa;IAEhB,GAAG,EAAE,wCAAwC;IAC7C,KAAK,EAAE,iCAAiC;IACxC,OAAO,EAAE,OAAO;IAEhB,IAAI,EAAE,WAAW;IAEjB,MAAM,EAAE,KAAK,EAAE,EACb,IAAI,EACJ,EAAE,EACF,IAAI,EACJ,IAAI,GAAG,KAAK,EACZ,QAAQ,EACR,KAAK,GAAG,KAAK,EACb,MAAM,GAAG,KAAK,EACd,MAAM,GAAG,KAAK,EACd,GAAG,MAAM,EACV,EAAE,EAAE;QACH,IAAI,CAAC;YACH,uBAAuB;YACvB,IAAI,CAAC,kBAAkB,IAAI,CAAC,gBAAgB,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAClE,MAAM,IAAI,KAAK,CACb,sGAAsG,CACvG,CAAC;YACJ,CAAC;YAED,4CAA4C;YAC5C,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,EAAE,CAAC;YAC3C,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC;YAEvC,kCAAkC;YAClC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,gDAAgD,GAAG,MAAM,CAAC,CAAC;YAC7E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O,EAAE,CAAC;IAChC,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=bulkgate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bulkgate.d.ts","sourceRoot":"","sources":["../../src/worker/bulkgate.ts"],"names":[],"mappings":""}
@@ -0,0 +1,104 @@
1
+ import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
+ const { BULKGATE_APPLICATION_ID, BULKGATE_APPLICATION_TOKEN } = process.env;
3
+ // BulkGate Simple API for SMS (transactional by default, promotional via boolean)
4
+ const BulkGateWorker = {
5
+ ...WorkerAdapter,
6
+ key: 'shop.unchained.worker-plugin.bulkgate',
7
+ label: 'Send SMS through BulkGate',
8
+ version: '1.0.0',
9
+ type: 'BULKGATE',
10
+ doWork: async ({ from, to, text, unicode = false, country, schedule, promotional = false, ...params }) => {
11
+ try {
12
+ // Choose API endpoint based on promotional flag
13
+ const url = promotional
14
+ ? 'https://portal.bulkgate.com/api/1.0/simple/promotional'
15
+ : 'https://portal.bulkgate.com/api/1.0/simple/transactional';
16
+ // Prepare the request body
17
+ const requestBody = {
18
+ application_id: BULKGATE_APPLICATION_ID,
19
+ application_token: BULKGATE_APPLICATION_TOKEN,
20
+ number: to, // Phone number in international format (or semicolon-separated for promotional)
21
+ text: text || '',
22
+ unicode: unicode, // Boolean value for unicode support
23
+ sender_id: from ? 'gText' : 'gSystem', // Use text sender if 'from' is provided
24
+ sender_id_value: from || '', // Custom sender name if using gText
25
+ ...(country && { country }), // Optional country code
26
+ ...(schedule && { schedule }), // Optional scheduled time
27
+ ...params, // Any additional parameters
28
+ };
29
+ const response = await fetch(url, {
30
+ method: 'POST',
31
+ headers: {
32
+ 'Content-Type': 'application/json',
33
+ 'Cache-Control': 'no-cache',
34
+ },
35
+ body: JSON.stringify(requestBody),
36
+ });
37
+ const responseData = await response.json();
38
+ // Check if we have an error response
39
+ if (responseData.error || responseData.type) {
40
+ return {
41
+ success: false,
42
+ error: {
43
+ name: 'BULKGATE_ERROR',
44
+ message: responseData.error ||
45
+ `Failed to send ${promotional ? 'promotional' : 'transactional'} SMS`,
46
+ type: responseData.type || null,
47
+ code: responseData.code || response.status,
48
+ detail: responseData.detail || null,
49
+ },
50
+ };
51
+ }
52
+ // Success response (transactional has specific structure, promotional might vary)
53
+ if (responseData.data) {
54
+ // For transactional SMS, check for specific accepted status
55
+ if (!promotional && responseData.data.status === 'accepted') {
56
+ return {
57
+ success: true,
58
+ result: {
59
+ sms_id: responseData.data.sms_id,
60
+ price: responseData.data.price,
61
+ credit: responseData.data.credit,
62
+ number: responseData.data.number,
63
+ status: responseData.data.status,
64
+ },
65
+ error: null,
66
+ };
67
+ }
68
+ // For promotional SMS or other successful responses
69
+ if (promotional || responseData.data.status) {
70
+ return {
71
+ success: true,
72
+ result: responseData.data,
73
+ error: null,
74
+ };
75
+ }
76
+ }
77
+ // Unexpected response format
78
+ return {
79
+ success: false,
80
+ error: {
81
+ name: 'BULKGATE_ERROR',
82
+ message: 'Unexpected response format from BulkGate API',
83
+ response: responseData,
84
+ },
85
+ };
86
+ }
87
+ catch (err) {
88
+ return {
89
+ success: false,
90
+ error: {
91
+ name: err.name,
92
+ message: err.message,
93
+ stack: err.stack,
94
+ },
95
+ };
96
+ }
97
+ },
98
+ };
99
+ // Register the plugin
100
+ WorkerDirector.registerAdapter(BulkGateWorker);
101
+ // Environment variables needed:
102
+ // BULKGATE_APPLICATION_ID=your_application_id
103
+ // BULKGATE_APPLICATION_TOKEN=your_application_token
104
+ //# sourceMappingURL=bulkgate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bulkgate.js","sourceRoot":"","sources":["../../src/worker/bulkgate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEpF,MAAM,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE5E,kFAAkF;AA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J,CAAC;YACH,CAAC;YAED,6BAA6B;YAC7B,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,gBAAgB;oBACtB,OAAO,EAAE,8CAA8C;oBACvD,QAAQ,EAAE,YAAY;iBACvB;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB;aACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC;AAEF,sBAAsB;AACtB,cAAc,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;AAE/C,gCAAgC;AAChC,8CAA8C;AAC9C,oDAAoD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=twilio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"twilio.d.ts","sourceRoot":"","sources":["../../src/worker/twilio.ts"],"names":[],"mappings":""}
@@ -0,0 +1,56 @@
1
+ import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
+ const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_SMS_FROM } = process.env;
3
+ const SmsWorkerPlugin = {
4
+ ...WorkerAdapter,
5
+ key: 'shop.unchained.worker-plugin.twilio',
6
+ label: 'Send Messages through Twilio',
7
+ version: '1.0.0',
8
+ type: 'TWILIO',
9
+ doWork: async ({ from, to, text, ...params }) => {
10
+ try {
11
+ const url = `https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Messages.json`;
12
+ const response = await fetch(url, {
13
+ method: 'POST',
14
+ headers: {
15
+ Authorization: `Basic ${Buffer.from(`${TWILIO_ACCOUNT_SID}:${TWILIO_AUTH_TOKEN}`).toString('base64')}`,
16
+ 'Content-Type': 'application/x-www-form-urlencoded',
17
+ },
18
+ body: new URLSearchParams({
19
+ Body: text || '',
20
+ From: from || TWILIO_SMS_FROM,
21
+ To: to,
22
+ ...params, // Include any additional parameters passed
23
+ }),
24
+ });
25
+ const data = await response.json();
26
+ if (!response.ok) {
27
+ return {
28
+ success: false,
29
+ error: {
30
+ name: 'TWILIO_ERROR',
31
+ message: data.message || 'Failed to send SMS',
32
+ },
33
+ };
34
+ }
35
+ return {
36
+ success: true,
37
+ result: {
38
+ sid: data.sid,
39
+ },
40
+ error: null,
41
+ };
42
+ }
43
+ catch (err) {
44
+ return {
45
+ success: false,
46
+ error: {
47
+ name: err.name,
48
+ message: err.message,
49
+ stack: err.stack,
50
+ },
51
+ };
52
+ }
53
+ },
54
+ };
55
+ WorkerDirector.registerAdapter(SmsWorkerPlugin);
56
+ //# sourceMappingURL=twilio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"twilio.js","sourceRoot":"","sources":["../../src/worker/twilio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEpF,MAAM,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE/E,MAAM,eAAe,GAQjB;IACF,GAAG,aAAa;IAEhB,GAAG,EAAE,qCAAqC;IAC1C,KAAK,EAAE,8BAA8B;IACrC,OAAO,EAAE,OAAO;IAEhB,IAAI,EAAE,QAAQ;IAEd,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE;QAC9C,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,8CAA8C,kBAAkB,gBAAgB,CAAC;YAC7F,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAChC,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACP,aAAa,EAAE,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,kBAAkB,IAAI,iBAAiB,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;oBACtG,cAAc,EAAE,mCAAmC;iBACpD;gBACD,IAAI,EAAE,IAAI,eAAe,CAAC;oBACxB,IAAI,EAAE,IAAI,IAAI,EAAE;oBAChB,IAAI,EAAE,IAAI,IAAI,eAAe;oBAC7B,EAAE,EAAE,EAAE;oBACN,GAAG,MAAM,EAAE,2CAA2C;iBACvD,CAAC;aACH,CAAC,CAAC;YAEH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAEnC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE;wBACL,IAAI,EAAE,cAAc;wBACpB,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,oBAAoB;qBAC9C;iBACF,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,GAAG,EAAE,IAAI,CAAC,GAAG;iBACd;gBACD,KAAK,EAAE,IAAI;aACZ,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB;aACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC;AAEF,cAAc,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/plugins",
3
- "version": "4.0.0-rc.8",
3
+ "version": "4.0.0-rc.9",
4
4
  "main": "lib/plugins-index.js",
5
5
  "types": "lib/plugins-index.d.ts",
6
6
  "exports": {
@@ -21,7 +21,9 @@ import '../filters/strict-equal.js';
21
21
  import '../filters/local-search.js';
22
22
 
23
23
  // Workers
24
- import '../worker/sms.js';
24
+ import '../worker/twilio.js';
25
+ import '../worker/bulkgate.js';
26
+ import '../worker/budgetsms.js';
25
27
  import '../worker/push-notification.js';
26
28
  import '../worker/enrollment-order-generator.js';
27
29
 
@@ -0,0 +1,268 @@
1
+ import { IWorkerAdapter, WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
+
3
+ const { BUDGETSMS_USERNAME, BUDGETSMS_USERID, BUDGETSMS_HANDLE } = process.env;
4
+
5
+ // BudgetSMS Plugin - Verified against official API documentation
6
+ // Note: BudgetSMS API has a quirk where it returns error 1001 (authentication failed)
7
+ // when you have insufficient credit, instead of the correct error 1003.
8
+ const BudgetSMSWorker: IWorkerAdapter<
9
+ {
10
+ from?: string;
11
+ to?: string;
12
+ text?: string;
13
+ test?: boolean; // If true, uses test endpoint (no credit deducted)
14
+ customid?: string;
15
+ price?: boolean; // Include price info in response
16
+ mccmnc?: boolean; // Include carrier info in response
17
+ credit?: boolean; // Include remaining credit in response
18
+ [key: string]: any;
19
+ },
20
+ any
21
+ > = {
22
+ ...WorkerAdapter,
23
+
24
+ key: 'shop.unchained.worker-plugin.budgetsms',
25
+ label: 'Send Messages through BudgetSMS',
26
+ version: '1.0.0',
27
+
28
+ type: 'BUDGETSMS',
29
+
30
+ doWork: async ({
31
+ from,
32
+ to,
33
+ text,
34
+ test = false,
35
+ customid,
36
+ price = false,
37
+ mccmnc = false,
38
+ credit = false,
39
+ ...params
40
+ }) => {
41
+ try {
42
+ // Validate credentials
43
+ if (!BUDGETSMS_USERNAME || !BUDGETSMS_USERID || !BUDGETSMS_HANDLE) {
44
+ throw new Error(
45
+ 'Missing BudgetSMS credentials. Please set BUDGETSMS_USERNAME, BUDGETSMS_USERID, and BUDGETSMS_HANDLE',
46
+ );
47
+ }
48
+
49
+ // Trim credentials to remove any whitespace
50
+ const username = BUDGETSMS_USERNAME.trim();
51
+ const userid = BUDGETSMS_USERID.trim();
52
+ const handle = BUDGETSMS_HANDLE.trim();
53
+
54
+ // Validate userid is numeric only
55
+ if (!/^\d+$/.test(userid)) {
56
+ throw new Error('BUDGETSMS_USERID must be numeric only. Found: ' + userid);
57
+ }
58
+
59
+ // Choose endpoint based on test mode
60
+ const url = test ? 'https://api.budgetsms.net/testsms/' : 'https://api.budgetsms.net/sendsms/';
61
+
62
+ // Format phone number according to E.164 (no + or 00, no spaces/dashes)
63
+ const formattedTo = to.replace(/^\+|^00/, '').replace(/[\s-]/g, '');
64
+
65
+ // Build query parameters
66
+ const queryParams = new URLSearchParams({
67
+ username: username,
68
+ userid: userid,
69
+ handle: handle,
70
+ msg: text || '', // Note: parameter is 'msg' not 'text'
71
+ from: from || '',
72
+ to: formattedTo,
73
+ ...(customid && { customid }),
74
+ ...(!test && price && { price: '1' }), // Price info only for real sends
75
+ ...(!test && mccmnc && { mccmnc: '1' }), // Carrier info only for real sends
76
+ ...(!test && credit && { credit: '1' }), // Credit info only for real sends
77
+ ...params,
78
+ });
79
+
80
+ // Make GET request
81
+ const fullUrl = `${url}?${queryParams.toString()}`;
82
+
83
+ const response = await fetch(fullUrl, {
84
+ method: 'GET',
85
+ headers: {
86
+ Accept: 'text/plain',
87
+ 'User-Agent': 'Unchained/BudgetSMS-Plugin',
88
+ },
89
+ });
90
+
91
+ const responseText = await response.text().then((text) => text.trim());
92
+
93
+ // Parse response: "OK <smsid> [price] [parts] [mccmnc] [credit]" or "ERR <errorcode>"
94
+ if (responseText.startsWith('OK')) {
95
+ const parts = responseText.split(' ');
96
+ const result: any = {
97
+ sms_id: parts[1] || null,
98
+ status: test ? 'test_successful' : 'sent',
99
+ test_mode: test,
100
+ };
101
+
102
+ if (test) {
103
+ result.message = 'Test SMS validated successfully (no credit deducted)';
104
+ } else {
105
+ // Parse additional info based on parameters used
106
+ let index = 2;
107
+ if (price && parts[index] && parts[index + 1]) {
108
+ result.price = parseFloat(parts[index]);
109
+ result.parts = parseInt(parts[index + 1]);
110
+ index += 2;
111
+ }
112
+ if (mccmnc && parts[index]) {
113
+ result.mccmnc = parts[index];
114
+ index += 1;
115
+ }
116
+ if (credit && parts[index]) {
117
+ result.remaining_credit = parseFloat(parts[index]);
118
+ }
119
+ }
120
+
121
+ return {
122
+ success: true,
123
+ result,
124
+ error: null,
125
+ };
126
+ }
127
+
128
+ if (responseText.startsWith('ERR')) {
129
+ const parts = responseText.split(' ');
130
+ const errorCode = parts[1] || 'UNKNOWN';
131
+
132
+ // Error code mappings from documentation
133
+ const errorMessages: Record<string, string> = {
134
+ '1001': 'Authentication failed OR insufficient credit (BudgetSMS returns 1001 for both)',
135
+ '1002': 'Account not active',
136
+ '1003': 'Insufficient credit',
137
+ '1004': 'No access to this API',
138
+ '1005': 'No handle provided',
139
+ '1006': 'No UserID provided',
140
+ '1007': 'No Username provided',
141
+ '2001': 'SMS message text is empty',
142
+ '2002': 'SMS numeric senderid can be max. 16 numbers',
143
+ '2003': 'SMS alphanumeric sender can be max. 11 characters',
144
+ '2004': 'SMS senderid is empty or invalid',
145
+ '2005': 'Destination number is too short',
146
+ '2006': 'Destination is not numeric',
147
+ '2007': 'Destination is empty',
148
+ '2008': 'SMS text is not OK (check encoding?)',
149
+ '2009': 'Parameter issue',
150
+ '2010': 'Destination number is invalidly formatted',
151
+ '2011': 'Destination is invalid',
152
+ '2012': 'SMS message text is too long',
153
+ '2013': 'SMS message is invalid',
154
+ '2014': 'SMS CustomID is used before',
155
+ '2015': 'Charset problem',
156
+ '2016': 'Invalid UTF-8 encoding',
157
+ '3001': 'No route to destination',
158
+ '3002': 'No routes are setup',
159
+ '3003': 'Invalid destination',
160
+ '4001': 'System error, related to customid',
161
+ '4002': 'System error, temporary issue',
162
+ };
163
+
164
+ // Special handling for 1001 error
165
+ let message = errorMessages[errorCode] || `Unknown error code: ${errorCode}`;
166
+ if (errorCode === '1001') {
167
+ message += '. Note: Check your account balance - BudgetSMS may return 1001 when credit is 0.';
168
+ }
169
+
170
+ return {
171
+ success: false,
172
+ error: {
173
+ name: 'BUDGETSMS_ERROR',
174
+ code: errorCode,
175
+ message,
176
+ },
177
+ };
178
+ }
179
+
180
+ // Unexpected response
181
+ return {
182
+ success: false,
183
+ error: {
184
+ name: 'BUDGETSMS_ERROR',
185
+ message: 'Unexpected response format from BudgetSMS API',
186
+ response: responseText,
187
+ },
188
+ };
189
+ } catch (err) {
190
+ return {
191
+ success: false,
192
+ error: {
193
+ name: err.name,
194
+ message: err.message,
195
+ stack: err.stack,
196
+ },
197
+ };
198
+ }
199
+ },
200
+ };
201
+
202
+ WorkerDirector.registerAdapter(BudgetSMSWorker);
203
+
204
+ // Environment variables needed:
205
+ // BUDGETSMS_USERNAME=your_username (alphanumeric)
206
+ // BUDGETSMS_USERID=your_userid (NUMERIC ONLY - found in BudgetSMS control panel)
207
+ // BUDGETSMS_HANDLE=your_api_handle (alphanumeric - found in BudgetSMS control panel)
208
+
209
+ // IMPORTANT: The userid MUST be numeric only. You can find it in the BudgetSMS control panel after login.
210
+ // Example: BUDGETSMS_USERID=12345 (NOT "user12345" or any non-numeric value)
211
+
212
+ // Usage examples:
213
+ //
214
+ // Send real SMS (requires credits):
215
+ // await WorkerDirector.doWork({
216
+ // type: 'BUDGETSMS',
217
+ // from: 'YourCompany',
218
+ // to: '+41791234567',
219
+ // text: 'Your message here',
220
+ // price: true, // Get price info
221
+ // credit: true, // Get remaining credit
222
+ // });
223
+ //
224
+ // Test SMS (no credit deducted):
225
+ // await WorkerDirector.doWork({
226
+ // type: 'BUDGETSMS',
227
+ // test: true,
228
+ // from: 'YourCompany',
229
+ // to: '+41791234567',
230
+ // text: 'Test message',
231
+ // });
232
+ //
233
+ // IMPORTANT: If you get error 1001, it could mean either:
234
+ // 1. Authentication failed (wrong credentials)
235
+ // 2. Insufficient credit (0 balance)
236
+ // Use the checkBudgetSmsCredentials() helper to verify which one it is.
237
+
238
+ // Helper function to check credentials and balance
239
+ export async function checkBudgetSmsCredentials() {
240
+ const url = 'https://api.budgetsms.net/checkcredit/';
241
+ const username = process.env.BUDGETSMS_USERNAME?.trim();
242
+ const userid = process.env.BUDGETSMS_USERID?.trim();
243
+ const handle = process.env.BUDGETSMS_HANDLE?.trim();
244
+
245
+ if (!username || !userid || !handle) {
246
+ return { error: 'Missing credentials' };
247
+ }
248
+
249
+ if (!/^\d+$/.test(userid)) {
250
+ return { error: 'UserID must be numeric only' };
251
+ }
252
+
253
+ const queryParams = new URLSearchParams({ username, userid, handle });
254
+
255
+ try {
256
+ const response = await fetch(`${url}?${queryParams.toString()}`, { method: 'GET' });
257
+ const text = await response.text();
258
+
259
+ if (text.startsWith('OK')) {
260
+ const credit = parseFloat(text.split(' ')[1]) || 0;
261
+ return { success: true, credit };
262
+ } else {
263
+ return { error: text };
264
+ }
265
+ } catch (err) {
266
+ return { error: err.message };
267
+ }
268
+ }
@@ -0,0 +1,138 @@
1
+ import { IWorkerAdapter, WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
+
3
+ const { BULKGATE_APPLICATION_ID, BULKGATE_APPLICATION_TOKEN } = process.env;
4
+
5
+ // BulkGate Simple API for SMS (transactional by default, promotional via boolean)
6
+ const BulkGateWorker: IWorkerAdapter<
7
+ {
8
+ from?: string;
9
+ to?: string;
10
+ text?: string;
11
+ unicode?: boolean;
12
+ country?: string;
13
+ schedule?: string | number; // ISO 8601 format or Unix timestamp
14
+ promotional?: boolean; // Set to true for promotional SMS, defaults to transactional
15
+ [key: string]: any;
16
+ },
17
+ any
18
+ > = {
19
+ ...WorkerAdapter,
20
+
21
+ key: 'shop.unchained.worker-plugin.bulkgate',
22
+ label: 'Send SMS through BulkGate',
23
+ version: '1.0.0',
24
+
25
+ type: 'BULKGATE',
26
+
27
+ doWork: async ({
28
+ from,
29
+ to,
30
+ text,
31
+ unicode = false,
32
+ country,
33
+ schedule,
34
+ promotional = false,
35
+ ...params
36
+ }) => {
37
+ try {
38
+ // Choose API endpoint based on promotional flag
39
+ const url = promotional
40
+ ? 'https://portal.bulkgate.com/api/1.0/simple/promotional'
41
+ : 'https://portal.bulkgate.com/api/1.0/simple/transactional';
42
+
43
+ // Prepare the request body
44
+ const requestBody = {
45
+ application_id: BULKGATE_APPLICATION_ID,
46
+ application_token: BULKGATE_APPLICATION_TOKEN,
47
+ number: to, // Phone number in international format (or semicolon-separated for promotional)
48
+ text: text || '',
49
+ unicode: unicode, // Boolean value for unicode support
50
+ sender_id: from ? 'gText' : 'gSystem', // Use text sender if 'from' is provided
51
+ sender_id_value: from || '', // Custom sender name if using gText
52
+ ...(country && { country }), // Optional country code
53
+ ...(schedule && { schedule }), // Optional scheduled time
54
+ ...params, // Any additional parameters
55
+ };
56
+
57
+ const response = await fetch(url, {
58
+ method: 'POST',
59
+ headers: {
60
+ 'Content-Type': 'application/json',
61
+ 'Cache-Control': 'no-cache',
62
+ },
63
+ body: JSON.stringify(requestBody),
64
+ });
65
+
66
+ const responseData = await response.json();
67
+
68
+ // Check if we have an error response
69
+ if (responseData.error || responseData.type) {
70
+ return {
71
+ success: false,
72
+ error: {
73
+ name: 'BULKGATE_ERROR',
74
+ message:
75
+ responseData.error ||
76
+ `Failed to send ${promotional ? 'promotional' : 'transactional'} SMS`,
77
+ type: responseData.type || null,
78
+ code: responseData.code || response.status,
79
+ detail: responseData.detail || null,
80
+ },
81
+ };
82
+ }
83
+
84
+ // Success response (transactional has specific structure, promotional might vary)
85
+ if (responseData.data) {
86
+ // For transactional SMS, check for specific accepted status
87
+ if (!promotional && responseData.data.status === 'accepted') {
88
+ return {
89
+ success: true,
90
+ result: {
91
+ sms_id: responseData.data.sms_id,
92
+ price: responseData.data.price,
93
+ credit: responseData.data.credit,
94
+ number: responseData.data.number,
95
+ status: responseData.data.status,
96
+ },
97
+ error: null,
98
+ };
99
+ }
100
+
101
+ // For promotional SMS or other successful responses
102
+ if (promotional || responseData.data.status) {
103
+ return {
104
+ success: true,
105
+ result: responseData.data,
106
+ error: null,
107
+ };
108
+ }
109
+ }
110
+
111
+ // Unexpected response format
112
+ return {
113
+ success: false,
114
+ error: {
115
+ name: 'BULKGATE_ERROR',
116
+ message: 'Unexpected response format from BulkGate API',
117
+ response: responseData,
118
+ },
119
+ };
120
+ } catch (err) {
121
+ return {
122
+ success: false,
123
+ error: {
124
+ name: err.name,
125
+ message: err.message,
126
+ stack: err.stack,
127
+ },
128
+ };
129
+ }
130
+ },
131
+ };
132
+
133
+ // Register the plugin
134
+ WorkerDirector.registerAdapter(BulkGateWorker);
135
+
136
+ // Environment variables needed:
137
+ // BULKGATE_APPLICATION_ID=your_application_id
138
+ // BULKGATE_APPLICATION_TOKEN=your_application_token
@@ -7,38 +7,19 @@ const SmsWorkerPlugin: IWorkerAdapter<
7
7
  from?: string;
8
8
  to?: string;
9
9
  text?: string;
10
+ [key: string]: any; // Allow additional parameters
10
11
  },
11
12
  any
12
13
  > = {
13
14
  ...WorkerAdapter,
14
15
 
15
- key: 'shop.unchained.worker-plugin.sms',
16
- label: 'Send a SMS through Twilio',
16
+ key: 'shop.unchained.worker-plugin.twilio',
17
+ label: 'Send Messages through Twilio',
17
18
  version: '1.0.0',
18
19
 
19
- type: 'SMS',
20
-
21
- doWork: async ({ from, to, text }) => {
22
- if (!TWILIO_SMS_FROM && !from) {
23
- return {
24
- success: false,
25
- error: {
26
- name: 'SENDER_REQUIRED',
27
- message: 'SMS requires a from, TWILIO_SMS_FROM not set',
28
- },
29
- };
30
- }
31
-
32
- if (!to) {
33
- return {
34
- success: false,
35
- error: {
36
- name: 'RECIPIENT_REQUIRED',
37
- message: 'SMS requires a to',
38
- },
39
- };
40
- }
20
+ type: 'TWILIO',
41
21
 
22
+ doWork: async ({ from, to, text, ...params }) => {
42
23
  try {
43
24
  const url = `https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Messages.json`;
44
25
  const response = await fetch(url, {
@@ -51,6 +32,7 @@ const SmsWorkerPlugin: IWorkerAdapter<
51
32
  Body: text || '',
52
33
  From: from || TWILIO_SMS_FROM,
53
34
  To: to,
35
+ ...params, // Include any additional parameters passed
54
36
  }),
55
37
  });
56
38