ActiveXperts SMS Messaging Server

Quicklinks

Create an SMS message using the SMS Messaging Server API - VBScript

SMS Messaging Server is an SMS messaging framework that enables companies to send, receive and process SMS- and e-mail messages. The framework is designed support virtually any scenario where low-and high volume SMS messaging is required. Use SMS Messaging Server in the following scenarios:

  • Mobile users query a database; results are sent back via SMS or e-mail;
  • Mobile users receive important information via SMS or e-mail while they are away from the office;
  • Stock prices are sent automatically via SMS and/or e-mail, daily;
  • Remote workers can update their worksheet from a remote location trough SMS;
  • ICT administrators restart/reboot servers and/or daemons from remote by SMS;
  • Setup an SMS voting system, supporting SMS and/or e-mail;
  • Etc.

SMS Messaging Server can be well integrated into VBScript environments. This document describes how the SMS Messaging Server can be integrated into your own projects.


Introduction

In this example we are going to create a VBScript sample page to create an SMS using the ActiveXperts SMS Messaging Server API. The SMS Messaging Server service will send the message you created in the database.

Step 1: Download and install SMS Messaging Server

Download ActiveXperts SMS Messaging Server from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new script

Create a new script using your favorite editor. You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.

You're now able to write a more advanced VBScript program to create new messages.

Step 3: Create the SMS Messaging Server API objects

Create a new VBScript file called DEMO.VBS. It is recommended to insert the following line on top of your code:

Option Explicit

This statement requires that all variable names be defined (with the Dim statement), to avoid simple typos that can cause incredible headaches and long debugging sessions for something that should have never happened.

Now, declare the MessageDB and Constants objects:

Dim objMessageDB Dim objMessage Dim objConstants

Create the MessageDB and Constants objects:

Set objMessageDB = CreateObject( "Axsms-messaging-server.MessageDB" ) Set objConstants = CreateObject( "Axsms-messaging-server.Constants" )

You should not create an instance of a Message yourself; it is returned by functions like Create, FindFirstMessage, FindNextMessage and Load.

Step 4: Create the SMS message

The following VBScript code will create an empty record in the database:

' Create new message in the Message Database Set objMessage = g_objMessageDB.Create PrintResult( "Create" ) If( g_objMessageDB.LastError <> 0 ) Then g_objMessageDB.Close WScript.Quit End If

Step 5: Set message information

Here we are going to setup the information of the message.

objMessage.DirectionID = g_objConstants.MESSAGEDIRECTION_OUT objMessage.TypeID = g_objConstants.MESSAGETYPE_SMS objMessage.BodyFormatID = g_objConstants.MESSAGEBODYFORMAT_SMS_TEXT objMessage.StatusID = g_objConstants.MESSAGESTATUS_PENDING objMessage.ChannelID = 0 ' First available SMS channel objMessage.ScheduledTime = "" ' To indicate immediate schedule. ' To schedule 1 day and 2 hours in advance, specify "+1d2h0m" ' To schedule on specific date/time, specify 12/25/2005 07:30 objMessage.ToAddress = ReadInput( "Enter recipient's mobile number:", "", False ) objMessage.Body = "This is an ActiveXperts test message"

Step 6: Save the SMS message

The following code will save the message in the database. The SMS Messaging Server service will then send this message.

' Save the new values that were just assigned g_objMessageDB.Save( objMessage ) PrintResult( "Save" )

Appendix: Full source code

The following code shows how to send an SMS message using the SMS Messaging Server API:

' // ======================================================================== ' // CreateSmsMessage.vbs ' // ------------------------------------------------------------------------ ' // This VBScript sample demonstrate how to create a new sms message using ' // the ActiveXperts SMS Messaging Server API. ' // The samples makes use of three objects of the SMS Messaging Server API: ' // 1) AxMmServer.MessageDB - represents the Message Database ' // 2) AxMmServer.Message - a single message, i.e. a single record in the ' // Message Database ' // 3) AxMmServer.Constants - collection of constant values ' // For a full explanation of the SMS Messaging Server API, please read the ' // online manual at www.activexperts.com/asmssrvr/help ' // ======================================================================== Option Explicit Dim g_objMessageDB, g_objConstants Dim numRecordID, objMessage ' Create global objects Set g_objMessageDB = CreateObject( "AxMmServer.MessageDB" ) Set g_objConstants = CreateObject( "AxMmServer.Constants" ) WScript.Echo "API Module: " & g_objMessageDB.Module WScript.Echo "API Build: " & g_objMessageDB.Build & vbCrLf ' Open the Database g_objMessageDB.Open PrintResult( "Open" ) If( g_objMessageDB.LastError <> 0 ) Then WScript.Quit End If ' Create new message in the Message Database Set objMessage = g_objMessageDB.Create PrintResult( "Create" ) If( g_objMessageDB.LastError <> 0 ) Then g_objMessageDB.Close WScript.Quit End If WScript.Echo "Message successfully created, recordID: " & objMessage.ID objMessage.DirectionID = g_objConstants.MESSAGEDIRECTION_OUT objMessage.TypeID = g_objConstants.MESSAGETYPE_SMS objMessage.BodyFormatID = g_objConstants.MESSAGEBODYFORMAT_SMS_TEXT objMessage.StatusID = g_objConstants.MESSAGESTATUS_PENDING objMessage.ChannelID = 0 ' First available SMS channel objMessage.ScheduledTime = "" ' To indicate immediate schedule. ' To schedule 1 day and 2 hours in advance, specify "+1d2h0m" ' To schedule on specific date/time, specify 12/25/2005 07:30 objMessage.ToAddress = ReadInput( "Enter recipient's mobile number:", "", False ) objMessage.Body = "This is an ActiveXperts test message" ' Save the new values that were just assigned g_objMessageDB.Save( objMessage ) PrintResult( "Save" ) ' Close the database g_objMessageDB.Close WScript.Echo "Ready." ' ///////////////////////////////////////////////////////////////////////////////////// Sub PrintMessage( numID ) Dim objMessage Set objMessage = g_objMessageDB.Load( numID ) PrintResult( "Load" ) If( g_objMessageDB.lastError <> 0 ) Then WScript.Echo "Failed to load message " & numID Exit Sub End If WScript.Echo " Message # " & objMessage.ID WScript.Echo " DirectionID: " & objMessage.DirectionID &_ " (" & g_objMessageDB.GetDirectionDescription( objMessage.DirectionID ) & ")" WScript.Echo " TypeID: " & objMessage.TypeID &_ " (" & g_objMessageDB.GetTypeDescription( objMessage.TypeID ) & ")" WScript.Echo " StatusID: " & objMessage.StatusID &_ " (" & g_objMessageDB.GetStatusDescription( objMessage.StatusID ) & ")" WScript.Echo " StatusDetailsID: " & objMessage.StatusDetailsID &_ " (" & g_objMessageDB.GetStatusDetailsDescription( objMessage.StatusDetailsID ) & ")" WScript.Echo " ChannelID: " & objMessage.ChannelID ' WScript.Echo " BillingID: " & objMessage.BillingID WScript.Echo " MessageReference: " & objMessage.MessageReference WScript.Echo " ScheduledTime: " & objMessage.GetScheduledTimeString() WScript.Echo " LastUpdate: " & objMessage.GetLastUpdateString() WScript.Echo " From: " & objMessage.From WScript.Echo " ToAddress: " & objMessage.ToAddress WScript.Echo " Subject: " & objMessage.Subject WScript.Echo " Body: " & objMessage.Body WScript.Echo " Trace: " & objMessage.Trace End Sub ' ///////////////////////////////////////////////////////////////////////////////////// Sub PrintResult( strFunction ) ' NOTE: For a complete list of error codes, please visit ' http://www.activexperts.com/support/errorcodes WScript.Echo strFunction & ", result: " & g_objMessageDB.LastError End Sub ' ///////////////////////////////////////////////////////////////////////////////////// Function ReadInput( ByVal strTitle, ByVal strDefault, ByVal bAllowEmpty ) Dim strInput, strReturn Do strInput = inputbox( strTitle, "Enter value", strDefault ) If ( strInput <> "" ) Then strReturn = strInput End If Loop until strReturn <> "" Or bAllowEmpty ReadInput = strReturn End Function

You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-messaging-server. There are many other working samples included with the product or on the FTP site.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The SMS Messaging Server project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.