Article
· Jan 27, 2017 2m read

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.

Discussion (5)1
Log in or sign up to continue

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