Jump to content
Gold Sponsor: Data-Way IT-Consulting, Austria

  • 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.

     

     


    Tom Wellige
     Share


     Share




    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.