Jump to content

#7: Welcome to Babylon!


Tom Wellige

763 views

VBScript Lua

 

Have you ever had the necessity to create a call routing that somehow identifies the callers language and then provide all announcements afterwards in that language and maybe also connect to different destinations within the SwyxWare?

 

In this article I would like to show some approaches on how this could be done and also point out their pros and cons.

 

Lets assume you have a simple call routing that plays a welcome message, afterwards provide an IVR/DTMF menu and then connects the call to the selected user group or the operator if the caller can't decide or can't send DTMF:

 

image.png

 

VBScript based Call Routing

Multi_Language_1.rse

 

Lua based Call Routing

Multi_Language_1_Lua.rse

 

In this example of course you have the announcements fixed and therefore in one language only.

 

But as you have business in lots of different countries you have to differ a few languages your callers might speak: English, German, Italian, French, Spanish, Portuguese Greek, Swedish or Dutch. 9 languages all together (I ❤️ Europe!).

 

Select Language

The easiest way to decide what language should be used is of course by checking from where the call comes from, i.e. its country code. Of course there are countries where multiple of the above listed languages are spoken (e.g. Switzerland or Belgium) but for the ease of the call routing they will get one language. 

 

With using the "Insert Script Code" block we can implement the language selection quite easily:

 

image.png

 

The following code goes into the "Parameters" page of the block.

 

For VBScript based Call Routing:

Dim sCountryCode
sCountryCode = "0044"  ' United Kingdom, Default Langauge English

If Len(IpPbx.CallingNumber) > 4 then sCountryCode = Left(IpPbx.CallingNumber, 4)

Select Case sCountryCode
	Case "0044" ' United Kingdom
		UseExit = 0 ' -> English

	Case "0049" ' Germany
		UseExit = 1 ' -> German

	Case "0043" ' Austria
		UseExit = 1 ' -> German

	Case "0041" ' Switzerland
		UseExit = 1 ' -> German

	Case "0039" ' Italy
		UseExit = 2 ' -> Italian

	Case "0033" ' France
		UseExit = 3 ' -> French

	Case "0032" ' Belgium
		UseExit = 3 ' -> French

	Case "0034" ' Spain
		UseExit = 4 ' -> Spanish

	Case "0035" ' Portugal
		UseExit = 5 ' -> Portuguese

	Case "0030" ' Greece
		UseExit = 6 ' -> Greek

	Case "0046" ' Sweden
		UseExit = 7 ' -> Swedish

	Case "0031" ' The Netherlands
		UseExit = 8 ' -> Dutch

	Case Else ' Every other country / own country / no number signalled
		UseExit = 0 ' -> English

End Select

 

For Lua based Call Routing:

local sCountryCode = "0044"  -- United Kingdom, Default Langauge English

if (StringLen(IpPbx.CallingNumber()) > 4) then 
    sCountryCode = StringLeft(IpPbx.CallingNumber(), 4)
end

if (sCountryCode == "0044") then     -- United Kingdom
    UseExit = 0 -- -> English

elseif (sCountryCode == "0049") then -- Germany
    UseExit = 1 -- -> German

elseif (sCountryCode == "0043") then -- Austria
    UseExit = 1 -- -> German

elseif (sCountryCode == "0041") then -- Switzerland
    UseExit = 1 -- -> German

elseif (sCountryCode == "0041") then -- Italy
    UseExit = 2 -- -> Italian

elseif (sCountryCode == "0033") then -- France
    UseExit = 3 -- -> French

elseif (sCountryCode == "0032") then -- Belgium
    UseExit = 3 -- -> French

elseif (sCountryCode == "0034") then -- Spain
    UseExit = 4 -- -> Spanish

elseif (sCountryCode == "0035") then -- Portugal
    UseExit = 5 -- -> Portuguese

elseif (sCountryCode == "0030") then -- Greece
    UseExit = 6 -- -> Greek

elseif (sCountryCode == "0046") then -- Sweden
    UseExit = 7 -- -> Swedish

elseif (sCountryCode == "0031") then -- The Netherlands
    UseExit = 8 -- -> Dutch

else -- Every other country / own country / no number signalled
    UseExit = 0 -- -> English

end

 

Within the code the property IpPbx.CallingNumber / IpPbx.CallingNumber() is used. It provides the number of the caller.

 

You might or might not have noticed that I only differed 9 languages so far. Believe it or not, I did that intentionally ;) If you need to differ more than 10 languages you could do something like this, and for that I need the tenth exit of the first "Insert Script Code" block to be free to use it to route to the next one.

 

image.png

 

Feel free to add any number of more languages here. The above is just a quick example, no discrimination intended.

 

Now that we know the language of the caller we need to implement our call routing accordingly. 

 

Language aware Call Routing (1)

The most straight forward approach for the call routing would look like this

 

image.png

 

with having for each language the complete initial script with announcement, menu and connect to, e.g.

 

image.png

 

VBScript based Call routing

Multi_Language_2.rse

 

Lua based Call routing

Multi_Language_2_Lua.rse

 

 

Lets take a look into the pros and cons of this straight forward approach:

  • Pros
    • straight forward
    • for each language a separate call routing
    • therefore it is possible to have different call routing per language, not just different announcements
  • Cons
    • the script is huuuuuuuge
    • therefore not easy to understand when taking a look on it the first time
    • therefore it is easy to break it when trying to modify it
    • relatively huge amount of work to add new languages

 

I don't know about you, but I like things a little bit more easy to grasp at a first glance. Something like the very first screenshot on this page. So this brings me to a second possible approach for this.

 

Language aware Call Routing (2)

As said, I want to come back to the initial script, easy to grasp, just a hand full of blocks.

 

The idea now is to replace the announcements and destination numbers in blocks as we need them. This is easily be done by taking the announcements and number from variables and all we need to do at the beginning of the script is to initialize those variables properly. 

 

We use the "Start" block to define the needed variables.

 

For VBScript based Call Routing:

Dim sMsgWelcome
Dim sMsgMenu
Dim sNumSupport
Dim sNumSales
Dim sNumOperator

 

For Lua based Call Routing:

local sMsgWelcome
local sMsgMenu
local sNumSupport
local sNumSales
local sNumOperator

 

Without having them already initialized (will follow soon) we can change all 5 blocks in the script to make use of the variables, instead of using hard coded file names or numbers. 

 

The welcome announcement:

image.png

 

The IVR/DTMF menu:

image.png

 

And the connect blocks to get the call where it should go to:

image.png

 

 

With having this done we can start thinking about the initialization of these variables i.e. the language selection and definition what values should be used for the variables. With a small VBScript function in the "Start" block this can be quickly done. You might notice that the code looks quite similar to what we have done in the first example in the "Insert Script Code" block. This is because we still use the same principle of language selection.

 

For VBScript based Call Routing:

Function Initialize

    Dim sCountryCode
    sCountryCode = "0044"  ' United Kingdom, Default Langauge English

    If Len(IpPbx.CallingNumber) > 4 then sCountryCode = Left(IpPbx.CallingNumber, 4)

    Select Case sCountryCode

        Case "0044" ' United Kingdom -> English
            sMsgWelcome  = "MSG_WELCOME_EN.wav"
            sMsgMenu     = "MSG_WELCOME_EN.wav"
            sNumSupport  = "201"
            sNumSales    = "301"
            sNumOperator = "101"

        Case "0049" ' Germany -> German
            sMsgWelcome  = "MSG_WELCOME_DE.wav"
            sMsgMenu     = "MSG_WELCOME_DE.wav"
            sNumSupport  = "202"
            sNumSales    = "302"
            sNumOperator = "102"

        Case "0043" ' Austria -> German
            sMsgWelcome  = "MSG_WELCOME_DE.wav"
            sMsgMenu     = "MSG_WELCOME_DE.wav"
            sNumSupport  = "202"
            sNumSales    = "302"
            sNumOperator = "102"

        Case "0041" ' Switzerland -> German
            sMsgWelcome  = "MSG_WELCOME_DE.wav"
            sMsgMenu     = "MSG_WELCOME_DE.wav"
            sNumSupport  = "202"
            sNumSales    = "302"
            sNumOperator = "102"

        Case "0039" ' Italy -> Italian
            sMsgWelcome  = "MSG_WELCOME_IT.wav"
            sMsgMenu     = "MSG_WELCOME_IT.wav"
            sNumSupport  = "203"
            sNumSales    = "303"
            sNumOperator = "103"

        Case "0033" ' France -> French
            sMsgWelcome  = "MSG_WELCOME_FR.wav"
            sMsgMenu     = "MSG_WELCOME_FR.wav"
            sNumSupport  = "204"
            sNumSales    = "304"
            sNumOperator = "104"

        Case "0032" ' Belgium -> French
            sMsgWelcome  = "MSG_WELCOME_FR.wav"
            sMsgMenu     = "MSG_WELCOME_FR.wav"
            sNumSupport  = "204"
            sNumSales    = "304"
            sNumOperator = "104"

        Case "0034" ' Spain -> Spanish
            sMsgWelcome  = "MSG_WELCOME_ES.wav"
            sMsgMenu     = "MSG_WELCOME_ES.wav"
            sNumSupport  = "205"
            sNumSales    = "305"
            sNumOperator = "105"

        Case "0035" ' Portugal -> Portuguese
            sMsgWelcome  = "MSG_WELCOME_PT.wav"
            sMsgMenu     = "MSG_WELCOME_PT.wav"
            sNumSupport  = "206"
            sNumSales    = "306"
            sNumOperator = "1064"

        Case "0030" ' Greece -> Greek
            sMsgWelcome  = "MSG_WELCOME_GR.wav"
            sMsgMenu     = "MSG_WELCOME_GR.wav"
            sNumSupport  = "207"
            sNumSales    = "307"
            sNumOperator = "107"

        Case "0046" ' Sweden -> Swedish
            sMsgWelcome  = "MSG_WELCOME_SE.wav"
            sMsgMenu     = "MSG_WELCOME_SE.wav"
            sNumSupport  = "208"
            sNumSales    = "308"
            sNumOperator = "108"

        Case "0031" ' The Netherlands -> Dutch
            sMsgWelcome  = "MSG_WELCOME_NL.wav"
            sMsgMenu     = "MSG_WELCOME_NL.wav"
            sNumSupport  = "209"
            sNumSales    = "309"
            sNumOperator = "109"

        Case Else ' Every other country / own country / no number signalled -> English
            sMsgWelcome  = "MSG_WELCOME_EN.wav"
            sMsgMenu     = "MSG_WELCOME_EN.wav"
            sNumSupport  = "201"
            sNumSales    = "301"
            sNumOperator = "101"

    End Select

End Function

 

For Lua based Call Routing:

function Initialize()

    local sCountryCode = "0044"  -- United Kingdom, Default Langauge English

    if StringLen(IpPbx.CallingNumber() > 4) then 
        sCountryCode = StringLeft(IpPbx.CallingNumber(), 4)
    end

    if (sCountryCode == "0044") then     -- United Kingdom -> English
        sMsgWelcome  = "MSG_WELCOME_EN.wav"
        sMsgMenu     = "MSG_WELCOME_EN.wav"
        sNumSupport  = "201"
        sNumSales    = "301"
        sNumOperator = "101"

    elseif (sCountryCode == "0049") then -- Germany -> German
        sMsgWelcome  = "MSG_WELCOME_DE.wav"
        sMsgMenu     = "MSG_WELCOME_DE.wav"
        sNumSupport  = "202"
        sNumSales    = "302"
        sNumOperator = "102"

    elseif (sCountryCode == "0043") then -- Austria -> German
        sMsgWelcome  = "MSG_WELCOME_DE.wav"
        sMsgMenu     = "MSG_WELCOME_DE.wav"
        sNumSupport  = "202"
        sNumSales    = "302"
        sNumOperator = "102"

    elseif (sCountryCode == "0041") then -- Switzerland -> German
        sMsgWelcome  = "MSG_WELCOME_DE.wav"
        sMsgMenu     = "MSG_WELCOME_DE.wav"
        sNumSupport  = "202"
        sNumSales    = "302"
        sNumOperator = "102"

    elseif (sCountryCode == "0041") then -- Italy -> Italian
        sMsgWelcome  = "MSG_WELCOME_IT.wav"
        sMsgMenu     = "MSG_WELCOME_IT.wav"
        sNumSupport  = "203"
        sNumSales    = "303"
        sNumOperator = "103"

    elseif (sCountryCode == "0033") then -- France -> French
        sMsgWelcome  = "MSG_WELCOME_FR.wav"
        sMsgMenu     = "MSG_WELCOME_FR.wav"
        sNumSupport  = "204"
        sNumSales    = "304"
        sNumOperator = "104"

    elseif (sCountryCode == "0032") then -- Belgium -> French
        sMsgWelcome  = "MSG_WELCOME_FR.wav"
        sMsgMenu     = "MSG_WELCOME_FR.wav"
        sNumSupport  = "204"
        sNumSales    = "304"
        sNumOperator = "104"

    elseif (sCountryCode == "0034") then -- Spain -> Spanish
        sMsgWelcome  = "MSG_WELCOME_ES.wav"
        sMsgMenu     = "MSG_WELCOME_ES.wav"
        sNumSupport  = "205"
        sNumSales    = "305"
        sNumOperator = "105"

    elseif (sCountryCode == "0035") then -- Portugal -> Portuguese
        sMsgWelcome  = "MSG_WELCOME_PT.wav"
        sMsgMenu     = "MSG_WELCOME_PT.wav"
        sNumSupport  = "206"
        sNumSales    = "306"
        sNumOperator = "106"

    elseif (sCountryCode == "0030") then -- Greece -> Greek
        sMsgWelcome  = "MSG_WELCOME_GR.wav"
        sMsgMenu     = "MSG_WELCOME_GR.wav"
        sNumSupport  = "207"
        sNumSales    = "307"
        sNumOperator = "107"

    elseif (sCountryCode == "0046") then -- Sweden -> Swedish
        sMsgWelcome  = "MSG_WELCOME_SE.wav"
        sMsgMenu     = "MSG_WELCOME_SE.wav"
        sNumSupport  = "208"
        sNumSales    = "308"
        sNumOperator = "108"

    elseif (sCountryCode == "0031") then -- The Netherlands -> Dutch
        sMsgWelcome  = "MSG_WELCOME_NL.wav"
        sMsgMenu     = "MSG_WELCOME_NL.wav"
        sNumSupport  = "209"
        sNumSales    = "309"
        sNumOperator = "109"

    else -- Every other country / own country / no number signalled -> English
        sMsgWelcome  = "MSG_WELCOME_EN.wav"
        sMsgMenu     = "MSG_WELCOME_EN.wav"
        sNumSupport  = "201"
        sNumSales    = "301"
        sNumOperator = "101"

    end

end

 

Within the code the function IpPbx.CallingNumber / IpPbx.CallingNumber() is used. It provides the number of the caller.

 

To start the initialization function we can directly use the "Start" block. By simply calling this function within the "Start" block it will automatically be called when the script starts.

 

For VBScript based Call Routing:

' start the initialization automatically when the script starts
Initialize

 

For Lua based Call Routing:

-- start the initialization automatically when the script starts
Initialize()

 

 

With having all the above 3 code snippets in the "Start" block our call routing script looks like this:

 

image.png

 

For VBScript based Call Routing:

Multi_Language_3.rse

 

For Lua based Call Routing:

Multi_Language_3_Lua.rse

 

 

Lets take a look into the pros and cons of this approach:

  • Pros
    • small and easy to grasp script
    • easy to maintain, easy to add new languages
  • Cons
    • as it uses the exact same call routing for every language it might be a little bit tricky to implement exceptions in the call routing for different languages
    • if you are not too happy with a little bit of VBScript code it could be difficult to maintain

 

 

Conclusion

Of course it matters how many languages you have to differ and how many blocks you have in your call routing which differ per language. I created the examples in here with lots of languages purposely to show you where you could end up sooner or later if the number of supported languages grow over the time.

 

If you feel more comfortable with GSE blocks instead of a little bit of code there is nothing wrong with the first attempt. It has its pros as it has its cons. As the second one has its pros and cons.

 

Personally I would always tend to the second approach. But that is just me. 

 

 

Enjoy!

 

PS: don't miss to take a look into the ECR Useful Link Collection

 

0 Comments


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.