unismsgateway 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +143 -52
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -13
- package/dist/lib/lib.d.ts +5 -10
- package/dist/lib/lib.js +20 -23
- package/dist/lib/nest-gateway.d.ts +12 -0
- package/dist/lib/nest-gateway.js +145 -0
- package/dist/lib/platform.d.ts +13 -51
- package/dist/lib/platform.js +85 -93
- package/dist/lib/types.d.ts +44 -0
- package/dist/lib/types.js +2 -0
- package/package.json +28 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RazakAlpha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
# Unified Sms Gateway
|
|
3
2
|
|
|
4
3
|
Most of the time a single project relies on multiple sms Gateway so it can switched if one goes off.
|
|
@@ -10,84 +9,176 @@ which means you only does one implementation in it works for all supported sms g
|
|
|
10
9
|
you just have select or switch your sms platform and your code still works fine like nothing has changed
|
|
11
10
|
|
|
12
11
|
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install unismsgateway
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Supported Gateways
|
|
19
|
+
|
|
20
|
+
| Platform ID | Provider | Required Params |
|
|
21
|
+
|-------------|----------|-----------------|
|
|
22
|
+
| `route` | routeMobile | username, password, host |
|
|
23
|
+
| `hubtel` | Hubtel SMS (Ghana) | clientId, clientSecret |
|
|
24
|
+
| `nest` | SMSOnlineGH / smsonlinegh | apiKey |
|
|
25
|
+
|
|
13
26
|
## Usage/Examples
|
|
14
27
|
|
|
28
|
+
### Initialize with Platform
|
|
29
|
+
|
|
15
30
|
```javascript
|
|
16
31
|
const unisms = require('unismsgateway')
|
|
17
32
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
// For routeMobile
|
|
34
|
+
const routeGateway = unisms.init({
|
|
35
|
+
platformId: 'route',
|
|
36
|
+
param: {
|
|
37
|
+
username: 'your-username',
|
|
38
|
+
password: 'your-password',
|
|
39
|
+
host: 'rslr.connectbind.com',
|
|
40
|
+
protocol: 'http',
|
|
41
|
+
port: 8080
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// For Hubtel
|
|
46
|
+
const hubtelGateway = unisms.init({
|
|
47
|
+
platformId: 'hubtel',
|
|
48
|
+
param: {
|
|
49
|
+
clientId: 'your-client-id',
|
|
50
|
+
clientSecret: 'your-client-secret'
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// For SMSOnlineGH (nest)
|
|
55
|
+
const nestGateway = unisms.init({
|
|
56
|
+
platformId: 'nest',
|
|
57
|
+
param: {
|
|
58
|
+
apiKey: 'your-api-key',
|
|
59
|
+
// Optional: host, protocol (defaults to api.smsonlinegh.com, https)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Send SMS Message
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
const unisms = require('unismsgateway')
|
|
24
68
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
69
|
+
// Initialize gateway
|
|
70
|
+
const gateway = unisms.init({
|
|
71
|
+
platformId: 'nest',
|
|
72
|
+
param: {
|
|
73
|
+
apiKey: 'your-api-key'
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
// Send message
|
|
78
|
+
async function sendSms() {
|
|
79
|
+
try {
|
|
80
|
+
const result = await gateway.quickSend({
|
|
81
|
+
From: 'SenderName',
|
|
82
|
+
To: '233XXXXXXXXX', // recipient number
|
|
83
|
+
Content: 'Hello from unismsgateway!',
|
|
84
|
+
Type: 0 // optional, defaults to 0
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
if (result.success) {
|
|
88
|
+
console.log('Message sent successfully:', result.messageId)
|
|
89
|
+
} else {
|
|
90
|
+
console.error('Failed to send:', result.error)
|
|
91
|
+
}
|
|
92
|
+
} catch (err) {
|
|
93
|
+
console.error('Error:', err)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
28
96
|
|
|
97
|
+
sendSms()
|
|
29
98
|
```
|
|
30
99
|
|
|
31
|
-
###
|
|
32
|
-
```javascript
|
|
100
|
+
### With Callback
|
|
33
101
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
})
|
|
44
|
-
}catch(err){
|
|
45
|
-
console.log(err)
|
|
46
|
-
}
|
|
102
|
+
```javascript
|
|
103
|
+
gateway.quickSend({
|
|
104
|
+
From: 'SenderName',
|
|
105
|
+
To: '233XXXXXXXXX',
|
|
106
|
+
Content: 'Test message'
|
|
107
|
+
}, (response) => {
|
|
108
|
+
console.log('Response:', response)
|
|
109
|
+
})
|
|
110
|
+
```
|
|
47
111
|
|
|
112
|
+
### Check Balance (SMSOnlineGH/nest only)
|
|
48
113
|
|
|
114
|
+
```javascript
|
|
115
|
+
const gateway = unisms.init({
|
|
116
|
+
platformId: 'nest',
|
|
117
|
+
param: { apiKey: 'your-api-key' }
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
// Only available for nest platform
|
|
121
|
+
if (gateway.getGateway) {
|
|
122
|
+
const nestGateway = gateway.getGateway()
|
|
123
|
+
const balance = await nestGateway.getBalance()
|
|
124
|
+
console.log('Balance:', balance)
|
|
49
125
|
}
|
|
50
|
-
|
|
51
126
|
```
|
|
52
127
|
|
|
53
|
-
###
|
|
128
|
+
### Reset Gateway Instance
|
|
129
|
+
|
|
54
130
|
```javascript
|
|
131
|
+
// Clear the current gateway instance
|
|
132
|
+
unisms.reset()
|
|
133
|
+
|
|
134
|
+
// Initialize with new platform
|
|
135
|
+
const newGateway = unisms.init({
|
|
136
|
+
platformId: 'hubtel',
|
|
137
|
+
param: {
|
|
138
|
+
clientId: 'new-client-id',
|
|
139
|
+
clientSecret: 'new-secret'
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
```
|
|
55
143
|
|
|
56
|
-
|
|
57
|
-
try{
|
|
58
|
-
// const gateway = unisms.getSmsPlatform();
|
|
59
|
-
await gateway.sendPersonalized({From:'xxxxx',
|
|
60
|
-
To: {to: 233XXXXXXXXX, values: ['Alpha', 65332]}, // [{to: 233XXXXXXXXX, values: ['Alpha', 65332]}, {to: 211XXXXXXXXX, values: ['James', 2000]}, ]
|
|
61
|
-
Content: 'Testing unisms',
|
|
62
|
-
Type: 0}).then(r => {
|
|
63
|
-
console.log(r)
|
|
64
|
-
}).catch(err => {
|
|
65
|
-
console.log(err)
|
|
66
|
-
})
|
|
67
|
-
}catch(err){
|
|
68
|
-
console.log(err)
|
|
69
|
-
}
|
|
144
|
+
## API Reference
|
|
70
145
|
|
|
146
|
+
### `init(settings: IgatewaySettings): smsPlatform`
|
|
71
147
|
|
|
72
|
-
|
|
148
|
+
Initialize the SMS gateway with your platform configuration.
|
|
73
149
|
|
|
74
|
-
|
|
150
|
+
**Parameters:**
|
|
151
|
+
- `platformId`: `'route'` | `'hubtel'` | `'nest'`
|
|
152
|
+
- `param`: Platform-specific configuration object
|
|
75
153
|
|
|
154
|
+
### `getSmsPlatform(): smsPlatform | null`
|
|
76
155
|
|
|
77
|
-
|
|
156
|
+
Get the current gateway instance. Returns `null` if not initialized.
|
|
78
157
|
|
|
79
|
-
|
|
80
|
-
routeMobile sms (India) using routemobilesms
|
|
81
|
-
Nest SMS(Ghana) using nestsms
|
|
158
|
+
### `reset(): void`
|
|
82
159
|
|
|
83
|
-
|
|
160
|
+
Clear the current gateway instance.
|
|
84
161
|
|
|
85
|
-
|
|
162
|
+
### `quickSend(params: QuickSendParams, callback?: Function): Promise<SendResult>`
|
|
86
163
|
|
|
87
|
-
|
|
164
|
+
Send an SMS message.
|
|
88
165
|
|
|
166
|
+
**Parameters:**
|
|
167
|
+
- `From`: Sender ID/name
|
|
168
|
+
- `To`: Recipient phone number (string or number)
|
|
169
|
+
- `Content`: Message content
|
|
170
|
+
- `Type`: Optional message type (defaults to 0)
|
|
89
171
|
|
|
90
|
-
|
|
172
|
+
**Returns:**
|
|
173
|
+
```typescript
|
|
174
|
+
{
|
|
175
|
+
success: boolean;
|
|
176
|
+
messageId?: string;
|
|
177
|
+
data?: any;
|
|
178
|
+
error?: string;
|
|
179
|
+
}
|
|
180
|
+
```
|
|
91
181
|
|
|
92
|
-
|
|
182
|
+
## License
|
|
93
183
|
|
|
184
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './lib/lib';
|
|
1
|
+
export * from './lib/lib';
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./lib/lib"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./lib/lib"), exports);
|
package/dist/lib/lib.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { smsPlatform, IgatewaySettings,
|
|
2
|
-
export declare function init(settings: IgatewaySettings): smsPlatform;
|
|
3
|
-
export declare function getSmsPlatform(): smsPlatform;
|
|
4
|
-
export declare function
|
|
5
|
-
|
|
6
|
-
To: number;
|
|
7
|
-
Content: string;
|
|
8
|
-
Type?: number;
|
|
9
|
-
}, callback?: Function): any;
|
|
10
|
-
export declare function sendPersonalized(body: IQuickSendPersonalized): any;
|
|
1
|
+
import { smsPlatform, IgatewaySettings, IgatewayParam, PlatformId, QuickSendParams, SendResult, ISmsGateway } from './platform';
|
|
2
|
+
export declare function init(settings: IgatewaySettings): smsPlatform;
|
|
3
|
+
export declare function getSmsPlatform(): smsPlatform | null;
|
|
4
|
+
export declare function reset(): void;
|
|
5
|
+
export { smsPlatform, IgatewaySettings, IgatewayParam, PlatformId, QuickSendParams, SendResult, ISmsGateway };
|
package/dist/lib/lib.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const platform_1 = require("./platform");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return smsplatform.sendPersonalized(body);
|
|
22
|
-
}
|
|
23
|
-
exports.sendPersonalized = sendPersonalized;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.smsPlatform = exports.reset = exports.getSmsPlatform = exports.init = void 0;
|
|
4
|
+
const platform_1 = require("./platform");
|
|
5
|
+
Object.defineProperty(exports, "smsPlatform", { enumerable: true, get: function () { return platform_1.smsPlatform; } });
|
|
6
|
+
let smsPlatformInstance = null;
|
|
7
|
+
function init(settings) {
|
|
8
|
+
smsPlatformInstance = new platform_1.smsPlatform(settings);
|
|
9
|
+
smsPlatformInstance.init();
|
|
10
|
+
return smsPlatformInstance;
|
|
11
|
+
}
|
|
12
|
+
exports.init = init;
|
|
13
|
+
function getSmsPlatform() {
|
|
14
|
+
return smsPlatformInstance;
|
|
15
|
+
}
|
|
16
|
+
exports.getSmsPlatform = getSmsPlatform;
|
|
17
|
+
function reset() {
|
|
18
|
+
smsPlatformInstance = null;
|
|
19
|
+
}
|
|
20
|
+
exports.reset = reset;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ISmsGateway, QuickSendParams, SendResult, NestSmsConfig } from './types';
|
|
2
|
+
export declare class NestSmsGateway implements ISmsGateway {
|
|
3
|
+
private config;
|
|
4
|
+
constructor(config: NestSmsConfig);
|
|
5
|
+
init(): ISmsGateway;
|
|
6
|
+
private makeRequest;
|
|
7
|
+
quickSend(params: QuickSendParams, callback?: Function): Promise<SendResult>;
|
|
8
|
+
getBalance(): Promise<{
|
|
9
|
+
balance: number;
|
|
10
|
+
model: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.NestSmsGateway = void 0;
|
|
32
|
+
const https = __importStar(require("https"));
|
|
33
|
+
const http = __importStar(require("http"));
|
|
34
|
+
const DEFAULT_HOST = 'api.smsonlinegh.com';
|
|
35
|
+
const DEFAULT_PROTOCOL = 'https';
|
|
36
|
+
class NestSmsGateway {
|
|
37
|
+
constructor(config) {
|
|
38
|
+
this.config = {
|
|
39
|
+
host: config.host || DEFAULT_HOST,
|
|
40
|
+
protocol: config.protocol || DEFAULT_PROTOCOL,
|
|
41
|
+
apiKey: config.apiKey
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
init() {
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
makeRequest(endpoint, data) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
var _a;
|
|
51
|
+
const postData = data ? JSON.stringify(data) : '';
|
|
52
|
+
const protocol = this.config.protocol || DEFAULT_PROTOCOL;
|
|
53
|
+
const httpModule = protocol === 'https' ? https : http;
|
|
54
|
+
const defaultPort = protocol === 'https' ? 443 : 80;
|
|
55
|
+
const options = {
|
|
56
|
+
hostname: this.config.host || DEFAULT_HOST,
|
|
57
|
+
port: ((_a = this.config.host) === null || _a === void 0 ? void 0 : _a.includes(':'))
|
|
58
|
+
? parseInt(this.config.host.split(':')[1])
|
|
59
|
+
: defaultPort,
|
|
60
|
+
path: `/v5/${endpoint}`,
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: {
|
|
63
|
+
'Host': this.config.host || DEFAULT_HOST,
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
'Accept': 'application/json',
|
|
66
|
+
'Authorization': `key ${this.config.apiKey}`,
|
|
67
|
+
'Content-Length': Buffer.byteLength(postData)
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const req = httpModule.request(options, (res) => {
|
|
71
|
+
let responseBody = '';
|
|
72
|
+
res.on('data', (chunk) => {
|
|
73
|
+
responseBody += chunk;
|
|
74
|
+
});
|
|
75
|
+
res.on('end', () => {
|
|
76
|
+
try {
|
|
77
|
+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
78
|
+
const parsed = JSON.parse(responseBody);
|
|
79
|
+
resolve(parsed);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
reject(new Error(`HTTP ${res.statusCode}: ${responseBody}`));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
reject(new Error(`Failed to parse response: ${responseBody}`));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
req.on('error', (error) => {
|
|
91
|
+
reject(error);
|
|
92
|
+
});
|
|
93
|
+
req.write(postData);
|
|
94
|
+
req.end();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
quickSend(params, callback) {
|
|
99
|
+
var _a, _b;
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const endpoint = 'message/sms/send';
|
|
102
|
+
const requestBody = {
|
|
103
|
+
from: params.From,
|
|
104
|
+
to: String(params.To),
|
|
105
|
+
content: params.Content,
|
|
106
|
+
type: params.Type || 0
|
|
107
|
+
};
|
|
108
|
+
try {
|
|
109
|
+
const response = yield this.makeRequest(endpoint, requestBody);
|
|
110
|
+
const result = {
|
|
111
|
+
success: ((_a = response.handshake) === null || _a === void 0 ? void 0 : _a.id) === 0,
|
|
112
|
+
data: response.data,
|
|
113
|
+
messageId: (_b = response.data) === null || _b === void 0 ? void 0 : _b.messageId
|
|
114
|
+
};
|
|
115
|
+
if (callback) {
|
|
116
|
+
callback(result);
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
122
|
+
const result = {
|
|
123
|
+
success: false,
|
|
124
|
+
error: errorMessage
|
|
125
|
+
};
|
|
126
|
+
if (callback) {
|
|
127
|
+
callback(result);
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
getBalance() {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const endpoint = 'account/balance';
|
|
137
|
+
const response = yield this.makeRequest(endpoint);
|
|
138
|
+
return {
|
|
139
|
+
balance: ((_a = response.data) === null || _a === void 0 ? void 0 : _a.balance) || 0,
|
|
140
|
+
model: ((_b = response.data) === null || _b === void 0 ? void 0 : _b.model) || 'quantity'
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.NestSmsGateway = NestSmsGateway;
|
package/dist/lib/platform.d.ts
CHANGED
|
@@ -1,51 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
export interface IgatewaySettings {
|
|
15
|
-
platformId: string;
|
|
16
|
-
param: IgatewayParam;
|
|
17
|
-
}
|
|
18
|
-
export interface IgatewayParam {
|
|
19
|
-
host: string;
|
|
20
|
-
port?: number;
|
|
21
|
-
username?: string;
|
|
22
|
-
password?: string;
|
|
23
|
-
clientId?: string;
|
|
24
|
-
clientSecret?: string;
|
|
25
|
-
version: string;
|
|
26
|
-
authModel: AuthModel;
|
|
27
|
-
}
|
|
28
|
-
export interface AuthModel {
|
|
29
|
-
type: AuthTypes;
|
|
30
|
-
username?: string;
|
|
31
|
-
password?: string;
|
|
32
|
-
key?: string;
|
|
33
|
-
}
|
|
34
|
-
export declare enum AuthTypes {
|
|
35
|
-
factor = "factor",
|
|
36
|
-
key = "key"
|
|
37
|
-
}
|
|
38
|
-
export interface IQuickSendPersonalized {
|
|
39
|
-
From: string;
|
|
40
|
-
Content: string;
|
|
41
|
-
Type: MessageTypes;
|
|
42
|
-
To: IPersonalizedDestination | IPersonalizedDestination[];
|
|
43
|
-
}
|
|
44
|
-
export interface IPersonalizedDestination {
|
|
45
|
-
to: number;
|
|
46
|
-
values: (string | number)[];
|
|
47
|
-
}
|
|
48
|
-
export declare enum MessageTypes {
|
|
49
|
-
Text = 0,
|
|
50
|
-
flash = 1
|
|
51
|
-
}
|
|
1
|
+
import { IgatewaySettings, IgatewayParam, ISmsGateway, QuickSendParams, SendResult } from './types';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export declare class smsPlatform implements ISmsGateway {
|
|
4
|
+
private _settings;
|
|
5
|
+
private _gateway;
|
|
6
|
+
constructor(settings: IgatewaySettings);
|
|
7
|
+
private validateSettings;
|
|
8
|
+
private createGateway;
|
|
9
|
+
init(): ISmsGateway;
|
|
10
|
+
quickSend(param: QuickSendParams, callback?: Function): Promise<SendResult>;
|
|
11
|
+
getGateway(): ISmsGateway;
|
|
12
|
+
}
|
|
13
|
+
export { IgatewaySettings, IgatewayParam };
|
package/dist/lib/platform.js
CHANGED
|
@@ -1,93 +1,85 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
AuthTypes["factor"] = "factor";
|
|
87
|
-
AuthTypes["key"] = "key";
|
|
88
|
-
})(AuthTypes = exports.AuthTypes || (exports.AuthTypes = {}));
|
|
89
|
-
var MessageTypes;
|
|
90
|
-
(function (MessageTypes) {
|
|
91
|
-
MessageTypes[MessageTypes["Text"] = 0] = "Text";
|
|
92
|
-
MessageTypes[MessageTypes["flash"] = 1] = "flash";
|
|
93
|
-
})(MessageTypes = exports.MessageTypes || (exports.MessageTypes = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.smsPlatform = void 0;
|
|
14
|
+
const hubtel_sms_extended_1 = require("hubtel-sms-extended");
|
|
15
|
+
const routemobilesms_1 = require("routemobilesms");
|
|
16
|
+
const nest_gateway_1 = require("./nest-gateway");
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
const GATEWAY_CONFIGS = {
|
|
19
|
+
route: { requiresUsernamePassword: true },
|
|
20
|
+
hubtel: { requiresClientCredentials: true },
|
|
21
|
+
nest: { requiresApiKey: true }
|
|
22
|
+
};
|
|
23
|
+
class smsPlatform {
|
|
24
|
+
constructor(settings) {
|
|
25
|
+
this.validateSettings(settings);
|
|
26
|
+
this._settings = settings;
|
|
27
|
+
this._gateway = this.createGateway();
|
|
28
|
+
}
|
|
29
|
+
validateSettings(settings) {
|
|
30
|
+
const validPlatforms = ['route', 'hubtel', 'nest'];
|
|
31
|
+
if (!validPlatforms.includes(settings.platformId)) {
|
|
32
|
+
throw new Error(`Invalid platform ID. Supported platforms: ${validPlatforms.join(', ')}`);
|
|
33
|
+
}
|
|
34
|
+
const config = GATEWAY_CONFIGS[settings.platformId];
|
|
35
|
+
const param = settings.param;
|
|
36
|
+
if (config.requiresApiKey && !param.apiKey) {
|
|
37
|
+
throw new Error(`Platform '${settings.platformId}' requires 'apiKey' in param`);
|
|
38
|
+
}
|
|
39
|
+
if (config.requiresClientCredentials && (!param.clientId || !param.clientSecret)) {
|
|
40
|
+
throw new Error(`Platform '${settings.platformId}' requires 'clientId' and 'clientSecret' in param`);
|
|
41
|
+
}
|
|
42
|
+
if (config.requiresUsernamePassword && (!param.username || !param.password)) {
|
|
43
|
+
throw new Error(`Platform '${settings.platformId}' requires 'username' and 'password' in param`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
createGateway() {
|
|
47
|
+
const { platformId, param } = this._settings;
|
|
48
|
+
switch (platformId) {
|
|
49
|
+
case 'route':
|
|
50
|
+
return new routemobilesms_1.routeSms({
|
|
51
|
+
host: param.host || 'rslr.connectbind.com',
|
|
52
|
+
username: param.username,
|
|
53
|
+
password: param.password,
|
|
54
|
+
protocol: param.protocol || 'http',
|
|
55
|
+
port: param.port || 8080
|
|
56
|
+
});
|
|
57
|
+
case 'hubtel':
|
|
58
|
+
return new hubtel_sms_extended_1.HubtelSms({
|
|
59
|
+
clientId: param.clientId,
|
|
60
|
+
clientSecret: param.clientSecret
|
|
61
|
+
});
|
|
62
|
+
case 'nest':
|
|
63
|
+
return new nest_gateway_1.NestSmsGateway({
|
|
64
|
+
apiKey: param.apiKey,
|
|
65
|
+
host: param.host,
|
|
66
|
+
protocol: param.protocol
|
|
67
|
+
});
|
|
68
|
+
default:
|
|
69
|
+
throw new Error(`Unsupported platform: ${platformId}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
init() {
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
quickSend(param, callback) {
|
|
76
|
+
if (!this._gateway) {
|
|
77
|
+
throw new Error('Gateway not initialized. Call init() first.');
|
|
78
|
+
}
|
|
79
|
+
return this._gateway.quickSend(param, callback);
|
|
80
|
+
}
|
|
81
|
+
getGateway() {
|
|
82
|
+
return this._gateway;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.smsPlatform = smsPlatform;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare type PlatformId = 'route' | 'hubtel' | 'nest';
|
|
2
|
+
export interface QuickSendParams {
|
|
3
|
+
From: string;
|
|
4
|
+
To: string | number;
|
|
5
|
+
Content: string;
|
|
6
|
+
Type?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface SendResult {
|
|
9
|
+
success: boolean;
|
|
10
|
+
messageId?: string;
|
|
11
|
+
data?: any;
|
|
12
|
+
error?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface IgatewayParam {
|
|
15
|
+
host?: string;
|
|
16
|
+
port?: number;
|
|
17
|
+
username?: string;
|
|
18
|
+
password?: string;
|
|
19
|
+
clientId?: string;
|
|
20
|
+
clientSecret?: string;
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
protocol?: 'http' | 'https';
|
|
23
|
+
}
|
|
24
|
+
export interface IgatewaySettings {
|
|
25
|
+
platformId: PlatformId;
|
|
26
|
+
param: IgatewayParam;
|
|
27
|
+
}
|
|
28
|
+
export interface ISmsGateway {
|
|
29
|
+
init(): ISmsGateway;
|
|
30
|
+
quickSend(params: QuickSendParams, callback?: Function): Promise<SendResult>;
|
|
31
|
+
getBalance?(): Promise<any>;
|
|
32
|
+
}
|
|
33
|
+
export interface NestSmsConfig {
|
|
34
|
+
apiKey: string;
|
|
35
|
+
host?: string;
|
|
36
|
+
protocol?: 'http' | 'https';
|
|
37
|
+
}
|
|
38
|
+
export interface NestSendResponse {
|
|
39
|
+
handshake: {
|
|
40
|
+
id: number;
|
|
41
|
+
label: string;
|
|
42
|
+
};
|
|
43
|
+
data?: any;
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,32 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unismsgateway",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "A unified
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "A unified SMS gateway library that brings access to multiple SMS gateways under a single API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "https://github.com/RazakAlpha/unismsgateway"
|
|
10
|
-
},
|
|
11
7
|
"scripts": {
|
|
12
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
9
|
"build": "tsc",
|
|
14
|
-
"prepublish": "npm run build"
|
|
15
|
-
"publish": "git push --tags && npm publish"
|
|
10
|
+
"prepublish": "npm run build"
|
|
16
11
|
},
|
|
17
12
|
"files": [
|
|
18
13
|
"dist/**/*"
|
|
19
14
|
],
|
|
20
|
-
"keywords": [
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
"keywords": [
|
|
16
|
+
"sms",
|
|
17
|
+
"gateway",
|
|
18
|
+
"unified",
|
|
19
|
+
"hubtel",
|
|
20
|
+
"routemobile",
|
|
21
|
+
"smsonlinegh",
|
|
22
|
+
"messaging",
|
|
23
|
+
"sms-api",
|
|
24
|
+
"ghana",
|
|
25
|
+
"telecommunications"
|
|
26
|
+
],
|
|
27
|
+
"author": "RazakAlpha",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/RazakAlpha/unismsgateway.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/RazakAlpha/unismsgateway/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/RazakAlpha/unismsgateway#readme",
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=12.0.0"
|
|
39
|
+
},
|
|
23
40
|
"devDependencies": {
|
|
24
41
|
"@types/node": "^17.0.4",
|
|
25
42
|
"typescript": "^4.5.4"
|
|
26
43
|
},
|
|
27
44
|
"dependencies": {
|
|
28
45
|
"hubtel-sms-extended": "^1.0.2",
|
|
29
|
-
"nestsms": "^1.2.1",
|
|
30
46
|
"routemobilesms": "^1.0.4"
|
|
31
47
|
}
|
|
32
48
|
}
|