Custom VBScript Code - Twitter incoming calls (kb4067)

The information in this article applies to:

  • SwyxWare all versions

[ Summary | Information | Links ]


This article describes how to create new status messages (Tweets) on on incoming calls.

Twitter Logo
Twitter Logo
Click to enlarge...

This can be usefull for example for

  • Status messages (like an overflow in call center groups where usually emails would be sent)
  • A sort of public call journal for certain numbers

Other articles in this series:


How to setup the script

Download the file kb4067_Twitter.rse via the link at the end of this article. To load the file into the Call Routing Manager (CRM) i.e. the Graphical Script Editor (GSE) do the following:

  • Open the Call Routing Manager (CRM).
  • Click on New...
  • Select Graphical Script Editor (GSE) and click Ok.
  • Open the menu Files | Import... im GSE.
  • Select the file kb4067_Twitter.rse. The rule will now be loaded and looks like this:

    Graphical Script Editor
    Graphical Script Editor
    Click to enlarge...

  • Save the rule via the menu File | Save.
  • Close the GSE.
  • Move the rule to the top of the list of rules within the CRM:

    Call Routing Manager
    Call Routing Manager
    Click to enlarge...

  • Click on the both parameters in the description field of the rule and enter the username and password belonging to your account.


How it works

The Twitter service provides a so called Twitter API. This is a web (HTTP) based interface which can be used (beside others) to add new status messages (Tweets) via a simple HTTP request. Such HTTP requests can be created quite easily from within a call routing script. The script in this articles provides a function TwitterCall which can be called from naerly every place within graphical part of the call routing script. By calling this function the current phone call can be twittered in certain situations, like calls from certain numbers, overflows in call queues, timeouts in call queues.

Own VBScript code (to be more specific: own functions, subroutines, constant definitions and variable declarations) will be placed into the Start Block of a call routing script.

Start Block
Start Block
Click to enlarge...

The code being placed here can be called from nearly everywhere within the call routing script (as also from other call routing scripts for the same user as long as the script holding the code is activated). This example script uses the VBScript Code block to call the function.

Insert Script Code Block
Insert Script Code Block
Click to enlarge...

To make the script a little bit more easy and flexible to use two rule parameters are used to pass username and password from the Call Routing Manager (description field of the rule) into the script without the need for the user to open the GSE.

Rule Properties - Parameters
Rule Properties - Parameters
Click to enlarge...

GSE rule parameters will be defined within the properties of the GSE rule and are available in own defined variables within the call routing script.

The example script calls for every incoming call the TwitterCall function and passes the login information (rule parameters) as parameters. Afterwards the rule will be exited via the Rule skipped exit to force the Call Routing Manager to also start following rules in the list of rules.

This is the VBScript code being stored in the Start block:


  1. Function URLescape(ByVal sURL)
  2.     URLescape = sURL
  3.     URLescape = Replace(URLescape, "-", "%2D")
  4.     URLescape = Replace(URLescape, "'", "%27")
  5.     URLescape = Replace(URLescape, """", "%22")
  6. EndFunction
  9. Function TwitterCall(ByVal sUser, ByVal sPassword)
  10.     Dim xml
  11.     xml = PBXScript.CreateObject("Microsoft.XMLHTTP")
  13.     Dim sStatus
  14.     sStatus = "Just received a call from "
  16.     If PBXCall.CallingPartyName <> ""Then
  17.         sStatus = sStatus & PBXCall.CallingPartyName & _
  18.          " (" & PBXCall.CallingPartyNumber & ")"
  19.     Else
  20.         sStatus = sStatus & PBXCall.CallingPartyNumber
  21.     EndIf
  23.     PBXScript.OutputTrace("New Twitter Status: " & sStatus)
  25.     xml.Open("POST", "http://" & sUser & ":" & sPassword & _
  26.      "" & _
  27.     URLescape(sStatus), False)
  28.     xml.setRequestHeader("Content-Type", _
  29.      "content=text/html; charset=iso-8859-1")
  30.     xml.Send()
  32.     PBXScript.OutputTrace("Twitter Response: " & _
  33.     xml.responseText)
  35.     xml = Nothing
  37. EndFunction

If the server is able to resolve the caller name (from the global or private phonebook or a previous running script) this name will be used within the Twitter Tweet, otherwise just the caller's phone number.

Afterwards an HTTP request to Twitter will be executed using the Windows buid-in XMLHTTP COM object.

Using PBXScript.OutputTrace the status message (Tweet) as also the Twitter return code will be written into the server's trace file for failure analysis.


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

The third-party contact information included in this article is provided to help you find the technical support you need. This contact information is subject to change without notice. Enreach in no way guarantees the accuracy of this third-party contact information nor is responsible for it's content.


Comment on this article

If we have any follow-up questions, where can we contact you?

E-Mail Address (optional)


This feedback form can't be used for support requests. Those requests must be directed to your Enreach reseller or distributor.

Are you interested?
Swyx resellers near you

Simply find one of our certified Swyx resellers near you.

Find your reseller
We help you

Our competent contact persons are at your disposal at any time.

To the contact form