-
Notifications
You must be signed in to change notification settings - Fork 4
/
TeamsLogStatus.ahk
77 lines (64 loc) · 1.71 KB
/
TeamsLogStatus.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#NoEnv
#Warn ; Enable warnings to assist with detecting common errors.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
#Persistent
; Set the Webhook URI to POST to
WebhookURI = <ADD YOUR WEBHOOK URI HERE e.g. https://your-home-assistant:8123/api/webhook/some_hook_id>
;Set a default Status
CurrentStatus = Unknown
; Send a heartbeat webhook anyway every 5 mins
SetTimer, SendWebhook, 300000
logPath = %A_AppData%\Microsoft\Teams\logs.txt
lt := new CLogTailer(logPath, Func("NewLine"))
return
NewLine(text)
{
global CurrentStatus
ReadStatus := RegExMatch(text, "StatusIndicatorStateService: Added (?!NewActivity)(\w+)", StatusText)
if (ReadStatus != 0)
{
CurrentStatus := RegExReplace(StatusText1, "[^A-Z\s]\K([A-Z])", " $1")
SendWebhook()
}
}
class CLogTailer {
__New(logfile, callback){
this.file := FileOpen(logfile, "r-d")
this.callback := callback
; Move seek to end of file
this.file.Seek(0, 2)
fn := this.WatchLog.Bind(this)
SetTimer, % fn, 100
}
WatchLog(){
Loop {
p := this.file.Tell()
l := this.file.Length
line := this.file.ReadLine(), "`r`n"
len := StrLen(line)
if (len){
RegExMatch(line, "[\r\n]+", matches)
if (line == matches)
continue
this.callback.Call(Trim(line, "`r`n"))
}
} until (p == l)
}
}
; ----------------------
; Function to POST a JSON payload to the Webhook URI defined
; ----------------------
SendWebhook()
{
global
try {
WinHTTP := ComObjCreate("WinHTTP.WinHttpRequest.5.1")
WinHTTP.Open("POST", WebhookURI, 0)
WinHTTP.SetRequestHeader("Content-Type", "application/json")
Body = {"status":"%CurrentStatus%"}
WinHTTP.Send(Body)
Result := WinHTTP.ResponseText
Status := WinHTTP.Status
}
}