Show Navigation

twilio

Provides SMS sending capabilities to a Grails application.

Owner: novadge | 0.1.4 | Aug 13, 2016 | Package | Issues | Source | License: Apache-2.0


dependencies {
    compile 'org.grails.plugins:grails-twilio:0.1.4'
}

            

Twilio Grails

Description

The twilio-grails plug-in provides sms sending capability to a Grails application via twilio api.

Configuration

Add your twilio properties to grails configuration file: Example Assuming you have a twilio account, then add the required information to your grails config file.

twilio {
    // Enter your host address
    host = 'https://api.twilio.com'
    apiID = 'enter your api Id'
    apiPass = 'enter your api password'
    smsUrl = '/2010-04-01/Accounts/' + apiID + '/Messages.json'
    number = ""
}

BuildConfig.groovy

Copy and paste the following to your BuildConfig.groovy File compile(group:'org.apache.httpcomponents',name:'httpclient',version:'4.3.6') compile(group:'org.apache.httpcomponents',name:'fluent-hc',version:'4.3.6') compile(group:'org.apache.httpcomponents',name:'httpclient-cache',version:'4.3.6') compile(group:'org.apache.httpcomponents',name:'httpmime',version:'4.3.6')

Usage

Inject smsService into your class

def smsService

smsService is a Grails service that provides a method called send() that can take mapped parameters. Please note that 'send()' is overloaded 'see http://en.wikipedia.org/wiki/Function_overloading' and can take various variations of parameters.


One simple form is: send(Map map)

Where ......

map contains parameters... map.to: phone number of recipient eg +1234444444

map.from: your twilio assigned number eg. +09899898989

map.body: "The body of your message" map.mediaUrl: "Url for any attachment" (optional )

Example

An example usage can be seen below.

Class YourController{
 
    def smsService
    ...
    def yourMethod(){
        def map = [to:"070987878787",from:"09808000000",body:"SMS BODY"]
        smsService.send(map)
    
    }

}