-
Notifications
You must be signed in to change notification settings - Fork 5
/
owncastapiclient.go
51 lines (44 loc) · 1.46 KB
/
owncastapiclient.go
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
package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
"strconv"
"strings"
"time"
)
func getApiUrlFor(endpoint string) string {
return strings.TrimRight(DemoBotConfiguration.OwncastAddress, "/") + endpoint
}
func SendSystemMessage(message string, sendDelay int) {
time.Sleep(time.Duration(sendDelay) * time.Second)
postBody, _ := json.Marshal(map[string]string{
"body": message,
})
responseBody := bytes.NewBuffer(postBody)
req, _ := http.NewRequest("POST", getApiUrlFor("/api/integrations/chat/system"), responseBody)
req.Header.Add("Authorization", "Bearer "+DemoBotConfiguration.AccessToken)
req.Header.Add("ContentType", "application/json")
client := &http.Client{}
_, err := client.Do(req)
if err != nil {
log.Println("Error on response.\n[ERROR] -", err)
}
}
func SendSystemMessageToClient(clientId uint, message string, sendDelay int) {
time.Sleep(time.Duration(sendDelay) * time.Second)
var clientIdString string = strconv.FormatUint(uint64(clientId), 10)
postBody, _ := json.Marshal(map[string]string{
"body": message,
})
responseBody := bytes.NewBuffer(postBody)
req, _ := http.NewRequest("POST", getApiUrlFor("/api/integrations/chat/system/client/"+clientIdString), responseBody)
req.Header.Add("Authorization", "Bearer "+DemoBotConfiguration.AccessToken)
req.Header.Add("ContentType", "application/json")
client := &http.Client{}
_, err := client.Do(req)
if err != nil {
log.Println("Error on response.\n[ERROR] -", err)
}
}