Skip to content

How to add FrontlineSMS Transport Services

geoffreymuchai edited this page Oct 24, 2012 · 3 revisions

About FrontlineSMS Transport Services

FrontlineSMS transport refers to the different connection avenues available within FrontlineSMS for sending and receiving messages. The default supported transport channels are Modems but we have extended this functionality to include Bulk SMS aggregators such as Clickatell or IntelliSMS. When SMS messages are being sent out, internet routes(Bulk SMS aggregators) are given a higher priority over modem-based connections by default.

How to add a new FrontlineSMS transport service

Domain Class Setup

Every Connection within FronlineSMS is extended from the super Class Fconnection. To add a new type of connection to FrontlineSMS, create a new groovy class within the directory "frontlinesms2/plugins/frontlinesms-core/grails-app/domain/frontlinesms2/". For the purpose of this guide, we shall create a new Fconnection called ClickatellFconnection.groovy

package frontlinesms2

class ClickatellFconnection extends Fconnection {}

Add this new Fconnection to the list of Fconnection implementation represented by static def implementations on the Fconnection class.

Since the UI is automatically generated, the following variables have to be specified your new ClickatellFconnection

  • static final configFields = [] This variable specifies the fields to be whose values need to be specified from the setup Wizard
  • static final defaultValues = [] This variable specifies the default values for the above configurable fields
  • static String getShortName() { 'clickatell' } This variable specifies the short name of the new connection.

To connect to the routing technology used within FrontlineSMS, override the getRouteDefinitions method in Fconnection to include the configuration information required to send messages to the required SMS Aggregator. You can add additional Camel processor beans as required to the transport route within this method.

View Setup

Add internationalized message codes to the "frontlinesms2/plugins/frontlinesms-core/grails-app/i18n" files to ensure that the users are able to read through the connection setup.

Conclusion

If you encounter any problems while implementing new transport services, you can contact the developer team here

Here is example source code of a new Fconnection

package frontlinesms2
import frontlinesms2.camel.clickatell.*
import org.apache.camel.Exchange
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.model.RouteDefinition
import frontlinesms2.camel.exception.*
class ClickatellFconnection extends Fconnection {
	private static final String CLICKATELL_URL = "http://api.clickatell.com/http/sendmsg?"
	static final configFields = ["name", "apiId", "username", "password"]
	static final defaultValues = []
	static String getShortName() { "clickatell" }
	
	String apiId
	String username
	String password // FIXME maybe encode this rather than storing plaintext
	
	static passwords = ['password']

	static mapping = {
		password column: 'clickatell_password'
	}
	
	List<RouteDefinition> getRouteDefinitions() {
		return new RouteBuilder() {
			@Override void configure() {}
			List getRouteDefinitions() {
				return [from("seda:out-${ClickatellFconnection.this.id}")
						.onException(AuthenticationException, InvalidApiIdException)
									.handled(true)
									.beanRef('fconnectionService', 'handleDisconnection')
									.end()
						.setHeader(Fconnection.HEADER_FCONNECTION_ID, simple(ClickatellFconnection.this.id.toString()))
						.process(new ClickatellPreProcessor())
						.setHeader(Exchange.HTTP_QUERY,
								simple('api_id=${header.clickatell.apiId}&' +
										'user=${header.clickatell.username}&' + 
										'password=${header.clickatell.password}&' + 
										'to=${header.clickatell.dst}&' +
										'text=${body}'))
						.to(CLICKATELL_URL)
						.process(new ClickatellPostProcessor())
						.routeId("out-internet-${ClickatellFconnection.this.id}")]
			}
		}.routeDefinitions
	}
}