-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendPhoto.go
67 lines (53 loc) · 1.51 KB
/
sendPhoto.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
package telegram
import (
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"
)
func (t *BotT) SendPhoto(chatID int64, photo string, caption string, options *MessageOptions) (*MessageT, error) {
data := url.Values{}
if options != nil {
data = options.Get()
}
data.Add("chat_id", strconv.FormatInt(chatID, 10))
data.Add("photo", photo)
data.Add("caption", caption)
return t.sendRawMessage("sendPhoto", data)
}
func (t *BotT) SendPhotoFromBytes(chatID int64, filename string, file []byte, caption string, options *MessageOptions) (*MessageT, error) {
data := url.Values{}
if options != nil {
data = options.Get()
}
data.Add("chat_id", strconv.FormatInt(chatID, 10))
data.Add("caption", caption)
return t.sendRawFile("sendPhoto", data, "photo", filename, file, nil)
}
func (t *BotT) SendPhotoFromFile(chatID int64, filename string, file string, caption string, options *MessageOptions) (*MessageT, error) {
f, err := os.Open(file)
if err != nil {
return nil, err
}
defer f.Close()
bytes, err := ioutil.ReadAll(f)
if err != nil {
return nil, err
}
return t.SendPhotoFromBytes(chatID, filename, bytes, caption, options)
}
func (u *UpdateT) SendPhoto(chatID int64, photo string, caption string, options *MessageOptions) {
if u.context == nil {
_, _ = u.bot.SendPhoto(chatID, photo, caption, options)
return
}
data := map[string]string{}
if options != nil {
data = options.GetMap()
}
data["method"] = "sendPhoto"
data["photo"] = photo
data["caption"] = caption
u.context.JSON(http.StatusOK, data)
}