Sending SMS
From bemoko developer wiki
Goal
As an example of what you can do with the bemokoLive let's consider the case of sending an SMS. Many SMS aggregators provide web service integrations to interact with SMS messaging. They all use various flavours - but let's take a quick look at integrating with the service from TextAnywhere.
Site Configuration
Let's define an intent named in and define the view to use the UI resource in.html. Let's also configure the plugin SMSIn to be executed when for this in intent, e.g.
<site parent="components"> <content-sources> <source plugin="SMSIn" expr="uri.startsWith('/in')"/> </content-sources> <intents> <intent name="in" type="template" view="in.html"/> </intents> </site>
bemokoLive plugin
class SMSIn { private static String SEND_ENPOINT="http://ws.textanywhere.net/HTTPRX/SendSMSEx.aspx" void execute(Map parameters){ sendSMS(parameters.get("Originator")) } void sendSMS(String MSISDN) { if (!MSISDN.startsWith('+')) { /* * TextAnywhere inbound call does not have "+" at the beginning, however * outbound call requires it. This seems like a bug, so we have safety check to deal * with it either way */ MSISDN="+"+MSISDN } def conn = new URL(SEND_ENPOINT).openConnection() conn.requestMethod="POST" conn.doOutput=true conn.outputStream.withWriter("ASCII") { writer -> [ "Billing_Ref":BILLING_REF, "Body":"Hello, World!", "Client_ID":CLIENT_ID, "Client_Pass":CLIENT_PASS, "Client_Ref":CLIENT_REF, "Connection":CONNECTION_ENTERPRISE, "DestinationEx":MSISDN, "Originator":ORIGINATOR, "OType":"0", "Reply_Type":"0", "SMS_Type":"0" ].each { writer.write(”&” + URLEncoder.encode(it.key,”UTF-8″) + “=” + URLEncoder.encode(it.value,”UTF-8″)) } } sendResult = conn.inputStream.text } }
