A Grails plugin to allow applications send sms, lookup a number and make calls. with text-to-speech using Nexmo's API.
compile 'com.saopayne:grails-nexmo:1.2'
<dependency>
<groupId>com.saopayne</groupId>
<artifactId>grails-nexmo</artifactId>
<version>1.2</version>
<type>pom</type>
</dependency>
<dependency org='com.saopayne' name='grails-nexmo' rev='1.2'>
<artifact name='grails-nexmo' ext='pom' ></artifact>
</dependency>
https://dl.bintray.com/saopayne/plugins/com/saopayne/grails-nexmo/1.2/grails-nexmo-1.2.jar
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
You can proceed to use the plugin in a Grails controller or service by injecting the NexmoService bean, and calling the sendSms
method.
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" ]
- Fork this repository.
- Create a new branch and make additions as you deem fit.
- Send in a PR with the feature/bug it addresses.