-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
48 lines (39 loc) · 953 Bytes
/
utils.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
package main
import (
"io/ioutil"
"log"
"net/http"
"net/url"
"github.com/tidwall/gjson"
)
func webhookIsSet() bool {
destURL := rootTelegramMethodURL + "/getWebhookInfo"
res, err := http.Get(destURL)
if err != nil {
log.Println("Could not check webhook!")
}
bytes, _ := ioutil.ReadAll(res.Body)
setURL := gjson.Get(string(bytes), "result.url").String()
if setURL == "" {
return false
}
return true
}
func setWebhook() {
destURL := rootTelegramMethodURL + "/setWebhook"
_, err := http.PostForm(destURL, url.Values{"url": {publicURL}})
if err != nil {
log.Fatal("Error setting webhook: " + err.Error())
} else {
log.Println("Webhook set successfully")
}
}
func deleteWebhook() {
destURL := rootTelegramMethodURL + "/setWebhook"
_, err := http.PostForm(destURL, url.Values{"url": {""}})
if err != nil {
log.Fatal("Error unsetting webhook: " + err.Error())
} else {
log.Println("Webhook unset successfully")
}
}