-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendMessage.go
175 lines (134 loc) · 4.09 KB
/
sendMessage.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package telegram
import (
"net/http"
"net/url"
"reflect"
"strconv"
)
type ParseModeT int
const (
ParseModeNone ParseModeT = iota
ParseModeMarkdown
ParseModeHTML
)
func (t *BotT) SendMessage(chatID int64, text string, options *MessageOptions) (*MessageT, error) {
data := url.Values{}
if options != nil {
data = options.Get()
}
data.Add("chat_id", strconv.FormatInt(chatID, 10))
data.Add("text", text)
return t.sendRawMessage("sendMessage", data)
}
func (t *BotT) EditMessageText(chatID int64, messageID uint64, text string) (*MessageT, error) {
data := url.Values{}
data.Add("chat_id", strconv.FormatInt(chatID, 10))
data.Add("message_id", strconv.FormatUint(messageID, 10))
data.Add("text", text)
return t.sendRawMessage("editMessageText", data)
}
func (t *BotT) EditMessageCaption(chatID int64, messageID uint64, caption string) (*MessageT, error) {
data := url.Values{}
data.Add("chat_id", strconv.FormatInt(chatID, 10))
data.Add("message_id", strconv.FormatUint(messageID, 10))
data.Add("caption", caption)
return t.sendRawMessage("editMessageCaption", data)
}
func (t *BotT) EditMessageKeyboard(chatID int64, messageID uint64, keyboard KeyboardI) (*MessageT, error) {
data := url.Values{}
data.Add("chat_id", strconv.FormatInt(chatID, 10))
data.Add("message_id", strconv.FormatUint(messageID, 10))
if keyboard != nil && !reflect.ValueOf(keyboard).IsNil() {
data.Add("reply_markup", keyboard.Get())
}
return t.sendRawMessage("editMessageReplyMarkup", data)
}
func (t *BotT) DeleteMessage(chatID int64, messageID uint64) {
data := url.Values{}
data.Add("chat_id", strconv.FormatInt(chatID, 10))
data.Add("message_id", strconv.FormatUint(messageID, 10))
t.sendRawMethod("deleteMessage", data)
}
func (t *BotT) CallbackQuery(callbackID string, text string) {
data := url.Values{}
data.Add("callback_query_id", callbackID)
data.Add("text", text)
t.sendRawMethod("answerCallbackQuery", data)
}
func (u *UpdateT) SendMessage(chatID int64, text string, options *MessageOptions) {
if u.context == nil {
u.bot.SendMessage(chatID, text, options)
return
}
data := map[string]string{}
if options != nil {
data = options.GetMap()
}
data["method"] = "sendMessage"
data["chat_id"] = strconv.FormatInt(chatID, 10)
data["text"] = text
u.context.JSON(http.StatusOK, data)
}
func (u *UpdateT) EditMessageText(chatID int64, messageID uint64, text string) {
if u.context == nil {
u.bot.EditMessageText(chatID, messageID, text)
return
}
data := map[string]interface{}{}
data["method"] = "editMessageText"
data["chat_id"] = chatID
data["message_id"] = messageID
data["text"] = text
u.context.JSON(http.StatusOK, data)
}
func (u *UpdateT) EditMessageCaption(chatID int64, messageID uint64, caption string) {
if u.context == nil {
u.bot.EditMessageCaption(chatID, messageID, caption)
return
}
data := map[string]interface{}{}
data["method"] = "editMessageCaption"
data["chat_id"] = chatID
data["message_id"] = messageID
data["caption"] = caption
u.context.JSON(http.StatusOK, data)
}
func (u *UpdateT) EditMessageKeyboard(chatID int64, messageID uint64, keyboard KeyboardI) {
if u.context == nil {
u.bot.EditMessageKeyboard(chatID, messageID, keyboard)
return
}
data := map[string]interface{}{}
data["method"] = "editMessageReplyMarkup"
data["chat_id"] = chatID
data["message_id"] = messageID
if keyboard != nil && !reflect.ValueOf(keyboard).IsNil() {
data["reply_markup"] = keyboard.Get()
}
u.context.JSON(http.StatusOK, data)
}
func (u *UpdateT) DeleteMessage(chatID int64, messageID uint64) {
if u.context == nil {
u.bot.DeleteMessage(chatID, messageID)
return
}
data := map[string]interface{}{}
data["method"] = "deleteMessage"
data["chat_id"] = chatID
data["message_id"] = messageID
u.context.JSON(http.StatusOK, data)
}
func (u *UpdateT) CallbackQuery(text string) {
if u.Callback == nil {
return
}
if u.context == nil {
u.bot.CallbackQuery(u.Callback.ID, text)
return
}
data := map[string]interface{}{}
data["method"] = "answerCallbackQuery"
data["callback_query_id"] = u.Callback.ID
data["text"] = text
u.context.JSON(http.StatusOK, data)
}