Howto: Custom VB Script Code - Twitter Incoming Calls
SUMMARY
This article describes how to create new status messages (Tweets) on twitter.com on incoming calls.
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:
- Custom VBScript Code - Access web pages within a script (kb2650)
- Custom VBScript Code - Call logging into database (kb2218)
- Custom VBScript Code - Call logging into textfile (kb2217)
- Custom VBScript Code - Caller verification in database (kb2219)
- Custom VBScript Code - Check for Bank Holiday (kb2285)
INFORMATION
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:
- 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:
- Click on the both parameters in the description field of the rule and enter the username and password belonging to your twitter.com 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.
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.
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.
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 skippedexit 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:
Function URLescape(ByVal sURL)
URLescape = sURL
URLescape = Replace(URLescape, "-", "%2D")
URLescape = Replace(URLescape, "'", "%27")
URLescape = Replace(URLescape, """", "%22")
End Function
Function TwitterCall(ByVal sUser, ByVal sPassword)
Dim xml
xml = PBXScript.CreateObject("Microsoft.XMLHTTP")
Dim sStatus
sStatus = "Just received a call from "
If PBXCall.CallingPartyName <> "" Then
sStatus = sStatus & PBXCall.CallingPartyName & _
" (" & PBXCall.CallingPartyNumber & ")"
Else
sStatus = sStatus & PBXCall.CallingPartyNumber
End If
PBXScript.OutputTrace("New Twitter Status: " & sStatus)
xml.Open("POST", "http://" & sUser & ":" & sPassword & _
"@twitter.com/statuses/update.xml?status=" & _
URLescape(sStatus), False)
xml.setRequestHeader("Content-Type", _
"content=text/html; charset=iso-8859-1")
xml.Send()
PBXScript.OutputTrace("Twitter Response: " & _
xml.responseText)
xml = Nothing
End Function
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.
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
0 Kommentare