-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_inline.go
More file actions
262 lines (222 loc) · 8.03 KB
/
types_inline.go
File metadata and controls
262 lines (222 loc) · 8.03 KB
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
// This file is part of Camponotus
// Camponotus is free software: see LICENSE.txt for more details.
package telegram
// InlineQuery represents an incoming inline query.
// When the user sends an empty query, your bot could return some default or trending results.
type InlineQuery struct {
ID string `json:"id"`
From *Victim `json:"from"`
Location *Location `json:"location,omitempty"`
Query string `json:"query"`
Offset string `json:"offset"`
}
// InlineQueryResult holds methods for all kinds of inline query results
type InlineQueryResult interface {
ValidateType() // validates the result type
}
// IQR holds common fields for inline query results
type IQR struct {
Type string `json:"type"`
ID string `json:"id"`
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
ThumbURL string `json:"thumb_url,omitempty"`
ThumbWidth int `json:"thumb_width,omitempty"`
ThumbHeight int `json:"thumb_height,omitempty"`
}
// InlineQueryResultArticle represents a link to an article or web page.
type InlineQueryResultArticle struct {
IQR
URL string `json:"url,omitempty"`
HideURL bool `json:"hide_url,omitempty"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultArticle) ValidateType() {
r.IQR.Type = "article"
}
// InlineQueryResultPhoto represents a link to a photo.
type InlineQueryResultPhoto struct {
IQR
URL string `json:"photo_url,omitempty"`
FileID string `json:"photo_file_id,omitempty"`
Width int `json:"photo_width,omitempty"`
Height int `json:"photo_height,omitempty"`
Caption string `json:"caption,omitempty"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultPhoto) ValidateType() {
r.IQR.Type = "photo"
}
// InlineQueryResultGif represents a link to an animated GIF file.
type InlineQueryResultGif struct {
IQR
URL string `json:"gif_url,omitempty"`
FileID string `json:"gif_file_id,omitempty"`
Width int `json:"git_width,omitempty"`
Height int `json:"gif_height,omitempty"`
Caption string `json:"caption,omitempty"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultGif) ValidateType() {
r.IQR.Type = "gif"
}
// InlineQueryResultMpeg4Gif represents a link to a video animation.
type InlineQueryResultMpeg4Gif struct {
IQR
URL string `json:"mpeg4_url,omitempty"`
FileID string `json:"mpeg4_file_id,omitempty"`
Width int `json:"mpeg4_width,omitempty"`
Height int `json:"mpeg4_height,omitempty"`
Caption string `json:"caption,omitempty"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultMpeg4Gif) ValidateType() {
r.IQR.Type = "mpeg4_gif"
}
// InlineQueryResultVideo represnets a link to a page containing an embedded video player or a video file.
type InlineQueryResultVideo struct {
IQR
URL string `json:"video_url,omitempty"`
FileID string `json:"video_file_id,omitempty"`
MimeType string `json:"mime_type"`
Caption string `json:"caption,omitempty"`
Width int `json:"video_width,omitempty"`
Height int `json:"video_height,omitempty"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultVideo) ValidateType() {
r.IQR.Type = "video"
}
// InlineQueryResultAudio represents a link to an mp3 audio file.
type InlineQueryResultAudio struct {
IQR
URL string `json:"audio_url,omitempty"`
FileID string `json:"audio_file_id,omitempty"`
Performer string `json:"performer,omitempty"`
Duration int `json:"audio_duration,omitempty"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultAudio) ValidateType() {
r.IQR.Type = "audio"
}
// InlineQueryResultVoice represents a link to a voice recording in an .off container encoded with OPUS.
type InlineQueryResultVoice struct {
IQR
URL string `json:"voice_url,omitempty"`
FileID string `json:"voice_file_id,omitempty"`
Duration int `json:"voice_duration,omitempty"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultVoice) ValidateType() {
r.IQR.Type = "voice"
}
// InlineQueryResultDocument represents a link to a file.
type InlineQueryResultDocument struct {
IQR
Caption string `json:"caption,omitempty"`
URL string `json:"document_url,omitempty"`
FileID string `json:"document_file_id,omitempty"`
MimeType string `json:"mime_type"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultDocument) ValidateType() {
r.IQR.Type = "document"
}
// InlineQueryResultLocation represents a location on a map.
type InlineQueryResultLocation struct {
IQR
Lat float64 `json:"latitude"`
Lng float64 `json:"longitude"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultLocation) ValidateType() {
r.IQR.Type = "location"
}
// InlineQueryResultVenue represents a venue.
type InlineQueryResultVenue struct {
IQR
Lat float64 `json:"latitude"`
Lng float64 `json:"longitude"`
Address string `json:"address"`
Foursquare string `json:"foursquare_id,omitempty"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultVenue) ValidateType() {
r.IQR.Type = "venue"
}
// InlineQueryResultContact represents a contact with a phone number.
type InlineQueryResultContact struct {
IQR
PhoneNumber string `json:"phone_number"`
FirstName string `json:"first_name"`
LastName string `json:"last_name,omitempty"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultContact) ValidateType() {
r.IQR.Type = "contact"
}
// InlineQueryResultSticker represents a link to a sticker stored on the Telegram servers.
//
// This struct maps to https://core.telegram.org/bots/api#inlinequeryresultcachedsticker
type InlineQueryResultSticker struct {
IQR
FileID string `json:"sticker_file_id"`
}
// ValidateType validate and rewrite result type
func (r *InlineQueryResultSticker) ValidateType() {
r.IQR.Type = "sticker"
}
// InputMessageContent represents the content of a message to be sent as an result of an inline query.
type InputMessageContent map[string]interface{}
// InputTextMessageContent creates an InputMessageContent for text message
func InputTextMessageContent(msg, mode string, noPreview bool) InputMessageContent {
ret := map[string]interface{}{"message_text": msg}
if mode != "" {
ret["parse_mode"] = mode
}
if noPreview {
ret["disable_web_page_preview"] = true
}
return InputMessageContent(ret)
}
// InputLocationMessageContent creates an InputMessageContent for location message
func InputLocationMessageContent(lat, lng float64) InputMessageContent {
return InputMessageContent(map[string]interface{}{
"latitude": lat,
"longitude": lng,
})
}
// InputVenueMessageContent creates an InputMessageContent for venue message
func InputVenueMessageContent(lat, lng float64, title, addr, foursq string) InputMessageContent {
ret := map[string]interface{}{
"latitude": lat,
"longitude": lng,
"title": title,
"address": addr,
}
if foursq != "" {
ret["foursquare_id"] = foursq
}
return InputMessageContent(ret)
}
// InputContactMessageContent creates an InputMessageContent for contact message
func InputContactMessageContent(phone, firstName, lastName string) InputMessageContent {
ret := map[string]interface{}{
"phone_number": phone,
"first_name": firstName,
}
if lastName != "" {
ret["last_name"] = lastName
}
return InputMessageContent(ret)
}
// ChosenInlineResult represents a result of an inline query that was chosen by the user and sent to their chat partner.
type ChosenInlineResult struct {
ID string `json:"result_id"`
From *Victim `json:"from"`
Location *Location `json:"location,omitempty"`
InlineID string `json:"inline_message_id,omitempty"`
Query string `json:"query,omitempty"`
}