Code Monkey home page Code Monkey logo

grails-nexmo's Introduction

Grails-Nexmo Plugin

PRs Welcome

A Grails plugin to allow applications send sms, lookup a number and make calls. with text-to-speech using Nexmo's API.

Installation

Using Gradle

compile 'com.saopayne:grails-nexmo:1.2'

Using Maven
<dependency>
  <groupId>com.saopayne</groupId>
  <artifactId>grails-nexmo</artifactId>
  <version>1.2</version>
  <type>pom</type>
</dependency>
Using Ivy
<dependency org='com.saopayne' name='grails-nexmo' rev='1.2'>
  <artifact name='grails-nexmo' ext='pom' ></artifact>
</dependency>
Adding Jar File

https://dl.bintray.com/saopayne/plugins/com/saopayne/grails-nexmo/1.2/grails-nexmo-1.2.jar

Methods

This method allows you to perform a look up on a given number to get the carrier, cuntry code etc.

  • Parameters
    • apiKey - Your api key from the settings dashboard
    • apiSecret - Your api secret from the settings dashboard
    • number - The number to look up
  • Returns
    • carrier - The carrier details of the number such as the name and type
    • country_code - The country code

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

  • Parameters
    • apiKey - Your api key from the settings dashboard
    • apiSecret - Your api secret from the settings dashboard
    • 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
  • Returns
    • status - The status code of the message
    • id - The ID of the message

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

  • Parameters
    • apiKey - Your api key from the settings dashboard
    • apiSecret - Your api secret from the settings dashboard
    • 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

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

Example

class SampleController {

  // Inject the service
  def nexmoService

  def index() {
    def lookUpResult
    def smsResult
    def callResult

    try {
      // Lookup a particular number
      lookUpResult = nexmoService.lookup("apiKey", "apiSecret", "070707") 
       
      // Send the message "hello Nexmo" to 0704303333
      smsResult = nexmoService.sendSms("apiKey","apiSecret", "", "0704303333", "Hello Nexmo")

      // Call the number and tell them a message
      callResult = nexmoService.call("020233323", "Have a great day! Goodbye.")
    } catch (NexmoException e) {
      // Handle error if failure
    }
  }
}

Here is an example response:

// Lookup
[carrier:[name:carrierName, type:carrierType],country_code:countryCode]

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

// Call
[ status: "0", id: "14b75f2246e7c1a17d345449a20d93e5" ]

To contribute

  • Fork this repository.
  • Create a new branch and make additions as you deem fit.
  • Send in a PR with the feature/bug it addresses.

grails-nexmo's People

Contributors

saopayne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dubems orubel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.