The preferred way to install is use the npm package manager for Node.js.
$ npm install simple-nexmo
After you've installed, you can require the package in your node application using require
:
var Nexmo = require('simple-nexmo');
var nexmo = new Nexmo();
API_KEY
、API_SECRET
: Required. You will find them in "API Settings" in Nexmo Dashboard
API_PROTOCOL
: Optional. http or https
DEBUG_MODE
: Optional. Set to true to see debug informations
nexmo.init(API_KEY, API_SECRET, API_PROTOCOL, DEBUG_MODE);
- nexmo.sendTextMessage(
from
,to
,message
,callback
) - nexmo.sendBinaryMessage(
from
,to
,body
,udh
,callback
) - nexmo.sendWapPushMessage(
from
,to
,title
,url
,validity
,callback
)
- nexmo.getBalance(
callback
) - nexmo.getPricing(
countryCode
,callback
) - nexmo.updateSecret(
newSecret
,callback
) - nexmo.updateMoCallBackUrl(
newUrl
,callback
) - nexmo.updateDrCallBackUrl(
newUrl
,callback
) - nexmo.getTopUp(
transactionId
,callback
) - nexmo.getNumbers(
callback
) - nexmo.searchNumbers(
countryCode
,pattern
,index
,size
,callback
) - nexmo.buyNumber(
countryCode
,msisdn
,callback
) - nexmo.cancelNumber(
countryCode
,msisdn
,callback
) - nexmo.searchMessage(
messageId
,callback
) - nexmo.searchMessageByIds(
messageIds
,callback
) - nexmo.searchMessagesByRecipient(
date
,to
,callback
) - nexmo.searchRejections(
date
,to
,callback
)
The following API will supported in the future.
- nexmo.updateNumberCallback(
countryCode
,msisdn
,newUrl
,sysType
,callback
)
from
: Required. Sender address may be alphanumeric. Ex:MyCompany20
to
: Required. Mobile number in international format, and one recipient per request. Ex:886912345678
message
: Required. Text message. Ex:Hello World!
nexmo.sendTextMessage(from, to, message, callback)
from
: Required. Sender address may be alphanumeric. Ex:MyCompany20
to
: Required. Mobile number in international format, and one recipient per request. Ex:886912345678
body
: Required. Hex encoded binary data. Ex:0011223344556677
udh
: Required. Hex encoded udh. Ex:06050415811581
nexmo.sendBinaryMessage(from, to, body, udh, callback)
from
: Required. Sender address may be alphanumeric. Ex:MyCompany20
to
: Required. Mobile number in international format, and one recipient per request. Ex:886912345678
title
: Required. Title of WAP Push. Ex:MySite
url
: Required. WAP Push URL. Ex:http://www.mysite.com
validity
: Optional. Set how long WAP Push is available in milliseconds. Ex:86400000
(Default: 48 hours.)
nexmo.sendWapPushMessage(from, to, title, url, validity, callback)
nexmo.getBalance(callback)
countryCode
: Required. A 2 letter country code. Ex:CA
nexmo.getPricing(countryCode ,callback)
newSecret
: Required. New API secret (8 characters max)
nexmo.updateSecret(newSecret, callback)
newUrl
: Required. Inbound call back URL. Ex:http://mycallback.servername
nexmo.updateMoCallBackUrl(newUrl, callback)
newUrl
: Required. DLR call back URL. Ex:http://mycallback.servername
nexmo.updateDrCallBackUrl(newUrl, callback)
Account: Top Up - Top-up your account, only if you have turn-on the 'auto-reload' feature. The top-up amount is the one associated with your 'auto-reload' transaction.
transactionId
: Required. The transaction id associated with your first 'auto reload' top-up. Ex: 00X123456Y7890123Z
nexmo.getTopUp(transactionId, callback)
nexmo.getNumbers(callback)
countryCode
: Required. Country code. Ex:CA
pattern
: Optional. A matching pattern. Ex:888
index
: Optional. Page index (>0, default 1). Ex:2
size
: Optional. Page size (max 100, default 10). Ex:25
nexmo.searchNumbers(countryCode, pattern, index, size, callback)
countryCode
: Required. Country code. Ex: ES
msisdn
: Required. An available inbound number Ex:34911067000
nexmo.buyNumber(countryCode, msisdn, callback)
countryCode
: Required. Country code. Ex: ES
msisdn
: Required. One of your inbound numbers Ex:34911067000
nexmo.cancelNumber(countryCode, msisdn, callback)
messageId
: Required. Your message id received at submission time Ex:00A0B0C0
nexmo.searchMessage(messageId, callback)
messageIds
: Required. A list of message ids, up to 10 Ex:[00A0B0C0', '00A0B0C1', '00A0B0C2' ]
nexmo.searchMessageByIds(messageIds, callback)
date
: Required. Message date submission YYYY-MM-DD Ex:2013-11-03
to
: Required. A recipient number Ex:886912345678
nexmo.searchMessagesByRecipient(date, to, callback)
date
: Required. Message date submission YYYY-MM-DD Ex:2013-11-03
to
: Optional. A recipient number Ex:886912345678
nexmo.searchRejections(date, to, callback)
Callback from all API calls returns 2 parameters: error and a json object.
An example callback function:
function callback (err, response) {
if (err) {
console.log(err);
} else {
console.dir(response);
}
}
Refer offical docuemnts to get the schema for the returned message response object.
Copyright © 2013-2014 Calvert Yang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.