Frames

Untitled

0
1package main
2
3import (
4 "log"
5 "net/http"
6 "time"
7
8 "github.com/Syfaro/telegram-bot-api"
9)
10
11const (
12 ChatID = 1 //Insert here your chat id
13 Token = "Your telegram bot token"
14 OkResponse = "Ok."
15 BadResponse = "Bad."
16 URL = "Url to your remote server"
17)
18
19func main() {
20
21 bot, err := tgbotapi.NewBotAPI(Token)
22 if err != nil {
23 panic(err)
24 }
25
26 bot.Debug = true
27
28 log.Printf("Authorized %s", bot.Self.UserName)
29
30 var lastResponse int
31 for {
32 var msg tgbotapi.MessageConfig
33
34 //TODO: Use WS instead of HTTP
35 resp, _ := http.Get(URL)
36
37 log.Printf("Server status code is: %v \n %v \n", resp.StatusCode, resp.Body)
38
39 if resp.StatusCode != lastResponse {
40 if resp.StatusCode != 200 {
41 msg = tgbotapi.NewMessage(ChatID, BadResponse)
42 } else {
43 msg = tgbotapi.NewMessage(ChatID, OkResponse)
44 }
45 bot.Send(msg)
46 }
47 lastResponse = resp.StatusCode
48 time.Sleep(30 * time.Second)
49 }
50}
51