SMS Messaging and Verification via Nexmo Using Node.js

Candy Tsai
DeepQ Research Engineering Blog
4 min readJun 5, 2018

Nexmo is a service that allows developers to integrate calling or texting functions into business apps readily. In this article, we will focus on sending SMS messages and verifying users.

The following examples are based on parts of nexmo-node-quickstart, so you can head over there and clone the complete repository to follow along.

Nexmo provides 2 euro for a new registered user to test the API and will embed a [FREE SMS DEMO, TEST MESSAGE] watermark when sending custom SMS messages.

Sending Our First SMS Message

Pricing for sending a SMS message in Taiwan
const Nexmo = require('nexmo')const nexmo = new Nexmo({
apiKey: NEXMO_API_KEY,
apiSecret: NEXMO_API_SECRET
})
const options = {}
const from = 'Yingray'
const to = PHONE_NUMBER
const text = '安安、你好、幾歲、住哪'
nexmo.message.sendSms(from, to, text, options, (err, data) => {
console.log(err, data)
})

What will happen when this code is executed is that you will receive a text message on the carrier with PHONE_NUMBER:

Be careful when working with non-latin characters

Our custom message is written in Chinese so be sure to add type into our options object:

const options = {
type: 'unicode'
}

Now that it is set to unicode, we can receive our expected result:

Note that the free account will have the [FREE SMS DEMO, TEST MESSAGE] watermark

Stress Testing

According to “How fast can I send Outbound SMS?”:

Our standard account lets you handle up to 2,592,000 SMS per day (e.g. 30 SMS per second)

When using the testing free account, I tried sending 10 SMS/sec but the receiver did not receive all of the messages, but all of the messages were billed. Not sure if it will work once upgraded to standard account.

The Verify API

Taiwan is regarded as “All other countries”: 0.1 euro/successful verification

Nexmo also offers two factor authentication (2FA) out of the box through their Verify API. We will use the sample code provided here: https://github.com/nexmo-community/nexmo-node-quickstart/tree/master/verify. Please make sure that the environment variables are properly set because the naming in .env is usually different from the sample code.

The verification process works like this:

Ref: https://developer.nexmo.com/verify/guides/verify-a-user/
  1. Sends a PIN code to the specified phone number (default 300s expiration; Range: 60–3600s)
  2. User receives code on their phone, if user does not enter verification code, Nexmo will call the user
  3. User enters verification code
  4. Check phone verification code and see if it can successfully verify the user

Notes:

  • Nexmo will only bill successful verifications!
  • User will be phoned in a while if not verified, but I don’t know why after the first time I tried this feature, the phone doesn’t answer

If you request Taiwanese (zh-tw), the text message will be sent in Traditional Chinese, but the voice call uses a female voice speaking English with a Chinese accent.

Analytics

Nexmo also provides a dashboard with analytics data as well as logs to keep track of all sent verifications.

Custom Message/Voice Template

It is also possible to use custom messages/voice with the verify API: https://developer.nexmo.com/api/verify/templates/. BUT! The API actually sends a ticket to Nexmo to request an activation and it doesn’t say that anywhere in the documentation. So please remember that this is a manual process. Because we haven’t made a purchase, so the ticket was rejected.

Custom message request ticket

More information on Nexmo can be found directly on their site. They have done a really great job providing thorough tutorials and clear guides on how to use them.

--

--

Candy Tsai
DeepQ Research Engineering Blog

Front end developer who specializes in evangelizing Winnie the Pooh.