VERSION 1.0 CLASSBEGIN
MultiUse = -1
END
Attribute VB_Name = "PBX_Web"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclareID = False
Attribute VB_Exposed = False
'#Reference {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0#C:\Windows\System32\ieframe.dll#Microsoft Internet Controls
'#Reference {3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}#4.0#0#C:\Windows\System32\mshtml.tlb#Microsoft HTML Object Library
Option Explicit
Private oPBX As InternetExplorer
Private oPhoneBox As HTMLInputElement
Public Enum Campaign
Manual_Outbound = 7
Legal_Outbound = 13
End Enum
Public Enum CallResult
AnswerMachine_MessageLeft = 15
Contact = 26
No_Answer = 16
Wrong_Phone_Number = 14
Busy = 9
Dead_Air = 2
Operator_Intercept = 7
Third_Party = 27
End Enum
Private Function Doc As HTMLDocument
Set Doc = oPBX.document
End Property
Private Property Get oPhoneMain() As HTMLDivElement
Set oPhoneMain = Doc.getElementById("phone")
End Property
Private Property Get oStatus() As HTMLDivElement
Set oStatus = oPhoneMain.getElementsByClassName("connected")(0)
End Property
Private Property Get oDetails() As HTMLDivElement
Set oDetails = Doc.getElementById("agent-top").getElementsByClassName("call_info")(0).getElementsByClassName("info")(0).getElementsByTagName("p")(1)
End Property
Public Property Let PhoneNumber(sPhone As String)
oPhoneBox.value = sPhone
Debug.Print "PBX_Web: PhoneNumber changed to " & sPhone
End Property
Public Property Get PhoneNumber() As String
PhoneNumber = oPhoneBox.value
End Property
Public Property Let AccountID(sID As String)
Doc.querySelector("input.account_id").value = sID
Debug.Print "PBX_Web: AccountID Box Changed to " & sID
End Property
Public Property Let ManualCampaign(CampaignValue As Campaign)
Dim o As HTMLSelectElement, sValue As String
Set o = Doc.querySelector("div#phone > div.manual_call > select.campaign")
Doc.querySelector("div#phone > div.manual_call.internal > select.campaign").value = "12"
o.value = CStr(CampaignValue)
Debug.Print "PBX_Web: ManualCampaign Value changed to " & CampaignValue
End Property
Public Property Let Call_Result(ResultValue As CallResult)
With Doc.getElementById("agent-top").getElementsByClassName("call_wrap")(0).getElementsByClassName("wrap")(0)
.getElementsByClassName("call_result")(0).getElementsByTagName("select")(0).value = CStr(ResultValue)
End With
Debug.Print "PBX_Web: Call_Result Changed to " & ResultValue
End Property
Public Property Get Call_Result() As CallResult
With Doc.getElementById("agent-top").getElementsByClassName("call_wrap")(0).getElementsByClassName("wrap")(0)
Call_Result = .getElementsByClassName("call_result")(0).getElementsByTagName("select")(0).value
End With
End Property
Public Sub DialNumber()
Dim VerifyValue As String
VerifyValue = PhoneNumber
Doc.querySelector("div#phone > div.manual_call > div.button").click
Debug.Print "PBX_Web: Dialing Phone Number: " & PhoneNumber & ". Waiting on confirmation."
ConfirmCall VerifyValue
Debug.Print "PBX_Web: Confirmed call connected"
End Sub
Public Sub HoldCall()
Static onHold As Boolean
Doc.querySelector("div#phone > div.line > div.buttons > div.onhold").click
If Not onHold Then
Debug.Print "PBX_Web: Call placed on hold."
onHold = True
Else
Debug.Print "PBX_Web: Call removed from hold."
onHold = False
End If
End Sub
Public Sub HangupCall()
Doc.querySelector("div#phone > div.line > div.buttons > div.hangup").click
Debug.Print "PBX_Web: Hungup Call"
End Sub
Public Sub SaveAndFinishCall()
While Doc.getElementsByClassName("submit")(0).getAttribute("style") <> "display: table-row;"
DoEvents
Wend
Sleep 150
Doc.getElementById("submit_call").click
Debug.Print "PBX_Web: Saved and Finished Call."
End Sub
Public Sub WaitWithMessage(EndTime As Single)
Do Until Timer > EndTime
DoEvents
Window_NoActiveCallsText = "No active calls " & Format(EndTime - Timer, "0")
Loop
End Sub
Private Sub Class_Initialize()
Set oPBX = GetIE(".****************.***/") 'Trying NOT to be labeled as a spammer :)
Set oPhoneBox = Doc.querySelector("div#phone > div.manual_call > input.masked_phone")
End Sub
Private Sub ConfirmCall(ByVal sPhone As String)
Dim StartTime As Single
StartTime = Timer
While oDetails Is Nothing
DoEvents
Wend
While Not oDetails.innerText Like "Dialed: " & onlyDigits(sPhone) & "*"
DoEvents
Wend
End Sub
Private Function GetIE(sLocation As String) As InternetExplorer
Dim objShell As Object, objShellWindows As Object, o As Object
Dim sUrl As String
Dim retVal As Object
Set retVal = Nothing
Set objShell = CreateObject("shell.application")
Set objShellWindows = objShell.Windows
For Each o In objShellWindows
sUrl = ""
On Error Resume Next
sUrl = o.document.location
On Error GoTo 0
If sUrl Like "*" & sLocation & "*" Then Set retVal = o: Exit For
Next o
Set GetIE = retVal
End Function
Private Function onlyDigits(s As String) As String
Dim retVal As String, i As Integer
For i = 1 To Len(s)
If Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Then
retVal = retVal + Mid(s, i, 1)
End If
Next
onlyDigits = retVal
End Function