/
inline_mode.go
372 lines (336 loc) · 15.6 KB
/
inline_mode.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
package ext
import (
"encoding/json"
"net/url"
"strconv"
"github.com/pkg/errors"
)
type InlineQuery struct {
Id string `json:"id"`
From *User `json:"from"`
Location *Location `json:"location"`
Query string `json:"query"`
Offset string `json:"offset"`
}
type InlineQueryResult struct{}
type InlineQueryResultArticle struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
Title string `json:"title"`
InputMessageContent InputMessageContent `json:"input_message_content"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
Url string `json:"url"`
HideUrl bool `json:"hide_url"`
Description string `json:"description"`
ThumbUrl string `json:"thumb_url"`
ThumbWidth int `json:"thumb_width"`
ThumbHeight int `json:"thumb_height"`
}
type InlineQueryResultPhoto struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
PhotoUrl string `json:"photo_url"`
ThumbUrl string `json:"thumb_url"`
PhotoWidth int `json:"photo_width"`
PhotoHeight int `json:"photo_height"`
Title string `json:"title"`
Description string `json:"description"`
Caption string `json:"caption"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultGif struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
GifUrl string `json:"gif_url"`
GifWidth int `json:"gif_width"`
GifHeight int `json:"gif_height"`
GifDuration int `json:"gif_duration"`
ThumbUrl string `json:"thumb_url"`
Title string `json:"title"`
Caption string `json:"caption"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultMpeg4Gif struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
Mpeg4Url string `json:"mpeg4_url"`
Mpeg4Width int `json:"mpeg4_width"`
Mpeg4Height int `json:"mpeg4_height"`
Mpeg4Duration int `json:"mpeg4_duration"`
ThumbUrl string `json:"thumb_url"`
Title string `json:"title"`
Caption string `json:"caption"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultVideo struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
VideoUrl string `json:"video_url"`
MimeType string `json:"mime_type"`
ThumbUrl string `json:"thumb_url"`
Title string `json:"title"`
Caption string `json:"caption"`
VideoWidth int `json:"video_width"`
VideoHeight int `json:"video_height"`
VideoDuration int `json:"video_duration"`
Description string `json:"description"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultAudio struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
AudioUrl string `json:"audio_url"`
Title string `json:"title"`
Caption string `json:"caption"`
Performer string `json:"performer"`
AudioDuration int `json:"audio_duration"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultVoice struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
VoiceUrl string `json:"voice_url"`
Title string `json:"title"`
Caption string `json:"caption"`
VoiceDuration int `json:"voice_duration"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultDocument struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
Title string `json:"title"`
Caption string `json:"caption"`
DocumentUrl string `json:"document_url"`
MimeType string `json:"mime_type"`
Description string `json:"description"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
ThumbUrl string `json:"thumb_url"`
ThumbWidth int `json:"thumb_width"`
ThumbHeight int `json:"thumb_height"`
}
type InlineQueryResultLocation struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Title string `json:"title"`
HorizontalAccuracy float64 `json:"horizontal_accuracy"`
LivePeriod int `json:"live_period"`
Heading int `json:"heading"`
ProximityAlertRadius int `json:"proximity_alert_radius"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
ThumbUrl string `json:"thumb_url"`
ThumbWidth int `json:"thumb_width"`
ThumbHeight int `json:"thumb_height"`
}
type InlineQueryResultVenue struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Title string `json:"title"`
Address string `json:"address"`
FoursquareId string `json:"foursquare_id"`
FoursquareType string `json:"foursquare_type"`
GooglePlaceId string `json:"google_place_id"`
GooglePlaceType string `json:"google_place_type"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
ThumbUrl string `json:"thumb_url"`
ThumbWidth int `json:"thumb_width"`
ThumbHeight int `json:"thumb_height"`
}
type InlineQueryResultContact struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
PhoneNumber string `json:"phone_number"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
ThumbUrl string `json:"thumb_url"`
ThumbWidth int `json:"thumb_width"`
ThumbHeight int `json:"thumb_height"`
}
type InlineQueryResultGame struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
GameShortName string `json:"game_short_name"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
}
type InlineQueryResultCachedPhoto struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
PhotoFileId string `json:"photo_file_id"`
Title string `json:"title"`
Description string `json:"description"`
Caption string `json:"caption"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultCachedGif struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
GifFileId string `json:"gif_file_id"`
Title string `json:"title"`
Caption string `json:"caption"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultCachedMpeg4Gif struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
Mpeg4FileId string `json:"mpeg4_file_id"`
Title string `json:"title"`
Caption string `json:"caption"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultCachedSticker struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
StickerFileId string `json:"sticker_file_id"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultCachedDocument struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
Title string `json:"title"`
DocumentFileId string `json:"document_file_id"`
Description string `json:"description"`
Caption string `json:"caption"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultCachedVideo struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
VideoFileId string `json:"video_file_id"`
Title string `json:"title"`
Description string `json:"description"`
Caption string `json:"caption"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultCachedVoice struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
VoiceFileId string `json:"voice_file_id"`
Title string `json:"title"`
Caption string `json:"caption"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InlineQueryResultCachedAudio struct {
InlineQueryResult
Type string `json:"type"`
Id string `json:"id"`
AudioFileId string `json:"audio_file_id"`
Caption string `json:"caption"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
InputMessageContent InputMessageContent `json:"input_message_content"`
}
type InputMessageContent struct{}
type InputTextMessageContent struct {
InputMessageContent
MessageText string `json:"message_text"`
ParseMode string `json:"parse_mode"`
DisableWebPagePreview bool `json:"disable_web_page_preview"`
}
type InputLocationMessageContent struct {
InputMessageContent
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
HorizontalAccuracy float64 `json:"horizontal_accuracy"`
LivePeriod int `json:"live_period"`
Heading int `json:"heading"`
ProximityAlertRadius int `json:"proximity_alert_radius"`
}
type InputVenueMessageContent struct {
InputMessageContent
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Title string `json:"title"`
Address string `json:"address"`
FoursquareId string `json:"foursquare_id"`
FoursquareType string `json:"foursquare_type"`
GooglePlaceId string `json:"google_place_id"`
GooglePlaceType string `json:"google_place_type"`
}
type InputContactMessageContent struct {
InputMessageContent
PhoneNumber string `json:"phone_number"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
type ChosenInlineResult struct {
ResultId string `json:"result_id"`
From *User `json:"from"`
Location Location `json:"location"`
InlineMessageId string `json:"inline_message_id"`
Query string `json:"query"`
}
type sendableAnswerInlineQuery struct {
bot Bot
InlineQueryId string
Results []InlineQueryResult
CacheTime int
IsPersonal bool
NextOffset string
SwitchPmText string
SwitchPmParameter string
}
func (b Bot) NewSendableAnswerInlineQuery(inlineQueryId string, results []InlineQueryResult) *sendableAnswerInlineQuery {
return &sendableAnswerInlineQuery{bot: b, InlineQueryId: inlineQueryId, Results: results}
}
func (aiq sendableAnswerInlineQuery) Send() (bool, error) {
resultsStr, err := json.Marshal(aiq.Results)
if err != nil {
return false, errors.Wrapf(err, "unable to unmarshal answerInlineQuery result")
}
v := url.Values{}
v.Add("inline_query_id", aiq.InlineQueryId)
v.Add("results", string(resultsStr))
v.Add("cache_time", strconv.Itoa(aiq.CacheTime))
v.Add("is_personal", strconv.FormatBool(aiq.IsPersonal))
v.Add("next_offset", aiq.NextOffset)
v.Add("switch_pm_text", aiq.SwitchPmText)
v.Add("switch_pm_parameter", aiq.SwitchPmParameter)
r, err := aiq.bot.Get("answerInlineQuery", v)
if err != nil {
return false, err
}
var bb bool
return bb, json.Unmarshal(r, &bb)
}
func (b Bot) AnswerInlineQuery(inlineQueryId string, results []InlineQueryResult) (bool, error) {
return b.NewSendableAnswerInlineQuery(inlineQueryId, results).Send()
}