This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9acdecc
Showing
5 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"extends": "airbnb-base", | ||
"parserOptions": { | ||
"sourceType": "module", | ||
}, | ||
"rules": { | ||
"strict": 0, | ||
"no-param-reassign": [ | ||
"error", | ||
{ "props": false } | ||
], | ||
"func-names": 0, | ||
"comma-dangle": 0, | ||
"prefer-template": 0, | ||
"camelcase": 0, | ||
"no-underscore-dangle": 0, | ||
"consistent-return": 0, | ||
"no-bitwise": ["error", { "allow": ["~"] }] | ||
}, | ||
"globals": { | ||
"describe": true, | ||
"it": true, | ||
"after": true, | ||
"afterEach": true, | ||
"before": true, | ||
"beforeEach": true, | ||
"should": true | ||
}, | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
output.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# movile-messaging | ||
|
||
Node.js wrapper for [Movile's SMS Messaging API](http://doc-messaging.movile.com/sms-v1.html). | ||
You will need your own `UserName` and `AuthenticationToken` to make API calls. | ||
Note that most optional parameters are missing in this module, I'm working on it. PR's are welcome as well 😉 | ||
|
||
## Usage example: | ||
``` | ||
var express = require('express'); | ||
var router = express.Router(); | ||
var Movile = require('movile-messaging'); | ||
/* GET home page. */ | ||
router.get('/', function(req, res, next) { | ||
let sms = new Movile('YOUR_USER_NAME', 'YOUR_AUTH_TOKEN'); | ||
console.log(sms.getStatus('9cb87d36-79af-11e5-89f3-1b0591cdf807')); | ||
res.render('index', { title: 'Movile Messaging Example' }); | ||
}); | ||
module.exports = router; | ||
``` | ||
|
||
## Methods: | ||
### send(destination, messageText) | ||
Send SMS message to a single endpoint. | ||
`destination`: Phone number with country code and area code. Example: `'5519998765432'` | ||
`messageText`: The message string to be sent. If it's too long, it will be split into multiple messages. | ||
|
||
Example: | ||
``` | ||
sms.send('5519998765432', 'Your text here'); | ||
``` | ||
|
||
Expected return: | ||
``` | ||
{ | ||
"id":"9cb87d36-79af-11e5-89f3-1b0591cdf807" | ||
} | ||
``` | ||
|
||
|
||
### sendBulk(numbers, messageText) | ||
Send the same SMS message to many endpoints at once. | ||
`numbers`: Array of phone numbers, just like `destination` in the `send` method. | ||
`messageText`: The message string to be sent. If it's too long, it will be split into multiple messages. | ||
|
||
Example: | ||
``` | ||
sms.sendBulk(['5519988887777', '5535989890000'], 'Your text here'); | ||
``` | ||
|
||
Expected return: | ||
``` | ||
{ | ||
"id":"317b925a-79b0-11e5-82d3-9fb06ba220b3", | ||
"messages":[ | ||
{ | ||
"id":"715773da-79b0-11e5-afc8-dfdd0dedf87a" | ||
}, | ||
{ | ||
"id":"717fb4bc-79b0-11e5-819e-57198aac792e" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
|
||
### getStatus(id) | ||
Check the delivery status of a single message. | ||
`id`: ID of a message, obtained when it is sent. | ||
|
||
Example: | ||
``` | ||
sms.getStatus('8f5af680-973e-11e4-ad43-4ee58e9a13a6'); | ||
``` | ||
Expected return: | ||
``` | ||
{ | ||
"id":"8f5af680-973e-11e4-ad43-4ee58e9a13a6", | ||
"carrierId":5, | ||
"carrierName":"TIM", | ||
"destination":"5519900001111", | ||
"sentStatusCode":2, | ||
"sentStatus":"SENT_SUCCESS", | ||
"sentStatusAt":1420732929252, | ||
"sentStatusDate":"2015-01-08T16:02:09Z", | ||
"deliveredStatusCode":4, | ||
"deliveredStatus":"DELIVERED_SUCCESS", | ||
"deliveredAt":1420732954000, | ||
"deliveredDate":"2015-01-08T16:02:34Z", | ||
"campaignId":1234 | ||
} | ||
``` | ||
|
||
* Note that phone numbers from `OI` carrier will not return `DELIVERED_SUCCESS` status even if the SMS was successfully received. | ||
* Delivery status data is only retained in Movile's backend for a few days, so you may want to store this data somewhere else. | ||
|
||
Special thanks to [@mCodex](https://github.com/mCodex/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
const axios = require('axios'); | ||
|
||
module.exports = class MovileMessaging { | ||
constructor(UserName = null, AuthenticationToken = null) { | ||
this.instance = axios.create({ | ||
baseURL: 'https://api-messaging.movile.com/v1', | ||
timeout: 5000, | ||
headers: { | ||
UserName, | ||
AuthenticationToken, | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
} | ||
|
||
send(destination = null, messageText = '') { | ||
this.instance.post('/send-sms', { | ||
destination, | ||
messageText | ||
}) | ||
.then(response => response.data) | ||
.catch(error => console.error(error)); | ||
} | ||
|
||
sendBulk(numbers = [], messageText = '') { | ||
const messages = numbers.map(number => ({ destination: number })); | ||
this.instance.post('/send-bulk-sms', { | ||
messages, | ||
defaultValues: { | ||
messageText | ||
} | ||
}) | ||
.then(response => response.data) | ||
.catch(error => console.error(error)); | ||
} | ||
|
||
getStatus(id = '') { | ||
this.instance.get('/sms-status?id=' + id) | ||
.then(response => response.data) | ||
.catch(error => console.error(error)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "movile-messaging", | ||
"version": "0.1.0", | ||
"description": "Simple node.js wrapper for Movile's Messaging API", | ||
"repository": "vspedr/movile-messaging", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"movile", | ||
"messaging", | ||
"send", | ||
"sms" | ||
], | ||
"author": "vspedr", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^0.15.3" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.16.0", | ||
"eslint-config-airbnb-base": "^11.1.0", | ||
"eslint-plugin-import": "^2.2.0" | ||
} | ||
} |