Jump to content

Function: CheckCallerInTextFile


Tom Wellige
 Share


Go to solution Solved by Markus Wallner,

Recommended Posts

Admin Edit: This function was restored from the Swyx Forum Archive

 

This function checks, if the current callers number is found in the given text file. 

 

The text file must be formatted with one number per line.

 

Please find the CheckCallerInTextFile function in the Function Collection (VBScript) area of the Programming References section of the SwyxPEDIA here on Swyx Forum. 

 

 

Link to comment
Share on other sites


  • 2 years later...

Hi,

 

we use this script as whitelist and it works well but the called party does show up as missed call on his swyxphone?

if the caller is on the whitelist the caller is routed to "rule executed", but the entry on the phone shoes up afterwards.

 

Any advice on how to fix this?

 

Thanks for your help!

Link to comment
Share on other sites


1 hour ago, Anonymer said:

Any advice on how to fix this?

 

How does your rule look like? Do you use a Connect To block within your rule to connect to call to the original destination after you identified it as white listed?

 

Can you export the rule as .rse file and attach it to your reply here? I am happy to take a look on it.

 

Link to comment
Share on other sites


Hi Tom,

 

the whitlisted entries do work as expected, they're forwared to the target as expected. The problem persists with entries not listed in the whitelist. Those are not getting fowarded as expected but the call shows up on the SwyxPhone as missed call, anyway.

 

CheckCallerInTextFile(true) -> True (whitlist number exists in textfile) is getting forwared as expected

CheckCallerInTextFile(true) -> NotTrue (whitlist number does not exist in textfile) is connected to a block with a redirection, but even if i try other blocks the result ist still the same (missing call entry).

Link to comment
Share on other sites


this is the script:

 

' FileOpen iomode Values
' https://www.swyxforum.com/vbscript-function-collection/functions/checkcallerintextfile-r3/

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 = True
Const fsoCreateIfNotExist     = False
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.


'----------------------------------------------------------------
' CheckCallerInTextFile
'
' Returns true if the current callers phone number can be found in a given text file.
' The text file must be formatted with one number per line.
'
' Parameter:
'   sFileName       text file (incl. path) that contains the numbers to check
'
' Return:
'   boolean
'----------------------------------------------------------------

Function CheckCallerInTextFile ( sFileName )

    sFileName = "C:\pathtodirectoryblabla\whitelist.txt"

    PBXScript.OutputTrace "-----------> CheckCallerInTextFile (" & sFileName & ")"

    Dim bReturn, sCaller, sLine
    bReturn = False

    On Error Resume Next

    sCaller = PBXCall.CallingPartyNumber
    PBXScript.OutputTrace "sCaller = " & sCaller

    Dim fso, file
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists( sFileName ) Then
        
        Set file = fso.OpenTextFile(sFileName, fsoForReading, fsoDontCreateIfNotExist, fsoTristateFalse)
        If Err = 0 Then

            PBXScript.OutputTrace "File opened"

            Do While (Not file.AtEndOfStream) And (Not bReturn)

                sLine = file.ReadLine
                PBXScript.OutputTrace "sLine = " & sLine

                ' does the number in the text file contain the given number?
                If InStr(sLine, sCaller) > 0 Then
                    bReturn = True
                    PBXScript.OutputTrace "Found!"
                End If

                ' does the number in the text file is identical to the given number?
                'If sLine = sCaller Then
                '    bReturn = True
                '    PBXScript.OutputTrace "Found!"
                'End If

            Loop

            file.Close

        Else
            PBXScript.OutputTrace "Error opening file!"
            PBXScript.OutputTrace Hex(Err) &  ": " & Err.Description
        End If

        Set file = Nothing

    Else
        PBXScript.OutputTrace "File does not exist!"
    End If

    Set fso = Nothing
    
    CheckCallerInTextFile = bReturn

    PBXScript.OutputTrace "bReturn = " & bReturn
    PBXScript.OutputTrace "<----------- CheckCallerInTextFile"

End Function

Link to comment
Share on other sites


Hi,

 

this can't have anything to do with the vbscript function and if it finds the caller in the textfile or not. It have have something to do with the way how you handle the call afterwards.

 

I would really like to see the entire call routing rule. So please export it as .rse file (File -> Export...) and attach the file here. 

Link to comment
Share on other sites


Hi Tom

 

here's the simplified RSE due to privacy reasons. There's no other rule afterwards, neither in RSE nor any manual forward or redirection in SwyxIt! itself. I don't know why the call is showing up as missed call afterwards, maybe is it written in some log file?

Whitelist.rse

Link to comment
Share on other sites


vor 14 Minuten schrieb Markus Wallner:

If the script is executed within the call routing of a certain user, i guess a call list entry will be written anyway.

In case of a blocked call you have to delete the entry:

Hi Markus,

 

yes the script is executed within the callrouting of a single user. Is it possible to delete the entry in this whitelist script within the script itself?

 

Link to comment
Share on other sites


Thanks for the .rse file. I have restructured it a little bit... (see further below)

 

When figuring that the call is whitelisted you should connect the call yourself to the called destination instead of leaving it to a following script by existing trough "Rule Skipped". You said that there are no following rules after this anymore anyway.

 

Regrding the missed call: in case of a not whitelisted caller you connect the call to another user with the "Proceed with destination script" option. This creates a new call under the hood for the other user, and for the original user this call is missed. But as Markus already hinted, you can prevent this entry into the call journal to be written by

before leaving your script (through the "Connect To" block with the "Proceed with destination script" option).

 

Here is a slightly modyfied script that should do what you wan/need:

 

image.png

 

 

Whitelist_Extended.rse

 

 

 

Link to comment
Share on other sites


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
 Share


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