SMS Customer Support

The general availability of SMS makes it a versatile solution for customer support. Phone numbers can be printed, read out, and put on websites, allowing anyone online or offline to engage with your business.

Providing customer support over SMS is an easy way to provide a full two-way communication system to anybody with a phone connected to a mobile network.

In this tutorial

You will build a simple system for SMS customer support using Nexmo's APIs and libraries.

To do this:


In order for this tutorial to work you will need:

A Basic Web application

For this tutorial start off with a simple web application with one page. The user will be able to click on a link to open their SMS app and request support. Your app will collect the inbound SMS and open a new ticket. Finally, the app will reply with a new SMS to the user confirming their ticket number.

sequenceDiagram Participant Phone Participant Nexmo Participant App Phone->>Nexmo: SMS 1 Nexmo-->>App: Webhook App->>Nexmo: SMS Request Nexmo->>Phone: SMS 2

Start by creating a basic app.

rails new customer-support
cd customer-support
rake db:create db:migrate

The page will be at the root of our application and will provide a link to your SMS app with some prefilled text.

Adding a first page

rails g controller pages index


<h1>ACME Support</h1>

  <a href="sms://<%= ENV['NEXMO_NUMBER'] %>?body=Hi ACME, I'd like some help with: " class='button'>
    Get support via SMS

With this in place the server can be started.

Starting the server

rails server

Purchase a phone number

Before the app can receive an SMS a Nexmo phone number has to be rented. Phone numbers can be purchased from the dashboard or directly from the command line with the Nexmo CLI.

> nexmo number:buy --country_code US --confirm
Number purchased: 447700900000

Finally, Nexmo must be informed of the webhook endpoint to make an HTTP request to when an inbound SMS is received. This can be done using the dashboard or the Nexmo CLI.

> nexmo link:sms 447700900000 http://[]/support
Number updated

Note: Ensure your server is running and publicly available before trying to set up a new callback URL for webhooks. When you are setting up a new webhook Nexmo will make a call to your server to confirm it's available.

Process an Inbound SMS

When the customer sends their SMS it will be received by Nexmo via the mobile carrier network. Nexmo will subsequently make a webhook to your application.

This webhook will contain the original text sent, the phone number the message came from, and a few more parameters. For more details see the Inbound Message documentation.

Your app should process the incoming webhook, extract the text and number, open a new ticket, or update an existing ticket. If this is a customer's first request the app should send a confirmation message back to the customer with their ticket number.

This is achieved by saving the incoming message and opening a new ticket if the number does not already have an open ticket.

Add a ticket and a message model

rails g controller support index
rails g model Ticket number
rails g model Message text ticket:references
rake db:migrate


class SupportController < ApplicationController
  def index
    render nothing: true


  def ticket
    @ticket ||= Ticket.where(
      number: params[:msisdn]

  def save_message
    message = Message.create(
      text: params[:text],
      ticket: ticket

Send an SMS reply with a ticket number

To send the confirmation to the customer's SMS, add the Nexmo library to your project.


gem 'nexmo'
gem 'dotenv-rails'

Note: To initialize the Server SDK you will need to pass it your API key and secret. We highly recommend that you do not store your API credentials in your code but to use environment variables instead.

With the library initialized the application can now send an SMS. Only send a response if this was the first message on this ticket.

def send_response
  return if ticket.messages.count > 1

  client =
  result = client.sms.send(
    from: ENV['NEXMO_NUMBER'],
    to: ticket.number,
    text: "Dear customer, your support" \
          "request has been registered. " \
          "Your ticket number is #{}. " \
          "We intend to get back to any " \
          "support requests within 24h."


In this tutorial you've learned how to receive an SMS from a customer's phone and send an SMS reply to them. With these code snippets you now have an SMS customer support solution using the Nexmo SMS API.

Get the Code

All the code for this tutorial and more is available on GitHub.