Navigation: How to... > Scripting examples > Gateway scripting examples >
Dispatch SMS to gateways
Learn how to use a C# or Visual Basic .NET script with Diafaan SMS Server to send an SMS message through a specific gateway, depending on the GSM number.
In this scenario three gateways are defined, GSM Modem 1, GSM Modem 2 and Clickatell. SMS messages to British GSM numbers should be sent with GSM Modem 1 and messages to French GSM numbers to GSM Modem 2. All messages to other destinations should be rejected. For both destinations the Clickatell gateway is used as a backup gateway. The maximum send attempts on both GSM modems is 2, this is indicated in the script with "GSM Modem 1:2" and "GSM Modem 2:2".
The only adaptation to the skeleton script is in the OnMessageToSend event:
private void OnMessageToSend(string recordId, string toAddress, string fromAddress,
"GSM Modem 1:2", "Clickatell");
"GSM Modem 2:2", "Clickatell");
"Error: Invalid country destination", "", "", false);
Visual Basic .NET script:
Private Sub OnMessageToSend(recordId As String, toAddress As String, _
fromAddress As String, message As String, _
messageType As String)
"GSM Modem 1:2", "Clickatell")
"GSM Modem 2:2", "Clickatell")
"Error: Invalid country destination", "", "", False)
If you make any change to the script make sure that the PostSendResult or PostDispatchMessage is always called, even if an exception is caused. Otherwise the script will only continue with the next message after a timeout of several minutes.
To enhance performance when a large amount of messages is sent, you can set the MaximumBatchSize in the Advanced properties to a higher value.