
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
A Node.JS REST API Wrapper library for Nexmo (http://nexmo.com/)
For full API documentation refer to https://docs.nexmo.com/
npm install nexmo
var Nexmo = require('nexmo');
var nexmo = new Nexmo({key: KEY, secret: SECRET}, {debug: DEBUG});
KEY
- API Key from NexmoSECRET
- API SECRET from NexmoDEBUG
- set this to true to debug library callsnexmo.sms.sendTextMessage(sender, recipient, message, opts, callback);
opts
- parameter is optionalnexmo.sms.sendBinaryMessage(fromnumber, tonumber,body, udh, callback);
body
- Hex encoded binary dataudh
- Hex encoded udhnexmo.sms.sendWapPushMessage(fromnumber, tonumber, title, url, validity, callback);
validity
- is optional (if given should be in milliseconds)nexmo.sms.shortcodeAlert(recipient, messageParams, opts, callback);
nexmo.account.checkBalance(callback);
nexmo.number.getPricing(countryCode, callback);
countryCode
- 2 letter ISO Country Codenexmo.number.getPhonePricing(product, countryCode, callback);
product
- either voice
or sms
countryCode
- 2 letter ISO Country Codenexmo.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
Example:
nexmo.number.get({pattern:714,index:1,size:50,search_pattern:2},consolelog);
nexmo.number.search(countryCode,options,callback);
options
parameter is optional. They can be one of the following :
pattern
search_pattern
features
index
size
For more details on what the above options mean refer to the Nexmo API documentation
Example:
nexmo.number.buy(countryCode, msisdn, callback);
nexmo.number.cancel(countryCode, msisdn, callback);
nexmo.number.update(countryCode, msisdn, params, callback);
params is a dictionary of parameters per documentation
nexmo.account.updatePassword(<NEW_PASSWORD>,callback);
nexmo.updateSMSCallback(<NEW_CALLBACK_URL>,callback);
nexmo.account.updateDeliveryReceiptCallback(<NEW_DR_CALLBACK_URL>,callback);
nexmo.voice.sendTTSMessage = function(<TO_NUMBER>,message,options,callback);
nexmo.sendTTSPromptWithCapture(<TO_NUMBER>,message,<MAX_DIGITS>, <BYE_TEXT>,options,callback);
nexmo.voice.sendTTSPromptWithConfirm(<TO_NUMBER>, message ,<MAX_DIGITS>,'<PIN_CODE>',<BYE_TEXT>,<FAILED_TEXT>,options,callback);
nexmo.voice.call(<TO_NUMBER>,<ANSWER_URL>,options,callback);
For more information check the documentation at https://docs.nexmo.com/voice/call
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
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
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
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
nexmo.numberInsight.get({level: 'basic', number: NUMBER}, callback);
For more information check the documentation at https://docs.nexmo.com/number-insight/basic
Example:
nexmo.numberInsight.get({level: 'basic', number: '1-234-567-8900'}, consolelog);
nexmo.numberInsight.get({level: 'standard', number: NUMBER}, callback);
For more information check the documentation at https://docs.nexmo.com/number-insight/standard
Example:
nexmo.numberInsight.get({level: 'standard', number: '1-234-567-8900'}, consolelog);
nexmo.numberInsight.get({level: 'advanced', number: NUMBER}, callback);
For more information check the documentation at https://docs.nexmo.com/number-insight/advanced
Callback from all API calls returns 2 parameters - error and a json object.
An example callback function:
function consolelog (err,messageResponse) {
if (err) {
console.log(err);
} else {
console.dir(messageResponse);
}
}
Refer here https://docs.nexmo.com/ to get the schema for the returned message response object.
Run the
npm test
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:
nexmo.setHost('localhost');
Note that default port is 443 and nexmo 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:
nexmo.setPort('8080');
There are some basic examples which will test the functionality. They uses environment variables for settings for the tests. The environment variables are:
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:
node examples/pre-v1.js
And
node examples/v1-beta.js
MIT - see LICENSE
FAQs
Nexmo REST API client for Node.js. API support for SMS, Voice Calls, Text-to-Speech, Numbers, Verify (2FA) and more.
The npm package nexmo receives a total of 6,319 weekly downloads. As such, nexmo popularity was classified as popular.
We found that nexmo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.