Skip to content

Instantly share code, notes, and snippets.

@adambutler
Last active October 31, 2017 11:42
Show Gist options
  • Save adambutler/fdfeba152303388adc3fbc7c99272123 to your computer and use it in GitHub Desktop.
Save adambutler/fdfeba152303388adc3fbc7c99272123 to your computer and use it in GitHub Desktop.

Sending an SMS Instructions

Specification

A building block that shows how to send a basic SMS with Nexmo.

  • Change the body of Install the Nexmo library to be appropriate for the language
  • Acme Inc must be used as the placeholder for the from field
  • NEXMO_API_KEY must be specified as a constant NEXMO_API_KEY or as a string "NEXMO_API_KEY"
  • NEXMO_API_SECRET must be specified as a constant NEXMO_API_SECRET or as a string "NEXMO_API_SECRET"
  • TO_NUMBER must be specified as a string "TO_NUMBER"
  • The text of the message should be A test SMS sent using the Nexmo SMS API
  • Code examples should include a GitHub link to the file
  • Code examples should include the line numbers used from the linked file
  • All code examples must be present in the master branch of the relevant quickstart repo
  • All code examples must be tested to work (manual testing is fine)

Instructions

  1. Fork this gist
  2. Edit the gist and the building block files to match the specification
  3. Return Gist as a comment in the original issue

Sending an SMS

Sending an SMS message with Nexmo is easy. Simply sign up for an account and replace the following variables in the example below:

Key Description
TO_NUMBER The number you are sending the SMS to in E.164 format. For example 447700900000.
NEXMO_API_KEY You can find this in your account overview
NEXMO_API_SECRET You can find this in your account overview

Install the Nexmo library

$ npm install --save nexmo

Initialize the library

// GITHUB: https://github.com/nexmo-community/nexmo-node-quickstart/blob/master/sms/send.js
// Lines: 10-15

const Nexmo = require('nexmo')

const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET
})

Send an SMS

// GITHUB: https://github.com/nexmo-community/nexmo-node-quickstart/blob/master/sms/send.js
// Lines: 17-21

const from = 'Acme Inc'
const to = TO_NUMBER
const text = 'A text message sent using the Nexmo SMS API'

nexmo.message.sendSms(from, to, text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment