Jump to content
  • LogCallIntoTextFile

    LogCallIntoTextFile

    VBScript   → Lua

     

    This function logs some details into a given log (text) file.

    Please see the Introduction chapter for some usage instructions.

     

    ' FileOpen iomode Values
    Const fsoForReading           = 1     ' Open a file for reading only.
    Const fsoForWriting           = 2     ' Open a file for writing only.
    Const fsoForAppending         = 8     ' Open a file and write to the end of the file.
    Const fsoDontCreateIfNotExist = False
    Const fsoCreateIfNotExist     = True
    Const fsoTristateUseDefault   = -2    ' Opens the file by using the system default.
    Const fsoTristateTrue         = -1    ' Opens the file as Unicode.
    Const fsoTristateFalse        = 0     ' Opens the file as ASCII.
    
    Const LogFormat = """%NUMBER%"",""%NAME%"",""%TIMESTAMP%"""
    
    
    '----------------------------------------------------------------
    ' Function LogCallIntoTextFile
    '
    ' Logs details of the current call into a text file.
    ' Line format: "Number","Name","Timestamp"
    '
    ' Parameter:
    '   sFileName   name of logfile (incl. path)
    '
    ' Return:
    '   boolean     true - log created, false - error creating log
    '----------------------------------------------------------------
    Function LogCallIntoTextFile ( sFileName )
    
        PBXScript.OutputTrace "-----------> LogCallIntoTextFile ( " & sFileName & ")"
    
        On Error Resume Next 
    
        Dim bReturn
        bReturn = False
    
        Dim fso, file, sLine
    
        ' create FileSystemObejct
        Set fso = CreateObject("Scripting.FileSystemObject")
    
        ' open text file
        Set file = fso.OpenTextFile(sFileName, fsoForAppending, fsoCreateIfNotExist, fsoTristateFalse)
        if Err <> 0 then
            PBXScript.OutputTrace "Error opening log file!"
            PBXScript.OutputTrace Err & ": " & Err.Description
        else
            ' create log line
            sLine = LogFormat
            sLine = Replace(sLine, "%NUMBER%",    PBXCall.CallingPartyNumber)
            sLine = Replace(sLine, "%NAME%",      PBXCall.CallingPartyName)
            sLine = Replace(sLine, "%TIMESTAMP%", Now)
            PBXScript.OutputTrace "sLine = " & sLine
            ' write (append) log data to file
            file.WriteLine(sLine)
            file.Close()
            Set file = Nothing
            bReturn = True
        end if
    
        Set fso  = Nothing
    
        LogCallIntoTextFile = bReturn
    
        PBXScript.OutputTrace "bReturn = " & bReturn
        PBXScript.OutputTrace "<----------- LogCallIntoTextFile"
    
    End Function

     

    This function makes use of the Server Script API functions PBXCall.CallingPartyNumber and PBXCall.CallingPartyName for the call details and PBXScript.OutputTrace to write trace information into the SwyxServer trace file.

     

     




    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.