-
Notifications
You must be signed in to change notification settings - Fork 6
/
helpers.go
293 lines (237 loc) · 6.51 KB
/
helpers.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package micha
import (
"encoding/json"
"net/url"
"strings"
)
// Convert struct to url values map
// TODO: temp implementation
func structToValues(obj interface{}) (url.Values, error) {
data, err := json.Marshal(obj)
if err != nil {
return nil, err
}
rawMap := map[string]json.RawMessage{}
if err := json.Unmarshal(data, &rawMap); err != nil {
return nil, err
}
values := url.Values{}
for key := range rawMap {
values.Set(key, strings.Trim(string(rawMap[key]), `/"`))
}
return values, nil
}
type sendMessageParams struct {
SendMessageOptions
ChatID ChatID `json:"chat_id"`
Text string `json:"text"`
}
type sendPhotoParams struct {
ChatID ChatID `json:"chat_id"`
Photo string `json:"photo,omitempty"`
SendPhotoOptions
}
func newSendPhotoParams(chatID ChatID, photo string, options *SendPhotoOptions) *sendPhotoParams {
params := &sendPhotoParams{
ChatID: chatID,
Photo: photo,
}
if options != nil {
params.SendPhotoOptions = *options
}
return params
}
type sendAudioParams struct {
ChatID ChatID `json:"chat_id"`
Audio string `json:"audio,omitempty"`
SendAudioOptions
}
func newSendAudioParams(chatID ChatID, audio string, options *SendAudioOptions) *sendAudioParams {
params := &sendAudioParams{
ChatID: chatID,
Audio: audio,
}
if options != nil {
params.SendAudioOptions = *options
}
return params
}
type sendDocumentParams struct {
ChatID ChatID `json:"chat_id"`
Document string `json:"document,omitempty"`
SendDocumentOptions
}
func newSendDocumentParams(chatID ChatID, document string, options *SendDocumentOptions) *sendDocumentParams {
params := &sendDocumentParams{
ChatID: chatID,
Document: document,
}
if options != nil {
params.SendDocumentOptions = *options
}
return params
}
type sendStickerParams struct {
ChatID ChatID `json:"chat_id"`
Sticker string `json:"sticker,omitempty"`
SendStickerOptions
}
func newSendStickerParams(chatID ChatID, sticker string, options *SendStickerOptions) *sendStickerParams {
params := &sendStickerParams{
ChatID: chatID,
Sticker: sticker,
}
if options != nil {
params.SendStickerOptions = *options
}
return params
}
type sendVideoParams struct {
ChatID ChatID `json:"chat_id"`
Video string `json:"video,omitempty"`
SendVideoOptions
}
func newSendVideoParams(chatID ChatID, video string, options *SendVideoOptions) *sendVideoParams {
params := &sendVideoParams{
ChatID: chatID,
Video: video,
}
if options != nil {
params.SendVideoOptions = *options
}
return params
}
type sendVoiceParams struct {
ChatID ChatID `json:"chat_id"`
Voice string `json:"voice,omitempty"`
SendVoiceOptions
}
func newSendVoiceParams(chatID ChatID, voice string, options *SendVoiceOptions) *sendVoiceParams {
params := &sendVoiceParams{
ChatID: chatID,
Voice: voice,
}
if options != nil {
params.SendVoiceOptions = *options
}
return params
}
type sendVideoNoteParams struct {
ChatID ChatID `json:"chat_id"`
VideoNote string `json:"video_note,omitempty"`
SendVideoNoteOptions
}
func newSendVideoNoteParams(chatID ChatID, videoNote string, options *SendVideoNoteOptions) *sendVideoNoteParams {
params := &sendVideoNoteParams{
ChatID: chatID,
VideoNote: videoNote,
}
if options != nil {
params.SendVideoNoteOptions = *options
}
return params
}
type sendLocationParams struct {
ChatID ChatID `json:"chat_id"`
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
SendLocationOptions
}
func newSendLocationParams(chatID ChatID, latitude, longitude float64, options *SendLocationOptions) *sendLocationParams {
params := &sendLocationParams{
ChatID: chatID,
Latitude: latitude,
Longitude: longitude,
}
if options != nil {
params.SendLocationOptions = *options
}
return params
}
type sendVenueParams struct {
ChatID ChatID `json:"chat_id"`
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
Title string `json:"title,omitempty"`
Address string `json:"address,omitempty"`
SendVenueOptions
}
func newSendVenueParams(chatID ChatID, latitude, longitude float64, title, address string, options *SendVenueOptions) *sendVenueParams {
params := &sendVenueParams{
ChatID: chatID,
Latitude: latitude,
Longitude: longitude,
Title: title,
Address: address,
}
if options != nil {
params.SendVenueOptions = *options
}
return params
}
type sendContactParams struct {
ChatID ChatID `json:"chat_id"`
PhoneNumber string `json:"phone_number"`
FirstName string `json:"first_name"`
LastName string `json:"last_name,omitempty"`
SendContactOptions
}
func newSendContactParams(chatID ChatID, phoneNumber, firstName, lastName string, options *SendContactOptions) *sendContactParams {
params := &sendContactParams{
ChatID: chatID,
PhoneNumber: phoneNumber,
FirstName: firstName,
LastName: lastName,
}
if options != nil {
params.SendContactOptions = *options
}
return params
}
type sendGameParams struct {
ChatID ChatID `json:"chat_id"`
GameShortName string `json:"game_short_name"`
SendGameOptions
}
type setGameScoreParams struct {
UserID int64 `json:"user_id"`
Score int `json:"score"`
SetGameScoreOptions
}
type answerCallbackQueryParams struct {
CallbackQueryID string `json:"callback_query_id"`
AnswerCallbackQueryOptions
}
func newAnswerCallbackQueryParams(callbackQueryID string, options *AnswerCallbackQueryOptions) *answerCallbackQueryParams {
params := &answerCallbackQueryParams{
CallbackQueryID: callbackQueryID,
}
if options != nil {
params.AnswerCallbackQueryOptions = *options
}
return params
}
type editMessageTextParams struct {
ChatID ChatID `json:"chat_id,omitempty"`
MessageID int64 `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
Text string `json:"text"`
EditMessageTextOptions
}
type editMessageCationParams struct {
ChatID ChatID `json:"chat_id,omitempty"`
MessageID int64 `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
EditMessageCationOptions
}
type editMessageReplyMarkupParams struct {
ChatID ChatID `json:"chat_id,omitempty"`
MessageID int64 `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
}
type answerInlineQueryParams struct {
InlineQueryID string `json:"inline_query_id"`
Results InlineQueryResults `json:"results"`
AnswerInlineQueryOptions
}