Custom VBScript Code - Valentines Greetings (kb2339)

Le informazioni contenute nel presente articolo riguardano i seguenti prodotti:

  • SwyxWare from version 4
  • Graphical Script Editor v4.00

[ Riepilogo | Informazioni | Referenze ]


The SwyxWare Distributor

Cliccare per ingrandire...

from the Netherlands had run a special Valentines Phone- or Greetings-EMail campaign on the 14th of February, 2003.

A user was able to register for free on a webpage to get a PIN. With this PIN he was able to leave a Valentines greeting on a chargeable phone number. After the greeting was recorded as WAV file it was sent via EMail attachment to a given address on the Valentines day.

This article describes the GSE script to record the greeting which was developed in less than an hour. It is therefore an excellent example for how effective and creative one can use the SwyxWare.


This is how a call will be handled

  • Call will reach the SwyxWare
  • An announcement will be played
  • The user enters a PIN using DTMF
  • The PIN will be checked against a database:
    • invalid PIN: re-enter the PIN
    • valid PIN: the script goes on
  • An announcement will explain how to record the valentines message
  • The message will be recorded
  • An IVR menu with these submenus follows:
    • 1 Playback the recorded message
    • 2 Re-record the message
    • 3 Save message and end script

Valentines Script in GSE
Valentines Script in GSE
Cliccare per ingrandire...


Installation of the Scripts

  • Unzip the ZIP file including its subdirectories.
  • Copy all files within the Voicemail directory into users Voicemail directory, e.g. C:\Documents and Settings\All Users\Application Data\ Swyx\Share\User\Valentines\PhoneClient\Voicemail
  • Open the Call Routing Manager of the desired user and create a new GSE rule.
  • Import the file valentines.rse into the GSE using the menu File | Import... and save it as active rule.
  • Create a directory D:\Valentines in which all recorded message will be copied to. If you want to use another directory you have to change the second statement within the VBScript Code: ' Folder to store all messages in (with tailing "\")
    Const SAVE_DIR = "d:\valentines\"


Installation of the Database

  • Copy the MS Access™ database file valentines.mdb into a folder of your choice.
  • Create a so called ODBC Datasource for this database. To do so open ODBC Datasource Administrator via Start | Programs | Administrative Tools. If you don't see the Administrative Tools menu item you'll have to enable it in the properties of the taskbar first.

    ODBC Datenquellen-Administrator
    ODBC Datenquellen-Administrator
    Cliccare per ingrandire...
    Create a new System-DSN:

    add Swystem-DSN
    add Swystem-DSN
    Cliccare per ingrandire...
    on base of an Microsoft Access Driver:

    Microsoft Access Driver
    Microsoft Access Driver
    Cliccare per ingrandire...
    Set the name of the datasource to valentines and connect it with the Access file on your harddisk. Later on the script will access the database using the configured datasource name.

    configure datasource
    configure datasource
    Cliccare per ingrandire...


    How the Script works

    Beside the standard GSE blocks there are three additional functions being implemented in custom VBScript code.

    Custom VBScript Code
    Custom VBScript Code
    Cliccare per ingrandire...

    This three functions are derived from the specification of the application:

    • Check the PIN against the database
    • Playback the recorded message
    • Save the recorded message with a specific filename in the given folder and update the database


    The function "ValidPin()"

    This function will be called using the Evaluate block Valid PIN ?:

    Call of the PIN Validation
    Call of the PIN Validation
    Cliccare per ingrandire...

    The function gets the entered PIN as parameter. The connect string to the database DB_DSN is defined in the first statement of the custom VBScript code ' Data Source Name
    Const DB_DSN = "valentines"
    and can be altered there if necessary.

    Function ValidPin ( sPin )
    Dim bReturn bReturn = false
    ' open connection to database Dim db Set db = CreateObject("ADODB.Connection") db.Open DB_DSN
    ' open recordset Dim sSQL Dim rs sSQL = "select * from users where pin = '" _ & sPin & "'"
    Set rs = CreateObject("ADODB.Recordset") rs.Open sSQL, db, adOpenDynamic, _ adLockOptimistic, adCmdText bReturn = not rs.EOF
    rs.Close Set rs = Nothing
    db.Close Set db = Nothing
    ValidPin = bReturn
    End Function
    The function reads all records from the users table of the database with the given PIN in its pin field. The EOF flag will be used to determine if there are any results. The flag is set to True if there are no results, so there are no users with this PIN in the database. Since the function ValidPin() should return False in this case we have to negate it.



    The function "PlayLastMessage ()"

    This function will be called using the Set Variable block Play Message. Please note that we use this block just for calling the function. We are not interested in its return value.

    The GSE currently do not have a simple to get the name of the the last recorded maeesage, but we can use its scripting interface to do it:

    Function PlayLastMessage ()
    Dim retVal Dim sFileName
    ' get name of last recorded file sFileName = PBXCall.LastRecordedMessage ' play last recorded file retVal = PBXCall.PlayMessage(sFileName)
    PlayLastMessage = True
    End Function


    The function "SaveMessage()"

    This function does the following:

    • The recorded message will be stored in the defined SAVE_DIR directory with a name PIN.WAV, where PIN is the PIN of the current user.
    • The complete filename including the path will be stored in the user's record in the database.
    This function will also be called using a Set Variable block Save Message and again we do not care about the return value.

    Call of the
    Call of the "SaveMessage()" function
    Cliccare per ingrandire...



    Function SaveMessage( sPin )
    Dim sFileName, sNewFileName
    ' get name of last recorded file sFileName = PBXCall.LastRecordedMessage ' cal new file name sNewFileName = SAVE_DIR & sPin & ".wav" ' create FileSystemObject Dim fso Set fso = CreateObject("Scripting.FileSystemObject") fso.CopyFile sFileName, sNewFileName Set fso = Nothing
    ' open connection to database Dim db Set db = CreateObject("ADODB.Connection") db.Open DB_DSN
    ' update record Dim sSQL sSQL = "update users set message = '" & _ sNewFileName & "' where pin = '" & _ sPin & "'" db.Execute(sSQL)
    db.Close Set db = Nothing
    SaveMessage = True
    End Function



    Please note that the announcements within the ZIP file are not the ones being used during the valentines camgain, but instead are just some test announcements.

    Further informations about the valentines campaign

    The campaign was of course more then just this GSE script. On the following webpages one was able to login to it:

    The Webpages where created by the company Web Power ( who where also responsible to sent all the valentines emails.

  • Referenze

    As far as software supplied or used by us, includes open source elements the additional terms under apply in addition. An overview which products from the Swyx portfolio include open source elements and which open source license is relevant can be found under

    Informazioni di altri produttori proposte in questo articolo hanno il compito di appoggiare la ricerca di informazioni tecniche. I contenuti potrebbero essere modificati senza preavviso. Swyx non garantisce per la veridicità dei contenuti di articoli di terzi e declina ogni responsabilità per essi.


    L'articolo è stato utile? Lasci un commento all'articolo

    Come possiamo contattarLa se dal Suo commento dovessero nascere altri quesiti?

    Indirizzo e-mail Adresse (facoltativo)


    Il campo destinato ai commenti non è ammesso per richieste all'assistenza. Per quesiti inerenti l'assistenza rivolgersi esclusivamente al proprio rivenditore di fiducia o al distributore competente.