Grails plugin for Infobip SMS API
- Sign up for an infobip account
- Confirm your account
String basicAuthorization(String username, String password)
- username - infobip username
- password - infobip password
NB: Basic authorization is mandatory for all infobip REST API requests.
JSONObject sendSingleMessage(String authorization, String from, String to, String text)
- from - Sender phone number registered on infobip (Phone numbers are usually prefixed with + (plus sign), followed by a country code, network code and the subscriber number)
- to - Recipient phone number
- text - SMS message to send
JSONObject sendSingleMessage(String authorization, String from, List to, String text)
- to - A list of string types of recipients' phone numbers
JSONObject sendMultipleMessages(String authorization, JSONObject data)
- data - A json object of data. An example is show below.
{
"messages":[
{
"from":"InfoSMS",
"to":[
"41793026727",
"41793026731"
],
"text":"May the Force be with you!"
},
{
"from":"41793026700",
"to":"41793026785",
"text":"A long time ago, in a galaxy far, far away... It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire."
}
]
}
JSONObject deliveryReport(String authorization)
JSONObject deliveryReport(String authorization, Map filters)
- filters - A filter map. View here for more filter information.
NB: Delivery reports can only be gotten once. A second call returns an empty result.
JSONObject messageLog(String authorization)
JSONObject messageLog(String authorization, Map filters)
- filters - A filter map. View here for filter information.
Edit application.groovy (or application.yml if you prefer) and build.gradle
- application.groovy
infobip.host = "https://api.infobip.com"
OR
- application.yml
infobip:
host: https://api.infobip.com
- build.gradle
repositories {
maven {
url "http://dl.bintray.com/modnsolutions/grails-plugins"
}
}
dependencies {
compile 'com.modnsolutions:modninfobip:0.1'
}
- Import the required service classes into you Grails Service or Controller class.
import com.modnsolutions.AuthorizationService
import com.modnsolutions.SendMessageService
- Inject AuthorizationService and SendMessageService classes into your Grails Service or Controller class.
AuthorizationService authorizationService
SendMessageService sendMessageService
- In your class method, generate your basic authorization code and send your messages
String basicAuthorization = authorizationService.basicAuthorization("INFOBIP_USERNAME", "INFOBIP_PASSWORD")
JSONObject singleMessageResponse = sendMessageService.sendSingleMessage(basicAuthorization, from, to, text)
println singleMessageResponse
import com.modnsolutions.AuthorizationService
import com.modnsolutions.SendMessageService
import org.grails.web.json.JSONArray
class SMSController {
AuthorizationService authorizationService
SendMessageService sendMessageService
def sendSingleSMS(String from, String to, String text) {
String basicAuthorization = authorizationService.basicAuthorization("INFOBIP_USERNAME", "INFORBIP_PASSWORD")
JSONObject singleMessageResponse = sendMessageService.sendSingleMessage(basicAuthorization, from, to, text)
println singleMessageResponse
flash.message = singleMessageResponse
render view: "/index.gsp"
}
...
}