forked from tucnak/telebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
210 lines (165 loc) · 5.61 KB
/
types.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
package telebot
import "strconv"
// Recipient is basically any possible endpoint you can send
// messages to. It's usually a distinct user or a chat.
type Recipient interface {
// ID of user or group chat, @Username for channel
Destination() string
}
// User object represents a Telegram user, bot
//
// object represents a group chat if Title is empty.
type User struct {
ID int `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Username string `json:"username"`
}
// Destination is internal user ID.
func (u User) Destination() string {
return strconv.Itoa(u.ID)
}
// Chat object represents a Telegram user, bot or group chat.
// Title for channels and group chats
// Type of chat, can be either “private”, “group”, "supergroup" or “channel”
type Chat struct {
ID int64 `json:"id"`
Type string `json:"type"`
Title string `json:"title"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Username string `json:"username"`
}
// Destination is internal chat ID.
func (c Chat) Destination() string {
ret := "@" + c.Username
if c.Type != "channel" {
ret = strconv.FormatInt(c.ID, 10)
}
return ret
}
// IsGroupChat returns true if chat object represents a group chat.
func (c Chat) IsGroupChat() bool {
return c.Type != "private"
}
// Update object represents an incoming update.
type Update struct {
ID int `json:"update_id"`
Payload *Message `json:"message"`
// optional
Callback *Callback `json:"callback_query"`
Query *Query `json:"inline_query"`
}
// Thumbnail object represents an image/sticker of a particular size.
type Thumbnail struct {
File
Width int `json:"width"`
Height int `json:"height"`
}
// Photo object represents a photo with caption.
type Photo struct {
File
Thumbnail
Caption string
}
// Audio object represents an audio file (voice note).
type Audio struct {
File
// Duration of the recording in seconds as defined by sender.
Duration int `json:"duration"`
// MIME type of the file as defined by sender.
Mime string `json:"mime_type"`
}
// Document object represents a general file (as opposed to Photo or Audio).
// Telegram users can send files of any type of up to 1.5 GB in size.
type Document struct {
File
// Document thumbnail as defined by sender.
Preview Thumbnail `json:"thumb"`
// Original filename as defined by sender.
FileName string `json:"file_name"`
// MIME type of the file as defined by sender.
Mime string `json:"mime_type"`
}
// Sticker object represents a WebP image, so-called sticker.
type Sticker struct {
File
Width int `json:"width"`
Height int `json:"height"`
// Sticker thumbnail in .webp or .jpg format.
Preview Thumbnail `json:"thumb"`
}
// Video object represents an MP4-encoded video.
type Video struct {
Audio
Width int `json:"width"`
Height int `json:"height"`
// Text description of the video as defined by sender (usually empty).
Caption string `json:"caption"`
// Video thumbnail.
Preview Thumbnail `json:"thumb"`
}
// KeyboardButton represents a button displayed on in a message.
type KeyboardButton struct {
Text string `json:"text"`
URL string `json:"url,omitempty"`
Data string `json:"callback_data,omitempty"`
InlineQuery string `json:"switch_inline_query,omitempty"`
}
// InlineKeyboardMarkup represents an inline keyboard that appears right next
// to the message it belongs to.
type InlineKeyboardMarkup struct {
// Array of button rows, each represented by an Array of KeyboardButton objects.
InlineKeyboard [][]KeyboardButton `json:"inline_keyboard,omitempty"`
}
// Contact object represents a contact to Telegram user
type Contact struct {
UserID int `json:"user_id"`
PhoneNumber string `json:"phone_number"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
// Location object represents geographic position.
type Location struct {
Longitude float32 `json:"longitude"`
Latitude float32 `json:"latitude"`
}
// Callback object represents a query from a callback button in an
// inline keyboard.
type Callback struct {
ID string `json:"id"`
// For message sent to channels, Sender may be empty
Sender User `json:"from"`
// Message will be set if the button that originated the query
// was attached to a message sent by a bot.
Message Message `json:"message"`
// MessageID will be set if the button was attached to a message
// sent via the bot in inline mode.
MessageID string `json:"inline_message_id"`
Data string `json:"data"`
}
// Venue object represents a venue location with name, address and optional foursquare id.
type Venue struct {
Location Location `json:"location"`
Title string `json:"title"`
Address string `json:"address"`
Foursquare_id string `json:"foursquare_id",omitempty`
}
// MessageEntity
// This object represents one special entity in a text message.
// For example, hashtags, usernames, URLs, etc
type MessageEntity struct {
// type Type of the entity. Can be mention (@username), hashtag,
// bot_command, url, email, bold (bold text), italic (italic text),
// code (monowidth string), pre (monowidth block), text_link (for clickable text URLs),
// text_mention (for users without usernames)
Type string `json:"type"`
// offset Offset in UTF-16 code units to the start of the entity
Offset int `json:"offset"`
//length Length of the entity in UTF-16 code units
Length int `json:"length"`
//url Optional. For “text_link” only, url that will be opened after user taps on the text
Url string `json:"url",omitempty`
//user Optional. For “text_mention” only, the mentioned user
User User `json:"user",omitempty`
}