forked from yanzay/tbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdates.go
451 lines (413 loc) · 17.2 KB
/
updates.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
package tbot
import (
"encoding/json"
"fmt"
)
// User is telegram user
type User struct {
ID int `json:"id"`
IsBot bool `json:"is_bot"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Username string `json:"username"`
LanguageCode string `json:"language_code"`
CanJoinGroups bool `json:"can_join_groups"`
CanReadAllGroupMessages bool `json:"can_read_all_group_messages"`
SupportsInlineQueries bool `json:"supports_inline_queries"`
}
// ChatPhoto represents a chat photo
type ChatPhoto struct {
SmallFileID string `json:"small_file_id"`
SmallFileUniqueID string `json:"small_file_unique_id"`
BigFileID string `json:"big_file_id"`
BigFileUniqueID string `json:"big_file_unique_id"`
}
// Chat represents a chat
type Chat struct {
ID string
Type string
Title string
Username string
FirstName string
LastName string
Photo *ChatPhoto
Description string
InviteLink string
PinnedMessage *Message
Permissions *ChatPermissions
StickerSetName string
AllMembersAreAdministrators bool // deprecated
SlowModeDelay int
CanSetStickerSet bool
}
// UnmarshalJSON implements json.Unmarshaler
func (c *Chat) UnmarshalJSON(data []byte) error {
s := &struct {
ID int `json:"id"`
Type string `json:"type"`
Title string `json:"title"`
Username string `json:"username"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Photo *ChatPhoto `json:"photo"`
Description string `json:"description"`
InviteLink string `json:"invite_link"`
PinnedMessage *Message `json:"pinned_message"`
StickerSetName string `json:"sticker_set_name"`
Permissions *ChatPermissions `json:"permissions"`
AllMembersAreAdministrators bool `json:"all_members_are_administrators"`
SlowModeDelay int `json:"slow_mode_delay"`
CanSetStickerSet bool `json:"can_set_sticker_set"`
}{}
err := json.Unmarshal(data, s)
if err != nil {
return err
}
*c = Chat{
ID: fmt.Sprint(s.ID),
Type: s.Type,
Title: s.Title,
Username: s.Username,
FirstName: s.FirstName,
LastName: s.LastName,
Photo: s.Photo,
Description: s.Description,
InviteLink: s.InviteLink,
PinnedMessage: s.PinnedMessage,
Permissions: s.Permissions,
StickerSetName: s.StickerSetName,
AllMembersAreAdministrators: s.AllMembersAreAdministrators,
SlowModeDelay: s.SlowModeDelay,
CanSetStickerSet: s.CanSetStickerSet,
}
return nil
}
// MessageEntity represents one special entity in a text message.
// For example, hashtags, usernames, URLs, etc.
type MessageEntity struct {
Type string `json:"type"`
Offset int `json:"offset"`
Length int `json:"length"`
URL string `json:"url"`
User *User `json:"user"`
Language string `json:"language"`
}
// Audio represents an audio file to be treated as music by the Telegram clients
type Audio struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Duration int `json:"duration"`
Performer string `json:"performer"`
Title string `json:"title"`
MIMEType string `json:"mime_type"`
FileSize int `json:"file_size"`
}
// PhotoSize represents one size of a photo or a file/sticker thumbnail.
type PhotoSize struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Width int `json:"width"`
Height int `json:"height"`
FileSize int `json:"file_size"`
}
// Document represents a general file
// (as opposed to photos, voice messages and audio files)
type Document struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Thumb *PhotoSize `json:"thumb"`
FileName string `json:"file_name"`
MIMEType string `json:"mime_type"`
FileSize int `json:"file_size"`
}
// Game represents a game. Use BotFather to create and edit games,
// their short names will act as unique identifiers.
type Game struct {
Title string `json:"title"`
Description string `json:"description"`
Photo []*PhotoSize `json:"photo"`
Text string `json:"text"`
TextEntities []*MessageEntity `json:"text_entities"`
Animation *Animation `json:"animation"`
}
// Animation represents an animation file
// to be displayed in the message containing a game
type Animation struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Thumb *PhotoSize `json:"thumb"`
FileName string `json:"file_name"`
MimeType string `json:"mime_type"`
FileSize int `json:"file_size"`
}
// Sticker represents a sticker
type Sticker struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Width int `json:"width"`
Height int `json:"height"`
IsAnimated bool `json:"is_animated"`
Thumb *PhotoSize `json:"thumb"`
Emoji string `json:"emoji"`
MaskPosition *MaskPosition `json:"mask_position"`
SetName string `json:"set_name"`
FileSize int `json:"file_size"`
}
// MaskPosition describes the position on faces
// where a mask should be placed by default
type MaskPosition struct {
Point string `json:"point"`
XShift float32 `json:"x_shift"`
YShift float32 `json:"y_shift"`
Scale float32 `json:"scale"`
}
// Video represents a video file
type Video struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Width int `json:"width"`
Height int `json:"height"`
Duration int `json:"duration"`
Thumbnail *PhotoSize `json:"thumb"`
MimeType string `json:"mime_type"`
FileSize int `json:"file_size"`
}
// Voice represents a voice note
type Voice struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Duration int `json:"duration"`
MimeType string `json:"mime_type"`
FileSize int `json:"file_size"`
}
// VideoNote represents a video message
type VideoNote struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Length int `json:"length"`
Duration int `json:"duration"`
Thumb *PhotoSize `json:"thumb"`
FileSize int `json:"file_size"`
}
// Contact represents a phone contact
type Contact struct {
PhoneNumber string `json:"phone_number"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
UserID int `json:"user_id"`
}
// Location represents a point on the map
type Location struct {
Longitude float64 `json:"longitude"`
Latitude float64 `json:"latitude"`
}
// Venue represents a venue
type Venue struct {
Location Location `json:"location"`
Title string `json:"title"`
Address string `json:"address"`
FoursquareID string `json:"foursquare_id"`
}
// Invoice contains basic information about an invoice
type Invoice struct {
Title string `json:"title"`
Description string `json:"description"`
StartParameter string `json:"start_parameter"`
Currency string `json:"currency"`
TotalAmount int `json:"total_amount"`
}
// SuccessfulPayment contains basic information about a successful payment
type SuccessfulPayment struct {
Currency string `json:"currency"`
TotalAmount int `json:"total_amount"`
InvoicePayload string `json:"invoice_payload"`
ShippingOptionID string `json:"shipping_option_id"`
OrderInfo *OrderInfo `json:"order_info"`
TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
}
// OrderInfo represents information about an order
type OrderInfo struct {
Name string `json:"name"`
PhoneNumber string `json:"phone_number"`
Email string `json:"email"`
ShippingAddress *ShippingAddress `json:"shipping_address"`
}
// ShippingAddress represents a shipping address
type ShippingAddress struct {
CountryCode string `json:"country_code"`
State string `json:"state"`
City string `json:"city"`
StreetLine1 string `json:"street_line1"`
StreetLine2 string `json:"street_line2"`
PostCode string `json:"post_code"`
}
// Message represents a message
type Message struct {
MessageID int `json:"message_id"`
From *User `json:"from"`
Date int64 `json:"date"`
Chat Chat `json:"chat"`
ForwardFrom *User `json:"forward_from"`
ForwardFromChat *Chat `json:"forward_from_chat"`
ForwardFromMessageID int `json:"forward_from_message_id"`
ForwardSignature string `json:"forward_signature"`
ForwardSenderName string `json:"forward_sender_name"`
ForwardDate int64 `json:"forward_date"`
ReplyToMessage *Message `json:"reply_to_message"`
EditDate int64 `json:"edit_date"`
MediaGroupID string `json:"media_group_id"`
AuthorSignature string `json:"author_signature"`
Text string `json:"text"`
Entities []*MessageEntity `json:"entities"`
CaptionEntities []*MessageEntity `json:"caption_entities"`
Audio *Audio `json:"audio"`
Document *Document `json:"document"`
Game *Game `json:"game"`
Photo []*PhotoSize `json:"photo"`
Sticker *Sticker `json:"sticker"`
Video *Video `json:"video"`
Voice *Voice `json:"voice"`
VideoNote *VideoNote `json:"video_note"`
Caption string `json:"caption"`
Contact *Contact `json:"contact"`
Location *Location `json:"location"`
Venue *Venue `json:"venue"`
Poll *Poll `json:"poll"`
Dice *Dice `json:"dice"`
NewChatMembers []*User `json:"new_chat_members"`
LeftChatMember *User `json:"left_chat_member"`
NewChatTitle string `json:"new_chat_title"`
NewChatPhoto []*PhotoSize `json:"new_chat_photo"`
DeleteChatPhoto bool `json:"delete_chat_photo"`
GroupChatCreated bool `json:"group_chat_created"`
SupergroupChatCreated bool `json:"supergroup_chat_created"`
ChannelChatCreated bool `json:"channel_chat_created"`
MigrateToChatID int `json:"migrate_to_chat_id"`
MigrateFromChatID int `json:"migrate_from_chat_id"`
PinnedMessage *Message `json:"pinned_message"`
Invoice *Invoice `json:"invoice"`
SuccessfulPayment *SuccessfulPayment `json:"successful_payment"`
ConnectedWebsite string `json:"connected_website"`
PassportData *PassportData `json:"passport_data"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
}
// InlineQuery represents an incoming inline query
type InlineQuery struct {
ID string `json:"id"`
From *User `json:"from"`
Location *Location `json:"location"`
Query string `json:"query"`
Offset string `json:"offset"`
}
// ChosenInlineResult represents a result of an inline query
// that was chosen by the user and sent to their chat partner
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"`
}
// CallbackQuery represents an incoming callback query
// from a callback button in an inline keyboard
type CallbackQuery struct {
ID string `json:"id"`
From *User `json:"from"`
Message *Message `json:"message"`
InlineMessageID string `json:"inline_message_id"`
ChatInstance string `json:"chat_instance"`
Data string `json:"data"`
GameShortName string `json:"game_short_name"`
}
// ShippingQuery contains information about an incoming shipping query
type ShippingQuery struct {
ID string `json:"id"`
From *User `json:"from"`
InvoicePayload string `json:"invoice_payload"`
ShippingAddress *ShippingAddress `json:"shipping_address"`
}
// PreCheckoutQuery contains information about an incoming pre-checkout query
type PreCheckoutQuery struct {
ID string `json:"id"`
From *User `json:"from"`
Currency string `json:"currency"`
TotalAmount int `json:"total_amount"`
InvoicePayload string `json:"invoice_payload"`
ShippingOptionID string `json:"shipping_option_id"`
OrderInfo *OrderInfo `json:"order_info"`
}
// Update represents an incoming update
// UpdateID is unique identifier
// At most one of the other fields can be not nil
type Update struct {
UpdateID int `json:"update_id"`
Message *Message `json:"message"`
EditedMessage *Message `json:"edited_message"`
ChannelPost *Message `json:"channel_post"`
EditedChannelPost *Message `json:"edited_channel_post"`
InlineQuery *InlineQuery `json:"inline_query"`
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
CallbackQuery *CallbackQuery `json:"callback_query"`
ShippingQuery *ShippingQuery `json:"shipping_query"`
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query"`
Poll *Poll `json:"poll"`
PollAnswer *PollAnswer `json:"poll_answer"`
}
// PassportData contains information about Telegram Passport data shared with the bot by the user
type PassportData struct {
Data []EncryptedPassportElement `json:"data"`
Credentials EncryptedCredentials `json:"credentials"`
}
// EncryptedPassportElement contains information about documents or other Telegram Passport elements shared with the bot by the user
type EncryptedPassportElement struct {
Type string `json:"type"`
Data string `json:"data"`
PhoneNumber string `json:"phone_number"`
Email string `json:"email"`
Files []*PassportFile `json:"files"`
FrontSide *PassportFile `json:"front_side"`
ReverseSide *PassportFile `json:"reverse_side"`
Selfie *PassportFile `json:"selfie"`
}
// PassportFile represents a file uploaded to Telegram Passport
type PassportFile struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
FileSize int `json:"file_size"`
FileDate int `json:"file_date"`
}
// EncryptedCredentials contains data required for decrypting and authenticating EncryptedPassportElement
type EncryptedCredentials struct {
Data string `json:"data"`
Hash string `json:"hash"`
Secret string `json:"secret"`
}
// Poll represents native telegram poll
type Poll struct {
ID string `json:"id"`
Question string `json:"question"`
Options []PollOption `json:"options"`
TotalVoterCount int `json:"total_voter_count"`
IsClosed bool `json:"is_closed"`
IsAnonymous bool `json:"is_anonymous"`
Type string `json:"type"`
AllowsMultipleAnswers bool `json:"allows_multiple_answers"`
CorrectOptionID int `json:"correct_option_id"`
}
// Dice represents native telegram dice
type Dice struct {
Emoji string `json:"emoji"`
Value int `json:"value"`
}
// PollOption is an option for Poll
type PollOption struct {
Text string `json:"text"`
VoterCount int `json:"voter_count"`
}
// PollAnswer represents an answer of a user in a non-anonymous poll
type PollAnswer struct {
PollID int `json:"poll_id"`
User User `json:"user"`
OptionIDs []int `json:"option_ids"`
}