#Persistent
#SingleInstance, force
SetBatchLines, -1
ahp=
(
AHKhttp-server 1.0
[var]
)
paths := {}
paths["/GV"] := Func("GV")
paths["404"] := Func("NotFound")
server := new HttpServer()
server.SetPaths(paths)
server.Serve(8000)
;********************************************************************************************************
; Start-up code.
;********************************************************************************************************
Loop, 1 ; Set Browser
bcode:=%A_Index%
if (bcode = "B") or (bcode = "b")
global browsr:="brave"
else if (bcode = "E") or (bcode = "e")
global browsr:="msedge"
else if (bcode = "F") or (bcode = "f")
global browsr:="firefox"
else
global browsr:="chrome"
return
;********************************************************************************************************
; End start-up.
;********************************************************************************************************
NotFound(ByRef req, ByRef res) {
res.SetBodyText("Page not found")
}
GV(ByRef req, ByRef res) {
global ahp
SetTitleMatchMode, 1
dialnum:=req.queries["parm1"] ; Get parms
fwdnum:=req.queries["parm2"]
rbutt:=req.queries["parm3"]
if fwdnum is not integer
fwdnum:=1
;********************************************************************************************************
; Following code processes a call using an existing GV window.
;********************************************************************************************************
if WinExist("Voice") ; Does a GV window exist?
{
WinActivate
Send {Esc} ; Close any popups
Sleep 200
WinActivate
Winfound:="Y"
SendInput !d ; ALT-d Highlight address bar
Sleep 100
if (StrLen(dialnum) = 10) ; Outbound number 10 digits?
dialnum := 1 . dialnum ; Add country code, otherwise will be treated as international call
SendInput https://voice.google.com/u/0/calls?a=nc`,`%2b%dialnum%
SendInput {Enter}
Sleep 1500
}
;********************************************************************************************************
; End existing window code.
;********************************************************************************************************
else
;********************************************************************************************************
; When script can't find a window name beginning with "Voice - Calls"
; opens a new GV window to process a call
;********************************************************************************************************
{
if (StrLen(dialnum) = 10) ; Outbound number 10 digits?
dialnum := 1 . dialnum ; Add country code, otherwise will be treated as international call
Run, %browsr%.exe --new-window "https://voice.google.com/u/0/calls?a=nc`,`%2b%dialnum%"
Send {Esc} ; Close any popups
}
;********************************************************************************************************
; End new window code.
;********************************************************************************************************
;********************************************************************************************************
; Start of common code for new & existing GV window.
;********************************************************************************************************
WinWait Voice - Calls ; Wait for GV
Sleep 2500 ; Pause until GV page fully loads
; Slower computers might need to increase this value
WinGetPos, X, Y, W, H, A ; Get coordinates of GV window
M1 := (W//2) ; Calc coordinates of approx middle of window
M2 := (H//2)
If (rbutt="R") or (rbutt="r") ; Mouse buttons switched?
MouseClick, Right, %M1%, %M2% ; Position cursor to middle of window for forwarding# selection
else
MouseClick, Left, %M1%, %M2%
Sleep 600
SendInput {Tab} ; Tab to forwarding number selection
SendInput {Enter} ; Enter to display the forwarding numbers
Sleep 350
;********************************************************************************************************
; The script will use parm2 (fwdnum) to select the forwarding number
; Valid numbers are 1, 2 or 3
; It will select the 1st when fwdnum is invalid or not specified
;********************************************************************************************************
if (fwdnum=2) ; Position cursor to 2nd forwarding number
{
SendInput {Down}
Sleep 100
}
if (fwdnum=3) ; Position cursor to 3rd forwarding number
{
SendInput {Down}
Sleep 100
SendInput {Down}
Sleep 100
}
SendInput {Enter} ; Enter will select the forwarding number
Sleep 500
SendInput {Tab} ; 2 tabs to "Connect" button
SendInput {Tab}
Sleep 100
SendInput {Enter} ; Enter to initiate callback
Sleep 1500
if (Winfound != "Y")
WinClose, Voice
res.status := 200
}
;********************************************************************************************************
; End common code.
;********************************************************************************************************
#Include %A_ScriptDir%\AHKhttp.ahk ; File muat be in same folder as Script
#Include %A_ScriptDir%\AHKsock.ahk