-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.go
75 lines (57 loc) · 1.45 KB
/
bot.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
)
const (
urlT = "https://api.telegram.org/"
)
type Elvira struct {
Token string `json:"token"`
}
func (e *Elvira) sendMsg(chatId int, msg string) {
urlSite := urlT + e.Token + "/sendMessage"
//fmt.Println("URL:>", urlSite)
req, err := http.NewRequest("GET", urlSite, nil)
if err != nil {
fmt.Println(err)
}
req.Header.Set("Content Type", "application/x-www-form-urlencoded;")
req.Header.Set("charset:", "UTF-8")
response, err := http.PostForm(urlSite, url.Values{"chat_id": {strconv.Itoa(chatId)}, "parse_mode": {"HTML"}, "text": {msg}})
if err != nil {
fmt.Println(err)
return
}
if err != nil {
fmt.Printf("%s", err)
} else {
defer response.Body.Close()
if err != nil {
fmt.Printf("%s", err)
}
}
}
func (e *Elvira) sendPhoto(chatId int, img string) {
urlSite := urlT + e.Token + "/sendPhoto"
req, err := http.NewRequest("GET", urlSite, nil)
req.Header.Set("Content Type", "application/x-www-form-urlencoded;")
req.Header.Set("charset:", "UTF-8")
response, err := http.PostForm(urlSite, url.Values{"chat_id": {strconv.Itoa(chatId)}, "photo": {"AgADAQADqqcxG9hEuAbvX1Tw8KBML0PH5y8ABPHpJLGgcfhStB4AAgI"}})
if err != nil {
return
}
if err != nil {
fmt.Printf("%s", err)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
}
fmt.Printf("%s\n", string(contents))
}
}