SMPP Lua Service

Introduction

The SMPPLuaService is a service for initiating Lua scripts running within the LogicApp.

The SMPPLuaService receives an SMPP message from instances of the SMPPApp which is configured to receive SMPP messages from an external entity.

The SMPPLuaService communicates with the SMPPApp using SMPP-S-REQUEST messages.

Configuring SMPPLuaService

The SMPPLuaService is configured within a LogicApp instance.

    <?xml version="1.0" encoding="utf-8"?>
    <n2svcd>
      ...
      <applications>
        ...
        <application name="Logic" module="LogicApp">
          <include>
            <lib>../apps/logic/lib</lib>
          </include>
          <parameters>
            ...
          </parameters>
          <config>
            <services>
              <service module="SMPPApp::SMPPLuaService" libs="../apps/smpp/lib" script_dir="/var/lib/n2svcd/logic/smpp">
                <triggers>
                  <trigger pdu="deliver" source="641234567" destination="123" script_name="123"/>
                  <trigger pdu="submit" source_prefix="64" destination_prefix="123" script_name="123"/>
                </triggers>
              </service>
            </services>
            <agents>
              ...
            </agents>
          </config>
        </application>
        ...
      </application>
      ...
    </n2svcd>

In addition to the Common LogicApp Service Configuration, note the following specific attribute notes, and service-specific attributes.

Under normal installation, the following service attributes apply:

Parameter Name Type XML Type Description
module String Attribute [Required] The module name containing the Lua Service code: SMPPApp::SMPPLuaService
libs String Element Location of the module for SMPPLuaService.
(Default: ../apps/smpp/lib)
script_dir String Attribute [Required] The directory containing scripts used by this service.
.triggers Array Element Array of trigger elements specifying Lua scripts to run for SMPP Inbound Transactions.
.trigger Object Element Provisions a Lua script to run for an SMPP Inbound Transaction for a destination/source party.

Script Trigger Rules

Each SMPP trigger rule defines the name of a script which is ready to handle an SMPP Inbound Transaction.

Note that destination and source addresses may contain hex digits A-F, and the matching is for destination_prefix and source_prefix is case-insensitive.

Each trigger Object in the config.triggers Array is configured as follows.

Parameter Name Type XML Type Description
destination String Attribute This trigger only applies for SMPP messages to this exact destination party.
(Default = Trigger applies to all SMPP messages).
destination_prefix String Attribute This trigger applies for only SMPP messages to destination parties starting with this prefix.
(Default = Trigger applies to all SMPP messages).
source String Attribute This trigger applies for only SMPP messages from this exact source party.
(Default = Trigger applies to all SMPP messages).
source_prefix String Attribute This trigger applies for only SMPP messages from source parties starting with this prefix.
(Default = Trigger applies to all SMPP messages).
script_name String Attribute The name of the Lua script to load (excluding the ".lua" suffix). The script should reside in the directory configured for the LogicApp's lua_script_dir, or in the specified subdirectory if script_subdir is configured for this service library.

Script Selection (SMPP Transaction Request)

The Lua Script selection to execute for an SMPP message takes into consideration the source and destination addresses.

The destination address for matching is the SMPP parameter destination_addr.

The source address for matching is the SMPP parameter source_addr.

The SMPPLuaService will iterate the configured trigger entries in the sequence given and use the first trigger that matches the parameters of the received message.

Refer to the LogicApp configuration for more information on directories, library paths, and script caching parameters.

Script Global Variables

Scripts run with this service have access to the Common LUA Service Global Variables.

There are no service-specific global variables.

Script Entry Parameters (SMPP Request)

The Lua script must be a Lua chunk which returns an n2svcd.handler, such as the following:

local n2svcd = require "n2.n2svcd"

local handler = function (smpp)
    n2svcd.debug ("Received...")
    n2svcd.debug_var (smpp)

    return {
        command_status = 0;
    }
end

return n2svcd.handler (handler)

The handler will be executed with a single smpp entry parameter which takes the same format as the smpp object of the received SMPP-S-REQUEST message.

Script Return Parameters (SMPP Response)

The Lua script is responsible for determing the contents of the response SMPP deliver_sm_resp or submit_sm_resp (as appropriate to the received SMPP message) that will be sent back to the message source.

The script return value must be a response object which takes the same format as the smpp object of the SMPP-S-RESPONSE message.

Example (returning a successful response):

local n2svcd = require "n2.n2svcd"

local handler = function (smpp)
    return {
        command_status = 0;
    }
end

return n2svcd.handler (handler)

The SMPPLuaService API

The SMPPLuaService does not have any distinct API methods. However, the SMPPLuaAgent API methods may be used as required.

Note that it is not necessary to load the SMPPLuaAgent API if you are only using the simple response mechanism described above. It is only required if you wish to use any of the extended features described.