How can we help?

Trigger on incoming messages and state changes


Overview

Using triggers is a great way to integrate the SMS Server into your own back-end or to build your own custom SMS application that interacts with your customers or employees.

Triggers are used to automatically process messages when they change state. The most common use case for trigger is reacting to incoming SMS messages.

A trigger runs a small user defined or generated script. Within this script everything is possible. For instance: Creating an automatic reply message based on the content of the SMS message.

To view triggers:

  1. Open the SMS Server manager
  2. Click on ‘Triggers’ in the tree view on the left.
View triggers

View triggers

There are three types of triggers:

  • Javascript – This will run a custom JavaScript
  • VBScript – This will run a custom Visual Basic Script
  • SQL Script – This will run a custom SQL query or starts a custom stored procedure

Creating a new trigger

You can create a new trigger by clicking ‘New Trigger’. This will start the trigger wizard.

Select a trigger template

Select a trigger template

The first page of the trigger wizard is the trigger select screen. This is where you select the template to start out with.

Empty triggers will just generate the skeleton of a script. The other templates will walk you through a couple of steps to collect all information required to automatically create a working script.

This means that for most common use cases no programming code is required at all.

The following use cases can be setup by using generated scripts and require either no programming or at all or very little programming:

  • Automatically forwarding a message. E.g SMS to E-mail, E-mail to SMS or convert new files on the filesystem to SMS messages, etc.
  • Automatically replying to a message, optionally based on a Web query or a database query.
  • Applying the status of  a delivery report to the original message.
  • Authorizing logins on the SMPP Server channels.
  • Subtracting credits for incoming SMPP Server messages.
  • Forwarding the message delivery status to SMPP Server clients.

Edit an existing trigger

A trigger has two parts:

  • The trigger script
  • The trigger condition

Both of these can be edited and fine-tunes after the trigger is generated by the trigger wizard. Clicking the ‘Edit’ icon on the right side of the trigger view will open the trigger editor.

Edit trigger - Condition

Edit trigger – Condition

The dialog has two tabs. The first tab to open edits the condition of the trigger. The condition of the trigger is a SQL expression that will capture all messages that this condition will trigger on.

The message type of the trigger and the message status are already a part of the condition and do not need to specified in the SQL expression.

The second tab, depending on the trigger type. Is either ‘VBScript’, ‘JavaScript’ or ‘SQL Script’.

VBScript and JavaScript triggers

Edit trigger - Script

Edit trigger – Script

This is where you can edit the script or select a different script. The ‘Function’ specifies the function in the script that is called by the SMS Server if the trigger condition matches.

The ‘Support attachments’ check-box is relevant when processing e-mail messages. If e-mail attachments are not important in the trigger script then it makes sense to leave this unchecked to save processing time.

SQL triggers

Edit trigger - SQL Script

Edit trigger – SQL Script

With SQL triggers the script is not stored in an external file but instead it’s stored in the database.

Just like with VBScript and JavaScript triggers the SQL Script triggers can make use of the fact that the SMS Server has already loaded the message data into memory when running this trigger: Any message fields that you want to use in your script you can prefix with ‘@fld’ to have them immediately available.

You can find out which fields are available and insert them automatically by using the ‘Insert Field’ button.

Insert field

Insert field