Receiving an SMS

Handling inbound SMS with Nexmo is easy. You just need to create a webhook endpoint and configure your number or account to point to the endpoint.

Prerequisites

Implement a webhook endpoint

const app = require('express')()
const bodyParser = require('body-parser')

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

app
  .route('/webhooks/inbound-sms')
  .get(handleInboundSms)
  .post(handleInboundSms)

function handleInboundSms(request, response) {
  const params = Object.assign(request.query, request.body)
  console.log(params)
  response.status(204).send()
}

app.listen(3000)

Run your server

Save this file to your machine and run it using the node command:

$ node app.js

You'll need to expose your server to the open internet. During development you can use a tool like Ngrok  to do that.

Configure your SMS endpoint with Nexmo

From Nexmo Dashboard  go to Settings  .

Enter your endpoint in the field labeled Webhook URL for Inbound Message:

Screenshot

Send your Nexmo number an SMS

Now when you send your Nexmo number an SMS you should see it logged in your console.