Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Grails plugin that gives an application the ability to send and receive SMS messages, as well as make outgoing phone calls through Nexmo's API.
Groovy Java
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
grails-app
src/java/grails/plugin/nexmo
test/unit/grails/plugin/nexmo
.gitignore
LICENSE
NexmoGrailsPlugin.groovy
README.md
application.properties

README.md

Nexmo Grails Plugin

This plugin gives any Grails application the ability to send SMS messages and outgoing phone calls with text-to-speech using Nexmo's API.

Installation

You can add this plugin to your application by adding the following to your BuildConfig.groovy file:

plugins {
  compile ":nexmo:1.0" // Add this line
}

Methods

sendSms(String to, String text, String from)

This method allows you to send an SMS message to a mobile number.

  • Parameters
    • to - The mobile number in international format
    • text - Body of the text message (with a maximum length of 3200 characters)
    • from (optional) - The number to send from, defaults to the default_from number in NexmoConfig.groovy.
  • Returns
    • status - The status code of the message
    • id - The ID of the message

call(String to, String text, String from)

This method uses text-to-speech to call your recipient and deliver a message.

  • Parameters
    • to - The phone number to send the call to, in International Format
    • text - The message to deliver during the call
    • from (optional) - The number to send the call from. Must be a voice enabled inbound number associated with your account
  • Returns
    • status - The status code of the message
    • id - The ID of the message

Usage

Set the configuration in your Config.groovy file, as shown below:

nexmo {
  api {
    key    = "abcde123" // Your Nexmo API Key
    secret = "fghij456" // Your Nexmo API Secret
  }

  sms {
    default_from = "15005551234" // Your default from telephone number for SMS
  }
}

You can then proceed to use the plugin in a Grails controller or service by injecting the NexmoService bean, and calling the sendSms method.

Example

class ExampleController {

  // Inject the service
  def nexmoService

  def index() {
    def smsResult
    def callResult

    try {
      // Send the message "What's up?" to 1-500-123-4567
      smsResult  = nexmoService.sendSms("15001234567", "What's up?")

      // Call the number and tell them a message
      callResult = nexmoService.call("15001234567", "Have a great day! Goodbye.")

    catch (NexmoException e) {
      // Handle error if failure
    }
  }
}

Here is an example response:

// SMS
[ status: "0", id: "00000125" ]

// Call
[ status: "0", id: "14b75f2246e7c1a17d345449a20d93e5" ]
Something went wrong with that request. Please try again.