├── .babelrc ├── .eslintrc.yml ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── lib ├── contact.js ├── device.js ├── index.js └── message.js ├── package.json └── src ├── contact.js ├── device.js ├── index.js └── message.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | env: 2 | node: true 3 | es6: true 4 | extends: 'eslint:recommended' 5 | parserOptions: 6 | sourceType: module 7 | rules: 8 | accessor-pairs: error 9 | array-bracket-spacing: error 10 | array-callback-return: error 11 | arrow-body-style: 'off' 12 | arrow-parens: error 13 | arrow-spacing: 14 | - error 15 | - after: true 16 | before: true 17 | block-scoped-var: error 18 | block-spacing: error 19 | brace-style: error 20 | callback-return: error 21 | camelcase: 22 | - error 23 | - properties: never 24 | class-methods-use-this: error 25 | comma-dangle: 26 | - error 27 | - always-multiline 28 | comma-spacing: 29 | - error 30 | - after: true 31 | before: false 32 | comma-style: 33 | - error 34 | - last 35 | complexity: error 36 | computed-property-spacing: error 37 | consistent-return: error 38 | consistent-this: error 39 | curly: error 40 | default-case: error 41 | dot-location: error 42 | dot-notation: error 43 | eol-last: error 44 | eqeqeq: error 45 | func-call-spacing: error 46 | func-names: error 47 | func-style: error 48 | generator-star-spacing: error 49 | global-require: 'off' 50 | guard-for-in: error 51 | handle-callback-err: error 52 | id-blacklist: error 53 | id-length: error 54 | id-match: error 55 | indent: 'off' 56 | init-declarations: error 57 | jsx-quotes: error 58 | key-spacing: error 59 | keyword-spacing: error 60 | linebreak-style: 61 | - error 62 | - unix 63 | lines-around-comment: error 64 | max-depth: error 65 | max-len: error 66 | max-lines: error 67 | max-nested-callbacks: error 68 | max-params: 'off' 69 | max-statements: error 70 | max-statements-per-line: error 71 | multiline-ternary: error 72 | new-cap: error 73 | new-parens: error 74 | newline-after-var: 'off' 75 | newline-before-return: 'off' 76 | newline-per-chained-call: error 77 | no-alert: error 78 | no-array-constructor: error 79 | no-bitwise: error 80 | no-caller: error 81 | no-catch-shadow: error 82 | no-confusing-arrow: error 83 | no-continue: error 84 | no-div-regex: error 85 | no-duplicate-imports: error 86 | no-else-return: error 87 | no-empty-function: error 88 | no-eq-null: error 89 | no-eval: error 90 | no-extend-native: error 91 | no-extra-bind: error 92 | no-extra-label: error 93 | no-extra-parens: error 94 | no-floating-decimal: error 95 | no-global-assign: error 96 | no-implicit-coercion: error 97 | no-implicit-globals: error 98 | no-implied-eval: error 99 | no-inline-comments: error 100 | no-invalid-this: error 101 | no-iterator: error 102 | no-label-var: error 103 | no-labels: error 104 | no-lone-blocks: error 105 | no-lonely-if: error 106 | no-loop-func: error 107 | no-magic-numbers: 108 | - error 109 | - ignoreArrayIndexes: true 110 | no-mixed-operators: error 111 | no-mixed-requires: error 112 | no-multi-spaces: error 113 | no-multi-str: error 114 | no-multiple-empty-lines: error 115 | no-negated-condition: error 116 | no-nested-ternary: error 117 | no-new: error 118 | no-new-func: error 119 | no-new-object: error 120 | no-new-require: error 121 | no-new-wrappers: error 122 | no-octal-escape: error 123 | no-param-reassign: error 124 | no-path-concat: error 125 | no-plusplus: error 126 | no-process-env: error 127 | no-process-exit: error 128 | no-proto: error 129 | no-prototype-builtins: error 130 | no-restricted-globals: error 131 | no-restricted-imports: error 132 | no-restricted-modules: error 133 | no-restricted-syntax: error 134 | no-return-assign: error 135 | no-script-url: error 136 | no-self-compare: error 137 | no-sequences: error 138 | no-shadow: error 139 | no-shadow-restricted-names: error 140 | no-spaced-func: error 141 | no-sync: error 142 | no-tabs: error 143 | no-template-curly-in-string: error 144 | no-ternary: error 145 | no-throw-literal: error 146 | no-trailing-spaces: error 147 | no-undef-init: error 148 | no-undefined: error 149 | no-underscore-dangle: error 150 | no-unmodified-loop-condition: error 151 | no-unneeded-ternary: error 152 | no-unsafe-negation: error 153 | no-unused-expressions: error 154 | no-use-before-define: error 155 | no-useless-call: error 156 | no-useless-computed-key: error 157 | no-useless-concat: error 158 | no-useless-constructor: error 159 | no-useless-escape: error 160 | no-useless-rename: error 161 | no-var: 'off' 162 | no-void: error 163 | no-warning-comments: error 164 | no-whitespace-before-property: error 165 | no-with: error 166 | object-curly-newline: 'off' 167 | object-curly-spacing: error 168 | object-property-newline: error 169 | object-shorthand: 'off' 170 | one-var: error 171 | one-var-declaration-per-line: error 172 | operator-assignment: error 173 | operator-linebreak: error 174 | padded-blocks: 'off' 175 | prefer-arrow-callback: error 176 | prefer-const: 'off' 177 | prefer-reflect: error 178 | prefer-rest-params: error 179 | prefer-spread: error 180 | prefer-template: 'off' 181 | quote-props: 'off' 182 | quotes: 183 | - error 184 | - single 185 | radix: error 186 | require-jsdoc: error 187 | rest-spread-spacing: error 188 | semi: 'off' 189 | semi-spacing: error 190 | sort-imports: error 191 | sort-keys: 'off' 192 | sort-vars: error 193 | space-before-blocks: error 194 | space-before-function-paren: error 195 | space-in-parens: 196 | - error 197 | - never 198 | space-infix-ops: error 199 | space-unary-ops: error 200 | spaced-comment: error 201 | strict: error 202 | symbol-description: error 203 | template-curly-spacing: error 204 | unicode-bom: 205 | - error 206 | - never 207 | valid-jsdoc: error 208 | vars-on-top: error 209 | wrap-iife: error 210 | wrap-regex: error 211 | yield-star-spacing: error 212 | yoda: error 213 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Dependency directories 7 | node_modules 8 | 9 | # npm cache directory 10 | .npm 11 | 12 | # Output directory 13 | lib 14 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .eslintrc.yml 2 | .gitignore 3 | .npmignore 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "6.1" 5 | 6 | cache: 7 | directories: 8 | - node_modules 9 | 10 | git: 11 | depth: 3 12 | 13 | branches: 14 | only: 15 | - master 16 | 17 | install: 18 | - npm install 19 | 20 | script: 21 | - npm test 22 | - npm run lint 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Nicolas Trinquier 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sms-gateway-nodejs 2 | 3 | [![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php) 4 | [![Build Status](https://travis-ci.org/ntrinquier/sms-gateway-nodejs.svg?branch=master)](https://travis-ci.org/ntrinquier/sms-gateway-nodejs) 5 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d381f7a23ced40a48f647fb3ca1e6d1e)](https://www.codacy.com/app/trinquier-nico/sms-gateway-nodejs?utm_source=github.com&utm_medium=referral&utm_content=ntrinquier/sms-gateway-nodejs&utm_campaign=Badge_Grade) 6 | [![Issuestats](http://issuestats.com/github/ntrinquier/sms-gateway-nodejs/badge/pr?style=flat)](http://issuestats.com/github/ntrinquier/sms-gateway-nodejs) 7 | [![Issuestats](http://issuestats.com/github/ntrinquier/sms-gateway-nodejs/badge/issue?style=flat)](http://issuestats.com/github/ntrinquier/sms-gateway-nodejs) 8 | 9 | A library to interact with [SMS Gateway](https://smsgateway.me/) API. 10 | 11 | ## Installation 12 | 13 | ``` 14 | npm install --save sms-gateway-nodejs 15 | ``` 16 | 17 | # Documentation 18 | 19 | ## `Initialization` 20 | 21 | 22 | 23 | #### Arguments 24 | 1. `emailAddress` *(String)*: Your smsgateway username 25 | 2. `password` *(String)*: Your smsgateway password 26 | 27 | #### Example 28 | ```js 29 | smsGateway = require('sms-gateway-nodejs')('ntrinquier@provider.com', 'p4ssw0rd') 30 | ``` 31 | 32 | 33 | 34 | 35 | 36 | ## `Contact` 37 | 38 | * `createContact` 39 | * `listOfContacts` 40 | * `fetchSingleContact` 41 | 42 | 43 | 44 | 45 | 46 | ## `Device` 47 | 48 | * `listOfDevices` 49 | * `fetchSingleDevice` 50 | 51 | 52 | 53 | 54 | 55 | ## `Messages` 56 | 57 | * `listOfMessages` 58 | * `fetchSingleMessage` 59 | * `sendMessageToNumber` 60 | * `sendMessageToNumbers` 61 | * `sendMessageToContact` 62 | * `sendMessageToContacts` 63 | * `sendMessagesToRecipients` 64 | 65 | 66 | 67 | ## `“Contacts” Methods` 68 | 69 | 70 | 71 | ### `createContact(page)` 72 | 73 | Create a contact. 74 | 75 | #### Arguments 76 | 1. `name` *(String)*: The contact's name 77 | 1. `number` *(String)*: The contact's number 78 | 79 | #### Example 80 | ```js 81 | smsGateway.contact.createContact('Nicolas', '+33612121212') 82 | .then((response) => { 83 | // do something with response 84 | }) 85 | .catch((error) => { 86 | // handle error 87 | }) 88 | ``` 89 | 90 | 91 | 92 | 93 | 94 | ### `listOfContacts(page)` 95 | 96 | Get a list of the contacts. 97 | 98 | #### Arguments 99 | 1. `page` *(String)*: The page number 100 | 101 | #### Example 102 | ```js 103 | smsGateway.contact.listOfContacts(2) 104 | .then((response) => { 105 | // do something with response 106 | }) 107 | .catch((error) => { 108 | // handle error 109 | }) 110 | ``` 111 | 112 | 113 | 114 | 115 | 116 | ### `fetchSingleContact(id)` 117 | 118 | Get a specific contact. 119 | 120 | #### Arguments 121 | 1. `id` *(String)*: The contact ID 122 | 123 | #### Example 124 | ```js 125 | smsGateway.contact.fetchSingleContact(2182) 126 | .then((response) => { 127 | // do something with response 128 | }) 129 | .catch((error) => { 130 | // handle error 131 | }) 132 | ``` 133 | 134 | 135 | 136 | ## `“Devices” Methods` 137 | 138 | 139 | 140 | ### `listOfDevices(page)` 141 | 142 | Get a list of the devices. 143 | 144 | #### Arguments 145 | 1. `page` *(String)*: The page number 146 | 147 | #### Example 148 | ```js 149 | smsGateway.device.listOfDevices(2) 150 | .then((response) => { 151 | // do something with response 152 | }) 153 | .catch((error) => { 154 | // handle error 155 | }) 156 | ``` 157 | 158 | 159 | 160 | 161 | 162 | ### `fetchSingleDevice(id)` 163 | 164 | Get a specific device. 165 | 166 | #### Arguments 167 | 1. `id` *(String)*: The device ID 168 | 169 | #### Example 170 | ```js 171 | smsGateway.device.fetchSingleDevice(2182) 172 | .then((response) => { 173 | // do something with response 174 | }) 175 | .catch((error) => { 176 | // handle error 177 | }) 178 | ``` 179 | 180 | 181 | 182 | ## `“Messages” Methods` 183 | 184 | 185 | 186 | ### `listOfMessages(page)` 187 | 188 | Get a list of the messages. 189 | 190 | #### Arguments 191 | 1. `page` *(String)*: The page number 192 | 193 | #### Example 194 | ```js 195 | smsGateway.message.listOfMessages(2) 196 | .then((response) => { 197 | // do something with response 198 | }) 199 | .catch((error) => { 200 | // handle error 201 | }) 202 | ``` 203 | 204 | 205 | 206 | 207 | 208 | ### `fetchSingleMessage(id)` 209 | 210 | Get a specific message. 211 | 212 | #### Arguments 213 | 1. `id` *(String)*: The message ID 214 | 215 | #### Example 216 | ```js 217 | smsGateway.message.fetchSingleMessage(2182) 218 | .then((response) => { 219 | // do something with response 220 | }) 221 | .catch((error) => { 222 | // handle error 223 | }) 224 | ``` 225 | 226 | 227 | 228 | 229 | 230 | ### `sendMessageToNumber(device, number, message, [sendAt], [expiresAt])` 231 | 232 | Send a message to a number. 233 | 234 | #### Arguments 235 | 1. `device` *(String)*: The ID of device you wish to send the message from 236 | 2. `number` *(String)*: The number to send the message to 237 | 3. `message` *(String)*: The content of the message to be sent 238 | 4. `[sendAt=undefined]` *(String)*: Time to send the message in Unix Time format 239 | 5. `[expiresAt=undefined]` *(String)*: Time to give up trying to send the message at in Unix Time format 240 | 241 | #### Example 242 | ```js 243 | smsGateway.message.sendMessageToNumber('2012', '+33123456789', 'Hello world :)') 244 | .then((response) => { 245 | // do something with response 246 | }) 247 | .catch((error) => { 248 | // handle error 249 | }) 250 | ``` 251 | 252 | 253 | 254 | 255 | 256 | ### `sendMessageToNumbers(device, numbers, message, [sendAt], [expiresAt])` 257 | 258 | Send a message to numbers. 259 | 260 | #### Arguments 261 | 1. `device` *(String)*: The ID of device you wish to send the message from 262 | 2. `numbers` *(Array)*: The numbers to send the message to 263 | 3. `message` *(String)*: The content of the message to be sent 264 | 4. `[sendAt=undefined]` *(String)*: Time to send the message in Unix Time format 265 | 5. `[expiresAt=undefined]` *(String)*: Time to give up trying to send the message at in Unix Time format 266 | 267 | #### Example 268 | ```js 269 | smsGateway.message.sendMessageToNumbers('2012', ['+33123456789', '+33987654321'], 'Penguins rock!') 270 | .then((response) => { 271 | // do something with response 272 | }) 273 | .catch((error) => { 274 | // handle error 275 | }) 276 | ``` 277 | 278 | 279 | 280 | 281 | 282 | ### `sendMessageToContact(device, contact, message, [sendAt], [expiresAt])` 283 | 284 | Send a message to a contact. 285 | 286 | #### Arguments 287 | 1. `device` *(String)*: The ID of device you wish to send the message from 288 | 2. `contact` *(String)*: The contact to send the message to 289 | 3. `message` *(String)*: The content of the message to be sent 290 | 4. `[sendAt=undefined]` *(String)*: Time to send the message in Unix Time format 291 | 5. `[expiresAt=undefined]` *(String)*: Time to give up trying to send the message at in Unix Time format 292 | 293 | #### Example 294 | ```js 295 | smsGateway.message.sendMessageToContact('2012', '30', 'Hello world :)') 296 | .then((response) => { 297 | // do something with response 298 | }) 299 | .catch((error) => { 300 | // handle error 301 | }) 302 | ``` 303 | 304 | 305 | 306 | 307 | 308 | ### `sendMessageToContacts(device, contacts, message, [sendAt], [expiresAt])` 309 | 310 | Send a message to contacts. 311 | 312 | #### Arguments 313 | 1. `device` *(String)*: The ID of device you wish to send the message from 314 | 2. `contacts` *(Array)*: The contacts to send the message to 315 | 3. `message` *(String)*: The content of the message to be sent 316 | 4. `[sendAt=undefined]` *(String)*: Time to send the message in Unix Time format 317 | 5. `[expiresAt=undefined]` *(String)*: Time to give up trying to send the message at in Unix Time format 318 | 319 | #### Example 320 | ```js 321 | smsGateway.message.sendMessageToContacts('2012', ['5', '30'], 'Penguins rock!') 322 | .then((response) => { 323 | // do something with response 324 | }) 325 | .catch((error) => { 326 | // handle error 327 | }) 328 | ``` 329 | 330 | 331 | 332 | 333 | 334 | ### `sendMessagesToRecipients(data)` 335 | 336 | Send messages to numbers or contacts. 337 | 338 | #### Arguments 339 | 1. `data` *(Array)*: Objects containing the messages to send, at the following format: 340 | 1. `device` *(String)*: The ID of device you wish to send the message from 341 | 2. `contact|number` *(String)*: The contact or number to send the message to 342 | 3. `message` *(String)*: The content of the message to be sent 343 | 4. `[sendAt=undefined]` *(String)*: Time to send the message in Unix Time format 344 | 5. `[expiresAt=undefined]` *(String)*: Time to give up trying to send the message at in Unix Time format 345 | 346 | #### Example 347 | ```js 348 | smsGateway.message.sendMessagesToRecipients([{ 349 | device: '2190', 350 | contact: '42', 351 | message: 'Hi!', 352 | }, { 353 | device: '2109', 354 | number: '+33123456789', 355 | message: 'Hello!', 356 | }]) 357 | .then((response) => { 358 | // do something with response 359 | }) 360 | .catch((error) => { 361 | // handle error 362 | }) 363 | ``` 364 | 365 | 366 | -------------------------------------------------------------------------------- /lib/contact.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var request = require('request'); 4 | 5 | module.exports = function (email, password) { 6 | var endPointPrefix = 'https://smsgateway.me/api/v3/contacts'; 7 | return { 8 | createContact: function createContact(name, number) { 9 | return new Promise(function (resolve, reject) { 10 | request({ 11 | method: 'POST', 12 | uri: "".concat(endPointPrefix, "/create"), 13 | json: true, 14 | qs: { 15 | email: email, 16 | password: password, 17 | name: name, 18 | number: number 19 | } 20 | }, function (error, response, body) { 21 | if (error) { 22 | reject(error); 23 | } else if (body.success) { 24 | resolve(body.result); 25 | } else { 26 | reject(body.errors); 27 | } 28 | }); 29 | }); 30 | }, 31 | listOfContacts: function listOfContacts(page) { 32 | return new Promise(function (resolve, reject) { 33 | request({ 34 | method: 'GET', 35 | uri: "".concat(endPointPrefix, "/"), 36 | json: true, 37 | qs: { 38 | email: email, 39 | password: password, 40 | page: page 41 | } 42 | }, function (error, response, body) { 43 | if (error) { 44 | reject(error); 45 | } else if (body.result) { 46 | resolve(body.result); 47 | } else { 48 | reject('Could not retrieve contacts.'); 49 | } 50 | }); 51 | }); 52 | }, 53 | fetchSingleContact: function fetchSingleContact(id) { 54 | return new Promise(function (resolve, reject) { 55 | request({ 56 | method: 'GET', 57 | uri: "".concat(endPointPrefix, "/view/").concat(id), 58 | json: true, 59 | qs: { 60 | email: email, 61 | password: password 62 | } 63 | }, function (error, response, body) { 64 | if (error) { 65 | reject(error); 66 | } else if (body.success) { 67 | resolve(body.result); 68 | } else { 69 | reject(body.errors); 70 | } 71 | }); 72 | }); 73 | } 74 | }; 75 | }; -------------------------------------------------------------------------------- /lib/device.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var request = require('request'); 4 | 5 | module.exports = function (email, password) { 6 | var endPointPrefix = 'https://smsgateway.me/api/v3/devices'; 7 | return { 8 | listOfDevices: function listOfDevices(page) { 9 | return new Promise(function (resolve, reject) { 10 | request({ 11 | method: 'GET', 12 | uri: "".concat(endPointPrefix, "/"), 13 | json: true, 14 | qs: { 15 | email: email, 16 | password: password, 17 | page: page 18 | } 19 | }, function (error, response, body) { 20 | if (error) { 21 | reject(error); 22 | } else if (body.result) { 23 | resolve(body.result); 24 | } else { 25 | reject('Could not retrieve devices.'); 26 | } 27 | }); 28 | }); 29 | }, 30 | fetchSingleDevice: function fetchSingleDevice(id) { 31 | return new Promise(function (resolve, reject) { 32 | request({ 33 | method: 'GET', 34 | uri: "".concat(endPointPrefix, "/view/").concat(id), 35 | json: true, 36 | qs: { 37 | email: email, 38 | password: password 39 | } 40 | }, function (error, response, body) { 41 | if (error) { 42 | reject(error); 43 | } else if (body.success) { 44 | resolve(body.result); 45 | } else { 46 | reject(body.errors); 47 | } 48 | }); 49 | }); 50 | } 51 | }; 52 | }; -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = function (emailAddress, password) { 4 | return { 5 | contact: require('./contact')(emailAddress, password), 6 | device: require('./device')(emailAddress, password), 7 | message: require('./message')(emailAddress, password) 8 | }; 9 | }; -------------------------------------------------------------------------------- /lib/message.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var request = require('request'); 4 | 5 | module.exports = function (email, password) { 6 | var endPointPrefix = 'https://smsgateway.me/api/v3/messages'; 7 | return { 8 | listOfMessages: function listOfMessages(page) { 9 | return new Promise(function (resolve, reject) { 10 | request({ 11 | method: 'GET', 12 | uri: "".concat(endPointPrefix, "/"), 13 | json: true, 14 | qs: { 15 | email: email, 16 | password: password, 17 | page: page 18 | } 19 | }, function (error, response, body) { 20 | if (error) { 21 | reject(error); 22 | } else if (body.result) { 23 | resolve(body.result); 24 | } else { 25 | reject('Could not retrieve messages.'); 26 | } 27 | }); 28 | }); 29 | }, 30 | fetchSingleMessage: function fetchSingleMessage(id) { 31 | return new Promise(function (resolve, reject) { 32 | request({ 33 | method: 'GET', 34 | uri: "".concat(endPointPrefix, "/view/").concat(id), 35 | json: true, 36 | qs: { 37 | email: email, 38 | password: password 39 | } 40 | }, function (error, response, body) { 41 | if (error) { 42 | reject(error); 43 | } else if (body.success) { 44 | resolve(body.result); 45 | } else { 46 | reject(body.errors); 47 | } 48 | }); 49 | }); 50 | }, 51 | sendMessageToNumber: function sendMessageToNumber(device, number, message, sendAt, expiresAt) { 52 | return new Promise(function (resolve, reject) { 53 | request({ 54 | method: 'POST', 55 | uri: "".concat(endPointPrefix, "/send"), 56 | json: true, 57 | qs: { 58 | email: email, 59 | password: password, 60 | device: device, 61 | number: number, 62 | message: message, 63 | send_at: sendAt, 64 | expires_at: expiresAt 65 | } 66 | }, function (error, response, body) { 67 | if (error) { 68 | reject(error); 69 | } else if (body.result.success.length) { 70 | resolve(body.result.success[0]); 71 | } else if (body.result.fails.length) { 72 | reject(body.result.fails); 73 | } else { 74 | reject('Could not send message.'); 75 | } 76 | }); 77 | }); 78 | }, 79 | sendMessageToNumbers: function sendMessageToNumbers(device, number, message, sendAt, expiresAt) { 80 | return new Promise(function (resolve, reject) { 81 | request({ 82 | method: 'POST', 83 | uri: "".concat(endPointPrefix, "/send"), 84 | json: true, 85 | qs: { 86 | email: email, 87 | password: password, 88 | device: device, 89 | number: number, 90 | message: message, 91 | send_at: sendAt, 92 | expires_at: expiresAt 93 | } 94 | }, function (error, response, body) { 95 | if (error) { 96 | reject(error); 97 | } else if (body.result.success.length) { 98 | resolve(body.result.success[0]); 99 | } else if (body.result.fails.length) { 100 | reject(body.result.fails); 101 | } else { 102 | reject('Could not send message.'); 103 | } 104 | }); 105 | }); 106 | }, 107 | sendMessageToContact: function sendMessageToContact(device, contact, message, sendAt, expiresAt) { 108 | return new Promise(function (resolve, reject) { 109 | request({ 110 | method: 'POST', 111 | uri: "".concat(endPointPrefix, "/send"), 112 | json: true, 113 | qs: { 114 | email: email, 115 | password: password, 116 | device: device, 117 | contact: contact, 118 | message: message, 119 | send_at: sendAt, 120 | expires_at: expiresAt 121 | } 122 | }, function (error, response, body) { 123 | if (error) { 124 | reject(error); 125 | } else if (body.result.success.length) { 126 | resolve(body.result.success[0]); 127 | } else if (body.result.fails.length) { 128 | reject(body.result.fails); 129 | } else { 130 | reject('Could not send message.'); 131 | } 132 | }); 133 | }); 134 | }, 135 | sendMessageToContacts: function sendMessageToContacts(device, contact, message, sendAt, expiresAt) { 136 | return new Promise(function (resolve, reject) { 137 | request({ 138 | method: 'POST', 139 | uri: "".concat(endPointPrefix, "/send"), 140 | json: true, 141 | qs: { 142 | email: email, 143 | password: password, 144 | device: device, 145 | contact: contact, 146 | message: message, 147 | send_at: sendAt, 148 | expires_at: expiresAt 149 | } 150 | }, function (error, response, body) { 151 | if (error) { 152 | reject(error); 153 | } else if (body.result.success.length) { 154 | resolve(body.result.success[0]); 155 | } else if (body.result.fails.length) { 156 | reject(body.result.fails); 157 | } else { 158 | reject('Could not send message.'); 159 | } 160 | }); 161 | }); 162 | }, 163 | sendMessagesToRecipients: function sendMessagesToRecipients(data) { 164 | return new Promise(function (resolve, reject) { 165 | request({ 166 | method: 'POST', 167 | uri: "".concat(endPointPrefix, "/send"), 168 | json: true, 169 | form: data 170 | }, function (error, response, body) { 171 | if (error) { 172 | reject(error); 173 | } else if (body.result.success.length) { 174 | resolve(body.result.success[0]); 175 | } else if (body.result.fails.length) { 176 | reject(body.result.fails); 177 | } else { 178 | reject('Could not send message.'); 179 | } 180 | }); 181 | }); 182 | } 183 | }; 184 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sms-gateway-nodejs", 3 | "version": "1.0.1", 4 | "description": "A library to interact with SMS Gateway API.", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "lint": "./node_modules/.bin/eslint src", 8 | "test": "echo \"No test specified yet\" && exit 0", 9 | "prebuild": "yarn install", 10 | "build": "rm -rf lib/* && ./node_modules/.bin/babel src/ -d lib/", 11 | "preversion": "yarn test && yarn lint", 12 | "version": "yarn build && git add -A -f ./lib", 13 | "postversion": "git push && git push --tags" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/ntrinquier/sms-gateway-nodejs.git" 18 | }, 19 | "author": "ntrinquier ", 20 | "license": { 21 | "type": "MIT", 22 | "url": "https://github.com/ntrinquier/sms-gateway-nodejs/blob/master/LICENSE" 23 | }, 24 | "bugs": { 25 | "url": "https://github.com/ntrinquier/sms-gateway-nodejs/issues" 26 | }, 27 | "homepage": "https://github.com/ntrinquier/sms-gateway-nodejs#readme", 28 | "devDependencies": { 29 | "@babel/cli": "^7.0.0", 30 | "@babel/core": "^7.0.0-0", 31 | "@babel/preset-env": "^7.0.0", 32 | "eslint": "^5.0.0" 33 | }, 34 | "dependencies": { 35 | "request": "^2.0.0" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/contact.js: -------------------------------------------------------------------------------- 1 | const request = require('request'); 2 | 3 | module.exports = (email, password) => { 4 | const endPointPrefix = 'https://smsgateway.me/api/v3/contacts' 5 | 6 | return { 7 | createContact: (name, number) => { 8 | return new Promise((resolve, reject) => { 9 | request({ 10 | method: 'POST', 11 | mode: 'no-cors', 12 | uri: `${endPointPrefix}/create`, 13 | json: true, 14 | qs: { 15 | email, 16 | password, 17 | name, 18 | number, 19 | }, 20 | }, (error, response, body) => { 21 | if (error) { 22 | reject(error) 23 | } else if (body.success) { 24 | resolve(body.result) 25 | } else { 26 | reject(body.errors) 27 | } 28 | }) 29 | }) 30 | }, 31 | listOfContacts: (page) => { 32 | return new Promise((resolve, reject) => { 33 | request({ 34 | method: 'GET', 35 | mode: 'no-cors', 36 | uri: `${endPointPrefix}/`, 37 | json: true, 38 | qs: { 39 | email, 40 | password, 41 | page, 42 | }, 43 | }, (error, response, body) => { 44 | if (error) { 45 | reject(error) 46 | } else if (body.result) { 47 | resolve(body.result) 48 | } else { 49 | reject('Could not retrieve contacts.') 50 | } 51 | }) 52 | }) 53 | }, 54 | fetchSingleContact: (id) => { 55 | return new Promise((resolve, reject) => { 56 | request({ 57 | method: 'GET', 58 | mode: 'no-cors', 59 | uri: `${endPointPrefix}/view/${id}`, 60 | json: true, 61 | qs: { 62 | email, 63 | password, 64 | }, 65 | }, (error, response, body) => { 66 | if (error) { 67 | reject(error) 68 | } else if (body.success) { 69 | resolve(body.result) 70 | } else { 71 | reject(body.errors) 72 | } 73 | }) 74 | }) 75 | }, 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/device.js: -------------------------------------------------------------------------------- 1 | const request = require('request'); 2 | 3 | module.exports = (email, password) => { 4 | const endPointPrefix = 'https://smsgateway.me/api/v3/devices' 5 | 6 | return { 7 | listOfDevices: (page) => { 8 | return new Promise((resolve, reject) => { 9 | request({ 10 | method: 'GET', 11 | mode: 'no-cors', 12 | uri: `${endPointPrefix}/`, 13 | json: true, 14 | qs: { 15 | email, 16 | password, 17 | page, 18 | }, 19 | }, (error, response, body) => { 20 | if (error) { 21 | reject(error) 22 | } else if (body.result) { 23 | resolve(body.result) 24 | } else { 25 | reject('Could not retrieve devices.') 26 | } 27 | }) 28 | }) 29 | }, 30 | fetchSingleDevice: (id) => { 31 | return new Promise((resolve, reject) => { 32 | request({ 33 | method: 'GET', 34 | mode: 'no-cors', 35 | uri: `${endPointPrefix}/view/${id}`, 36 | json: true, 37 | qs: { 38 | email, 39 | password, 40 | }, 41 | }, (error, response, body) => { 42 | if (error) { 43 | reject(error) 44 | } else if (body.success) { 45 | resolve(body.result) 46 | } else { 47 | reject(body.errors) 48 | } 49 | }) 50 | }) 51 | }, 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | module.exports = (emailAddress, password) => { 2 | return { 3 | contact: require('./contact')(emailAddress, password), 4 | device: require('./device')(emailAddress, password), 5 | message: require('./message')(emailAddress, password), 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/message.js: -------------------------------------------------------------------------------- 1 | const request = require('request'); 2 | 3 | module.exports = (email, password) => { 4 | const endPointPrefix = 'https://smsgateway.me/api/v3/messages' 5 | 6 | return { 7 | listOfMessages: (page) => { 8 | return new Promise((resolve, reject) => { 9 | request({ 10 | method: 'GET', 11 | mode: 'no-cors', 12 | uri: `${endPointPrefix}/`, 13 | json: true, 14 | qs: { 15 | email, 16 | password, 17 | page, 18 | }, 19 | }, (error, response, body) => { 20 | if (error) { 21 | reject(error) 22 | } else if (body.result) { 23 | resolve(body.result) 24 | } else { 25 | reject('Could not retrieve messages.') 26 | } 27 | }) 28 | }) 29 | }, 30 | fetchSingleMessage: (id) => { 31 | return new Promise((resolve, reject) => { 32 | request({ 33 | method: 'GET', 34 | mode: 'no-cors', 35 | uri: `${endPointPrefix}/view/${id}`, 36 | json: true, 37 | qs: { 38 | email, 39 | password, 40 | }, 41 | }, (error, response, body) => { 42 | if (error) { 43 | reject(error) 44 | } else if (body.success) { 45 | resolve(body.result) 46 | } else { 47 | reject(body.errors) 48 | } 49 | }) 50 | }) 51 | }, 52 | sendMessageToNumber: (device, number, message, sendAt, expiresAt) => { 53 | return new Promise((resolve, reject) => { 54 | request({ 55 | method: 'POST', 56 | mode: 'no-cors', 57 | uri: `${endPointPrefix}/send`, 58 | json: true, 59 | qs: { 60 | email, 61 | password, 62 | device, 63 | number, 64 | message, 65 | send_at: sendAt, 66 | expires_at: expiresAt, 67 | }, 68 | }, (error, response, body) => { 69 | if (error) { 70 | reject(error) 71 | } else if (body.result.success.length) { 72 | resolve(body.result.success[0]) 73 | } else if (body.result.fails.length) { 74 | reject(body.result.fails) 75 | } else { 76 | reject('Could not send message.') 77 | } 78 | }) 79 | }) 80 | }, 81 | sendMessageToNumbers: (device, number, message, sendAt, expiresAt) => { 82 | return new Promise((resolve, reject) => { 83 | request({ 84 | method: 'POST', 85 | mode: 'no-cors', 86 | uri: `${endPointPrefix}/send`, 87 | json: true, 88 | qs: { 89 | email, 90 | password, 91 | device, 92 | number, 93 | message, 94 | send_at: sendAt, 95 | expires_at: expiresAt, 96 | }, 97 | }, (error, response, body) => { 98 | if (error) { 99 | reject(error) 100 | } else if (body.result.success.length) { 101 | resolve(body.result.success[0]) 102 | } else if (body.result.fails.length) { 103 | reject(body.result.fails) 104 | } else { 105 | reject('Could not send message.') 106 | } 107 | }) 108 | }) 109 | }, 110 | sendMessageToContact: (device, contact, message, sendAt, expiresAt) => { 111 | return new Promise((resolve, reject) => { 112 | request({ 113 | method: 'POST', 114 | mode: 'no-cors', 115 | uri: `${endPointPrefix}/send`, 116 | json: true, 117 | qs: { 118 | email, 119 | password, 120 | device, 121 | contact, 122 | message, 123 | send_at: sendAt, 124 | expires_at: expiresAt, 125 | }, 126 | }, (error, response, body) => { 127 | if (error) { 128 | reject(error) 129 | } else if (body.result.success.length) { 130 | resolve(body.result.success[0]) 131 | } else if (body.result.fails.length) { 132 | reject(body.result.fails) 133 | } else { 134 | reject('Could not send message.') 135 | } 136 | }) 137 | }) 138 | }, 139 | sendMessageToContacts: (device, contact, message, sendAt, expiresAt) => { 140 | return new Promise((resolve, reject) => { 141 | request({ 142 | method: 'POST', 143 | mode: 'no-cors', 144 | uri: `${endPointPrefix}/send`, 145 | json: true, 146 | qs: { 147 | email, 148 | password, 149 | device, 150 | contact, 151 | message, 152 | send_at: sendAt, 153 | expires_at: expiresAt, 154 | }, 155 | }, (error, response, body) => { 156 | if (error) { 157 | reject(error) 158 | } else if (body.result.success.length) { 159 | resolve(body.result.success[0]) 160 | } else if (body.result.fails.length) { 161 | reject(body.result.fails) 162 | } else { 163 | reject('Could not send message.') 164 | } 165 | }) 166 | }) 167 | }, 168 | sendMessagesToRecipients: (data) => { 169 | return new Promise((resolve, reject) => { 170 | request({ 171 | method: 'POST', 172 | mode: 'no-cors', 173 | uri: `${endPointPrefix}/send`, 174 | json: true, 175 | form: data, 176 | }, (error, response, body) => { 177 | if (error) { 178 | reject(error) 179 | } else if (body.result.success.length) { 180 | resolve(body.result.success[0]) 181 | } else if (body.result.fails.length) { 182 | reject(body.result.fails) 183 | } else { 184 | reject('Could not send message.') 185 | } 186 | }) 187 | }) 188 | }, 189 | } 190 | } 191 | --------------------------------------------------------------------------------