Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nexmo

Package Overview
Dependencies
Maintainers
3
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nexmo - npm Package Compare versions

Comparing version 0.0.7 to 1.0.0-beta-1

.babelrc

55

package.json
{
"name": "nexmo",
"description": "A node.js library for accessing the Nexmo REST API",
"keywords": ["nexmo", "sms"],
"author": "Paul O'Fallon <paul@ofallonfamily.com>",
"homepage": "https://github.com/pofallon/node-nexmo",
"dependencies": {
"request": "2.2.x",
"connect": "1.8.x"
"author": "nexmo",
"version": "1.0.0-beta-1",
"main": "lib/nexmo",
"keywords": [
"sms",
"voice",
"nexmo"
],
"homepage": "https://github.com/nexmo/nexmo-node",
"repository": {
"type": "git",
"url": "git://github.com/nexmo/nexmo-node.git"
},
"description": "A nodejs wrapper for nexmo API to send SMS",
"contributors": [
"nexmo",
"pvela",
"leggetter",
"akuzi",
"bpilot",
"justinfreitag",
"ecwyne",
"https://github.com/backhand"
],
"scripts": {
"compile": "./node_modules/.bin/babel -d lib src/ -s inline",
"prepublish": "npm run compile",
"test": "npm run compile && mocha --compilers ./node_modules/.bin/_mocha --compilers js:babel-register ./test/*-test.js"
},
"devDependencies": {
"nodeunit": "0.6.x"
},
"engine": "node >= 0.4.1",
"version": "0.0.7",
"files": [
"index.js",
"lib",
"package.json",
"README.md",
"test"
],
"main": "index"
"babel-cli": "^6.7.7",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.7.2",
"dotenv": "^2.0.0",
"expect.js": "^0.3.1",
"mocha": "^2.4.5"
}
}

@@ -1,49 +0,334 @@

# node-nexmo
A node.js library for accessing the Nexmo REST API.
# Nexmo Client Library for Node.js [![build status](https://secure.travis-ci.org/Nexmo/nexmo-node.png)](http://travis-ci.org/Nexmo/nexmo-node)
A Node.JS REST API Wrapper library for Nexmo (http://nexmo.com/)
For full API documentation refer to https://docs.nexmo.com/
[![NPM](https://nodei.co/npm/easynexmo.png)](https://nodei.co/npm/easynexmo/)
## Installation Instructions
```bash
npm install easynexmo
```
## Usage
```javascript
var nexmo = require('nexmo')({key: 'key', secret: 'secret'});
```js
var Nexmo = require('easynexmo');
// Send an SMS message
var nexmo = new Nexmo({key: KEY, secret: SECRET}, {debug: DEBUG});
```
var message = nexmo.sms({to: 'to', from: 'from', text: 'Welcome to Nexmo from Node!'});
* `KEY` - API Key from Nexmo
* `SECRET` - API SECRET from Nexmo
* `DEBUG` - set this to true to debug library calls
message.send(function(err, results) {
if (!err) {
console.log('Your message was delivered in ' + results['message-count'] + ' part(s)!');
}
});
## List of API's supported by the library
// Check your account balance
### Send a text message
nexmo.account.balance(function(err, balance) {
if (!err) {
console.log('Your account balance is: ' + balance);
}
});
```js
nexmo.sms.sendTextMessage(sender, recipient, message, opts, callback);
```
// ... or spin up an http server and emit message receipts
* `opts` - parameter is optional
nexmo.receipts.on('failed', function(msg) {
console.log('Message to ' + msg.to + ' failed!');
nexmo.receipts.stop();
### Send a Binary Message
```js
nexmo.sms.sendBinaryMessage(fromnumber, tonumber,body, udh, callback);
```
* `body` - Hex encoded binary data
* `udh` - Hex encoded udh
### Send a WAP Push Message
```js
nexmo.sms.sendWapPushMessage(fromnumber, tonumber, title, url, validity, callback);
```
* `validity` - is optional (if given should be in milliseconds)
### Send a Short Code alert
```js
nexmo.sms.shortcodeAlert(recipient, messageParams, opts, callback);
```
### Check Account Balance
```js
nexmo.account.checkBalance(callback);
```
### Get Pricing for sending message to a country.
```js
nexmo.number.getPricing(countryCode, callback);
```
* `countryCode` - 2 letter ISO Country Code
### Get Pricing for sending message or making a call to a number.
```js
nexmo.number.getPhonePricing(product, countryCode, callback);
```
* `product` - either `voice` or `sms`
* `countryCode` - 2 letter ISO Country Code
### Get all numbers associated to the account.
```js
nexmo.number.get(options, callback);
```
* `options` parameter is an optional Dictionary Object containing any of the following parameters
* `pattern`
* `search_pattern`
* `index`
* `size`
For more details on what the above options mean refer to the Nexmo API [documentation](https://docs.nexmo.com/tools/developer-api/account-numbers)
Example:
```js
nexmo.number.get({pattern:714,index:1,size:50,search_pattern:2},consolelog);
```
### Search for MSISDN's available to purchase.
```js
nexmo.number.search(countryCode,options,callback);
```
`options` parameter is optional. They can be one of the following :
1. number pattern to match the search (eg. 1408)
2. Dictionary Object optionally containing the following parameters :
* `pattern`
* `search_pattern`
* `features`
* `index`
* `size`
For more details on what the above options mean refer to the Nexmo API [documentation](https://docs.nexmo.com/tools/developer-api/number-search)
Example:
```js nexmo.number.search('US',{pattern:3049,index:1,size:50,features:'VOICE',search_pattern:2},consolelog);
```
### Purchase number
```js
nexmo.number.buy(countryCode, msisdn, callback);
```
### Cancel Number
```js
nexmo.number.cancel(countryCode, msisdn, callback);
```
### Update Number
```js
nexmo.number.update(countryCode, msisdn, params, callback);
```
params is a dictionary of parameters per [documentation](https://docs.nexmo.com/index.php/developer-api/number-update)
### Update Password (API Secret)
```js
nexmo.account.updatePassword(<NEW_PASSWORD>,callback);
```
### Update Callback URL associated to the account
```js
nexmo.updateSMSCallback(<NEW_CALLBACK_URL>,callback);
```
### Change Delivery Receipt URL associated to the account
```js
nexmo.account.updateDeliveryReceiptCallback(<NEW_DR_CALLBACK_URL>,callback);
```
### Send TTS Message
```js
nexmo.voice.sendTTSMessage = function(<TO_NUMBER>,message,options,callback);
```
### Send TTS Prompt With Capture
```js
nexmo.sendTTSPromptWithCapture(<TO_NUMBER>,message,<MAX_DIGITS>, <BYE_TEXT>,options,callback);
```
### Send TTS Prompt With Confirm
```js
nexmo.voice.sendTTSPromptWithConfirm(<TO_NUMBER>, message ,<MAX_DIGITS>,'<PIN_CODE>',<BYE_TEXT>,<FAILED_TEXT>,options,callback);
```
### Make a voice call
```js
nexmo.voice.call(<TO_NUMBER>,<ANSWER_URL>,options,callback);
```
For more information check the documentation at https://docs.nexmo.com/voice/call
### Submit a Verification Request
```js
nexmo.verify.request({number:<NUMBER_TO_BE_VERIFIED>,brand:<NAME_OF_THE_APP>},callback);
```
For more information check the documentation at https://docs.nexmo.com/verify/api-reference/api-reference#vrequest
### Validate the response of a Verification Request
```js
nexmo.verify.check({request_id:<UNIQUE_ID_FROM_VERIFICATION_REQUEST>,code:<CODE_TO_CHECK>},callback);
```
For more information check the documentation at https://docs.nexmo.com/verify/api-reference/api-reference#check
### Search one or more Verification Request
```js
nexmo.verify.search(<ONE_REQUEST_ID or ARRAY_OF_REQUEST_ID>,callback);
```
For more information check the documentation at https://docs.nexmo.com/verify/api-reference/api-reference#search
### Verification Control API
```js
nexmo.verify.control({request_id:<UNIQUE_ID_FROM_VERIFICATION_REQUEST>,cmd:<CODE_TO_CHECK>},callback);
```
For more information check the documentation at https://docs.nexmo.com/verify/api-reference/api-reference#control
### Number Insight - Basic
```js
nexmo.numberInsight.get({level: 'basic', number: NUMBER}, callback);
```
For more information check the documentation at https://docs.nexmo.com/number-insight/basic
Example:
```js
nexmo.numberInsight.get({level: 'basic', number: '1-234-567-8900'}, consolelog);
```
### Number Insight - Standard
```js
nexmo.numberInsight.get({level: 'standard', number: NUMBER}, callback);
```
For more information check the documentation at https://docs.nexmo.com/number-insight/standard
Example:
```js
nexmo.numberInsight.get({level: 'standard', number: '1-234-567-8900'}, consolelog);
```
### Number Insight - Advanced
```js
nexmo.numberInsight.get({level: 'advanced', number: NUMBER}, callback);
```
For more information check the documentation at https://docs.nexmo.com/number-insight/advanced
## Callbacks
Callback from all API calls returns 2 parameters - error and a json object.
An example callback function:
```js
function consolelog (err,messageResponse) {
if (err) {
console.log(err);
} else {
console.dir(messageResponse);
}
}
nexmo.receipts.start();
```
Refer here https://docs.nexmo.com/ to get the schema for the returned message response object.
## Testing
Run the
```bash
npm test
```
## Install
For testing purposes you can also use setHost function to make the library send requests to another place like localhost instead of real Nexmo. Feel free to catch and process those requests the way you need. A usage example:
<pre>
npm install nexmo
</pre>
```js
nexmo.setHost('localhost');
```
## Dependencies
Note that default port is 443 and easynexmo does https calls in such a case. You can use setPort function to make it proper for your testing environment. When port is not 443 it will make requests via http protocol. Have a look at an example:
This library depends on:
```js
nexmo.setPort('8080');
```
* [mikeal/request](https://github.com/mikeal/request)
* [senchalabs/connect](https://github.com/senchalabs/connect)
* [caolan/nodeunit](https://github.com/caolan/nodeunit) (for unit tests)
## Examples
There are some basic examples which will test the functionality. They uses environment variables for settings for the tests. The environment variables are:
* KEY = The API key provided by Nexmo for your account
* SECRET = The secret provided by NExmo for your account
* FROM_NUMBER = The phone number to send messages and make calls from.
* TO_NUMBER = The phone number to send messages and make calls to.
* MAX_DIGITS = The maximum number of digits for the pin code.
* ANSWER_URL = The URL which has the VoiceXML file to control the call functionality
* PIN_CODE = The digits you must enter to confirm the message
The simplest way to run the examples is to create a `.env` file in the `examples` directory with the following:
```
KEY={value}
SECRET={value}
FROM_NUMBER={value}
TO_NUMBER={value}
MAX_DIGITS={value}
ANSWER_URL={value}
PIN_CODE={value}
```
Then run:
```bash
node examples/pre-v1.js
```
And
```bash
node examples/v1-beta.js
```
## License
MIT - see [LICENSE](LICENSE.txt)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc