Documentation Contents | User Documentation | Administrator Documentation | Index of terms | Technical Support | On-line Search |
Scripting application programming |
This document describes programming of script applications for MobilChange. It assumes that the reader has knowledge of VBScript or Visual Basic language.
Content
All user script applications run in UMS.TaskManager service environment. It checks their functioning and restarts them if necessary. Scripts are run inside Windows Scripting Host.
User applications are stored under MobilChange/script/
folder.
Various sample applications can be found in MobilChange/samples/
folder. How to use them is commented directly
in source code.
Libraries are linked to the user code by this command:
'#include "file.vbs" |
Filename in quotations can contain also path relative to the MobilChange/script/ folder.
During UMS.TaskManager starting is inside "startup" task MX_<task name>
compiled file
MobilChange/script/<task name>.vbs
, attached includes and resulting file is stored into
MobilChange/script/run/<task name>.vbs
. This file is then executed.
So if VBscript interpreter reports syntax error on line 200, you must find line 200 in compiled file
under MobilChange/script/run/
folder, repair error in source file in
MobilChange/script/
folder and finally restart UMS.TaskManager to recompile the script.
Information stated above are valid until MobilChange version 4.6.23. Higher versions do not use including - it was replaced by WSF jobs technology:
MobilChange/script/<task name>.wsf
file, which is executed by "normal" task - there is
no "startup" task
MobilChange/script/run/
Option Explicit '#include "include\mx_script_app.vbs" |
OnInit
function is called after all necessary initialization is finished. This function
takes three parameters which must be initialized.
AppName |
The script must fill this variable with its own name (the name used when it was added into the system). |
ServerName |
Application enters the name of MobilChange server to be worked with here.
Local server (the computer running this application) is identified using empty string ("").
In present version, enter empty string only. |
IddleTime |
Here the script specifies how often is OnIddle function to be called.
The amount of time entered is in milliseconds. Minimum value recommended is 5000, maximum is 60000. When UMS.Taskmanger is being
stopped it waits for this amount of time for script application finishing. So don't set too high value to not delay Taskmanager
for a long period of time. |
(Return |
Text string "OK" if everything is correct, "ERROR" string in case that an error occurred. When the user code returns "ERROR", the script is terminated and then restarted. |
Here is an example of a complete function OnInit()
:
Function OnInit( AppName, ServerName, IddleTime ) AppName = "pizza" ' application "pizza" ServerName = "" ' local server IddleTime = 10000 ' 10 seconds, recommended ' There can be done additinal initialization tasks OnInit = "OK" ' return status End Function |
OnReceivedSMS()
is called. This function is passed information about
SMS in three parameters. However this function is here only for backward compatibility. Preferred way of processing incoming messages is to use
OnNotification() function, which also receives information about incoming SMS and has extended data available for every message.
FromNumber |
The phone number of the sender in international format. |
TimeReceived |
Time the SMS was received in the following form of text string: YYYY/MM/DD hh:mm:ss |
MessageBody |
Text of the received SMS. |
(Return |
Text string "OK" if everything is correct, "ERROR" string in case that an error occurred. When the user code returns "ERROR", the script is terminated and then restarted. The SMS stays in the queue and it will be passed to the script after restarting. |
A complete example of the OnReceivedSMS()
function in Pizza user application.
It answers the received SMS and pastes a copy of the original message into it.
Function OnReceivedSMS( FromNumber, TimeReceived, MessageBody ) Dim rc MXLog "Working on received SMS..." MXLog "Sending reply..." rc = MobilChange.SendSMS( FromNumber, "PIZZA SERVICE: You have ordered pizza -" + MessageBody + "- from phone number " + FromNumber + ".", True ) MXLog "MobilChange.SendSms() = " & rc If rc <> "OK" Then MXLog "ERROR: " + MobilChange.LastError End If OnReceivedSMS = "OK" ' return status End Function |
OnNotification()
user fuction is called with these
parameters:
MessageType |
Type of message. Possible values:
|
Attr |
Attribute collection of the message, it is instance of FxExtObj.DSVariantCol object. Collection can contain these items:
|
(return |
Text string "OK" if everything is correct, "ERROR" string in case that an error occurred. When the user code returns "ERROR", the script is terminated and then restarted. The SMS stays in the queue and it will be passed to the script after restarting. |
OnIddle()
in case that during the specified period (set by the user in OnInit()
) were
not received any messages. It is intended for sending device status messages, database listings etc.
(Return |
Text string "OK" if everything is correct, "ERROR" string in case that an error occurred. When the user code returns "ERROR", the script is terminated and then restarted. |
Sample of OnIddle()
function:
Function OnIddle ' There can be done anything... OnIddle = "OK" ' return status End Function |
OnShutdown()
function is called by system when
UMS.TaskManager is being terminated, for example when shutting down the computer.
It allows closing database connections, deleting temporary files etc.
(Return |
Text string "OK" if everything is correct, "ERROR" string in case that an error occurred. When the user code returns "ERROR", the script is terminated and then restarted. |
Sample of OnShutdown()
function:
Function OnShutdown ' There can be done anything... OnShutdown = "OK" ' return status End Function |
MobilChange.SendSMS()
function sends an SMS. The syntax is:
MobilChange.SendSMS( to, text, nomodify )
MobilChange.SendSMS( to, text, nomodify, fromName, fromSMTP, fromEmail, language, DR )
to |
(text string) The phone number of recipient. |
text |
(text string) Text of message. |
nomodify |
(True/False) If is True , the text of message is being sent in exact form as was entered
by application. If is False , the text is processed via MobilChange server the same way as
sent e-mails, i.e. the spaces are skipped, decoded czech etc. |
fromName |
(text string) The name of user whos name is used by application when sending SMS.
The delivery report will be sent to this name. |
fromEmail |
(text string) E-mail address of the user, who is used by application when sending SMS,
but only in the range of local e-mail system (i.e. ex. EX: address of Exchange server).
The delivery report will be sent to this address. |
fromSMTP |
(text string) SMTP address of the user who is used by application when sending SMS.
This address is used for formating an outgoing SMS (if NoModify=False). |
language |
(text string) User's language code, whos used by application when sending SMS.
You can use the same codes, as used in MobilChange - a names of subdirectories in MobilChange/data/ directory, ie. CZ, UK, GE... |
DR |
(True/False) If is True , the delivery report is required. If is False , the
delivery report is not required. |
(return |
Text string "OK", when everything is alright, string "ERROR" in the case when an error has occured. |
Usage example:
Dim rc rc = MobilChange.SendSMS( "+420603899285", "Hello, World!", True ) MXLog "MobilChange.SendSms() = " & rc If rc <> "OK" Then MXLog "ERROR: " + MobilChange.LastError End If |
MobilChange.SendSMSEx()
sends SMS message, but it has more options than SendSMS(). Syntax is as follows:
MobilChange.SendSMSEx( To, Text, Nomodify, fromName, fromEmail, fromSMTP, language, DR, SendNotify, Priority, UserAppId, OtherOptions )
To |
(text string) The phone number of recipient. |
Text |
(text string) Text of message. |
NoModify |
(True/False) Pokud je If is True , the text of message is being sent in exact form as was entered
by application. If is False , text is processed via MobilChange server in the same way as sent e-mails, i.e. the spaces are
removed, czech is recoded etc. |
FromName |
(text string) The name of user whos name is used by application when sending SMS. Use "$Aapp_name" here (without quotations).
The delivery report will be sent to this name. |
FromEmail |
(text string) E-mail address of the user, who is used by application when sending SMS, but only in the range
of local e-mail system (i.e. EX: address of Exchange server). Use "$Aapp_name" here (without quotations).
The delivery report will be sent to this email. |
FromSMTP |
(text string) SMTP address of the user who is used by application when sending SMS. Use "$Aapp_name" here
(without quotations). This address is used during formatting of the message being sent, if NoModify=False. |
Language |
(text string) User's language code, which is used by application when sending SMS.
Delivery report will be sent in this language. Use "AA" for applications (without quotations). |
DR |
(True/False) If True , delivery report is required.
if False , application doesn't request delivery report. |
SendNotify |
(True/False) If True , information about sending into SMS center is required.
If False , application doesn't require information about sending into SMS center. |
Priority |
(text string) Message priority. Allowed values: "high", "normal", "low" (without quotations). |
UserAppId |
(text string) Message application identifier. If it is used, it can be found also in report about sending/(non)delivering, so application knows which message is related to. |
OtherOptions |
(text string) Other settings, separated by "|". Available settings:
|
(return |
Text string "OK", when everything is alright, string "ERROR" in the case when an error has occured. |
MobilChange.LastError
property contains text description of the last error resulting from the script subsystem of MobilExChange.
A sample usage can be found in the description of MobilChange.SendSMS() function.
MXLog
function is used for logging program events.
By default, events are written on console listing only when using debugging mode of
UMS.TaskManager service. Syntax:
MXLog text
A sample usage can be found in the description of MobilChange.SendSMS() function. Function has no return value.
New from MobilChange 3.0: MXLog function can also write the message text into log file
"\Mobilchange\log\<date-YYYYMMDD>.<script-name>.txt".
Using of filelog is set in registry:
HKLM\Software\Datasys\MobilChange\Scripting\<script-name>\LogLocalSetting
(Dword) for every script.
HKLM\Software\Datasys\MobilChange\Scripting\LogGlobalSetting
(Dword) for new scripts (read at first run of new script and copied
into HKLM\Software\Datasys\MobilChange\Scripting\<script-name>\LogLocalSetting
)
MXSendMail
send an e-mail message (regardless on type of e-mail server you're using).
Syntax:
MXSendMail(SenderName, SenderEmail, RecipientName, RecipientEmail, Subject, Text, Priority)
where Priority is number - 1 (low), 2 (normal) nebo 3 (high). If you are using Lotus Notes gateway, then SenderName, SenderEmail parameters are ignored - they are taken from Notes ID of the user, under which context gateway runs.
Return value is text string
Sample of usage:
rc = MXSendMail ("SMS server", "smss@yourfirm.com", "Charles Brown", "cbro@hotmail.com", "Automatic reply", _ "Your SMS from " & FromNumber & " was received and processed at " & Now, 2) |
MxDeleteSMS
allows to delete incoming SMS any time during processing. Standard behavior is like this:
MxDeleteSMS
Sample of usage:
Function OnReceivedSMS( FromNumber, TimeReceived, MessageBody ) MxDeleteSMS ... SMS processing continues here ... |
Adding of scripts into MobilChange is described thoroughly in this document.
For editing forwarding rules use MxRouteCfg program.
Now click on the icon in the upper left corner of the console window and select "Properties", "Layout" tab and set "Screen buffer size" "Height" to 9999. When finished, click "OK" and "Save settings for all windows with same title". A scrollbar will appear on the right side of the console window so you can view older outputs. Press a [Pause]/[Break] key to pause all running programs and their output, pressing any key will activate them.
Press "Ctrl-C" keys in the console window to stop UMS.TaskManager debugging (this applies also for running script as described below).
Another option is to disable task being debugged in umsTaskCfg and run it "manually" from command prompt by this command:
cscript script_name.wsf
or, if you require to use debugger, by:
cscript //X //D script_name.wsf
If you want your application to run in a separate window (so its output was not mixed with the output of other UMS.TaskManager applications), press "Ctrl-C" to quit UMS.TaskManager, and using umsTaskCfg switch "Share console" setting off for this application (in normal tasks). Then start debugging again.
Warning for VoiceChange users: VoiceChange also uses UMS.TaskManager. VoiceChange will not therefore service any incoming calls during the time when UMS.TaskManager is stopped (not running either as a service nor in debugging mode)!