A simple text messaging alert using an SMS gateway

Below is a simple alert processor based on the EnsLib.HTTP.OutboundAdapter  to send text alerts via an SMS Gateway service. Typically, all that is needed to send an HTTP Post to the gateway service is the destination phone number, a source phone number, credentials, and the URL.

The code below is based on the Anveo gateway whose interface is as follows:

Class Hospital.TextMessageAlert Extends Ens.BusinessOperation
{
Parameter ADAPTER = "EnsLib.HTTP.OutboundAdapter";
Property Adapter As EnsLib.HTTP.OutboundAdapter;
Parameter INVOCATION = "Queue";

 

/// The phone number that receives the text message alert
Property ToPhoneNumber As %String;
/// The phone number that generates the text message alert
Property FromPhoneNumber As %String;

Parameter SETTINGS = "ToPhoneNumber:Mobile,FromPhoneNumber:Mobile";

/// The alert notification
Method SendAlert(pRequest As Ens.AlertRequest, Output pResponse As Ens.Response) As %Status
{
 set tSC = $$$OK
 try 
 {
  set txtmessage = "An alert was generated from "_pRequest.SourceConfigName_" at "_pRequest.AlertTime
  set txtmessage = txtmessage _ ". Please respond to the issue." // _pRequest.AlertText
  set destination = ..ToPhoneNumber
  set action="sms"
  set credentials = "<user token>
  set from = ..FromPhoneNumber
  set tSC = ..Adapter.Get(.pResponse,"message,destination,action,credentials,from",txtmessage,destination,action,credentials,from)

 }
 catch ex
 {
 set tSC = ex.AsStatus()
 }

 return tSC
}

XData MessageMap
{
 <MapItems>
 <MapItem MessageType="Ens.AlertRequest">
 <Method>SendAlert</Method>
 </MapItem>
 </MapItems>
}

}

 

For further information on alerting see the online course Setting Up Alerts.

 

  • + 4
  • 0
  • 655
  • 5

Comments

This is great! Thanks Stuart. Is pRequest.AlertText commented out to convey that this information could be included in the text message if you'd like?

Is there a way to perform bi directional SMS alerts? In other words, receive a response from the target mobile/cell phone? 

This is possible, but I think you need to have an account of "short-number" in a cell network, so it looks like a costly solution depending on a cell provider.

Much easier to manage pretty the same thing via Telegram bot and for free. See an example of alerting with Telegram.

Thanks for the reply. Yes I thought that it would be possible via the cell/mobile network of our organisations using a SMS Gateway. Please correct me if I am wrong: So basically our network provider would supply with a number that we would configure in the Ensemble production to use the SMS Gateway. The mobile number to send to would be  a property of a request object and the actual message content stored in another property of this class. The response from the target mobile number being stored in a response object?

Thanks