Lua Services
Introduction
A Lua service is the inbound point which triggers the execution of a Lua script within the LogicApp application, in response to a new inbound transaction initiated by some external entity.
The Lua Service is responsible for the setup and tear-down of a LogicApp script instance:
- Choosing which Lua script to execute.
- Supplying arguments to the Lua script when it begins.
- Handling the final result returned by the Lua script.
- Optionally providing additional service-related actions to the script.
Since the service implements all of the underlying infrastructure, the Lua script needs only to perform the business logic:
- Process the arguments which are provided to it.
- Return some final result.
- Call supplementary Lua Service actions (if required).
- Call other Lua Agent functions (if required).
This Technical Guide describes the core Lua Services provided as part of the base n2svcd
package. Other protocol-specific Services are delivered by other packages, e.g. Services
related to SIP functionality are delivered by the n2sip package.
Configuring Services
Each Service must be configured within the LogicApp, within the <config><services> element,
each Service is a separate <service> definition.
Each Service running within the LogicApp is associated with a single inbound message name.
When the LogicApp receives a new inter-application message of that name, it will look
down the configured list of Services and offer the message to each Service which is associated
with that message name.
Each Service will be given the chance to claim the message. If a Service does not claim
the message (e.g. because it has no matching <triggers>) then it can decline the message,
which will allow the LogicApp to offer it to any other Services further down the list.
For example:
- The
RestLuaServicemay claim aREST-S-REQUESTmessage which is generated by aRestServerApp. - The
LhoSipIncallLuaServicemay claim aSCC-HANDLE-ALEG-INBOUND-INVITEmessage which is generated by aLhoSipApp.
Service Actions
Each script is initiated by a single Service library, initiated by some received message or event. That service will typically offer additional actions that the script can use to perform interactions during the processing.
For example:
- A Lua script initiated by a received REST request may use a service action to reply with an early REST response.
- A Lua script initiated by a MAP ProcessedUSSDRequest may perform USSD Menu interactions to the handset.
- A Lua script initiated by an inbound SIP call may perform RTP Audio interactions with the caller.
Agent Actions
In addition to the actions provided by a services, the Lua script may freely call upon Lua Agents to perform its work.
Any actions supplied by agents are independent from the actions provided by the script’s Service.