-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlackAPI.ahk
44 lines (37 loc) · 1.1 KB
/
SlackAPI.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
/******************************************
* @file SlackAPI.ahk
* @description: A class to interact with Slack API
* @author hsayed
* @date 2025/01/25
* @version 1.0.0
*******************************************/
class SlackAPI {
baseUrl := "https://slack.com/api"
token := ""
__New(token) {
this.token := token
}
SendRequest(endpoint, payload) {
http := ComObject("WinHttp.WinHttpRequest.5.1")
http.Open("POST", this.baseUrl "/" endpoint, true)
http.SetRequestHeader("Authorization", "Bearer " this.token)
http.SetRequestHeader("Content-Type", "application/json; charset=utf-8")
http.Send(payload)
http.WaitForResponse()
}
SetStatus(text, emoji) {
payload := '{"profile":{"status_text":"' text '","status_emoji":"' emoji '"}}'
this.SendRequest("users.profile.set", payload)
}
SetPresence(presence) {
payload := '{"presence":"' presence '"}'
this.SendRequest("users.setPresence", payload)
}
PauseNotifications(minutes) {
payload := '{"num_minutes":' minutes '}'
this.SendRequest("dnd.setSnooze", payload)
}
ResumeNotifications() {
this.SendRequest("dnd.endSnooze", "{}")
}
}