@@ -3,6 +3,7 @@ package tgbotapi
33import (
44 "encoding/json"
55 "fmt"
6+ "net/url"
67 "strings"
78 "time"
89)
@@ -22,6 +23,7 @@ type Update struct {
2223 Message Message `json:"message"`
2324 InlineQuery InlineQuery `json:"inline_query"`
2425 ChosenInlineResult ChosenInlineResult `json:"chosen_inline_result"`
26+ CallbackQuery CallbackQuery `json:"callback_query"`
2527}
2628
2729// User is a user on Telegram.
@@ -88,33 +90,36 @@ func (c *Chat) IsChannel() bool {
8890// Message is returned by almost every request, and contains data about
8991// almost anything.
9092type Message struct {
91- MessageID int `json:"message_id"`
92- From User `json:"from"` // optional
93- Date int `json:"date"`
94- Chat Chat `json:"chat"`
95- ForwardFrom User `json:"forward_from"` // optional
96- ForwardDate int `json:"forward_date"` // optional
97- ReplyToMessage * Message `json:"reply_to_message"` // optional
98- Text string `json:"text"` // optional
99- Audio Audio `json:"audio"` // optional
100- Document Document `json:"document"` // optional
101- Photo []PhotoSize `json:"photo"` // optional
102- Sticker Sticker `json:"sticker"` // optional
103- Video Video `json:"video"` // optional
104- Voice Voice `json:"voice"` // optional
105- Caption string `json:"caption"` // optional
106- Contact Contact `json:"contact"` // optional
107- Location Location `json:"location"` // optional
108- NewChatParticipant User `json:"new_chat_participant"` // optional
109- LeftChatParticipant User `json:"left_chat_participant"` // optional
110- NewChatTitle string `json:"new_chat_title"` // optional
111- NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional
112- DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
113- GroupChatCreated bool `json:"group_chat_created"` // optional
114- SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
115- ChannelChatCreated bool `json:"channel_chat_created"` // optional
116- MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
117- MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional
93+ MessageID int `json:"message_id"`
94+ From User `json:"from"` // optional
95+ Date int `json:"date"`
96+ Chat Chat `json:"chat"`
97+ ForwardFrom User `json:"forward_from"` // optional
98+ ForwardDate int `json:"forward_date"` // optional
99+ ReplyToMessage * Message `json:"reply_to_message"` // optional
100+ Text string `json:"text"` // optional
101+ Entities []MessageEntity `json:"entities"` // optional
102+ Audio Audio `json:"audio"` // optional
103+ Document Document `json:"document"` // optional
104+ Photo []PhotoSize `json:"photo"` // optional
105+ Sticker Sticker `json:"sticker"` // optional
106+ Video Video `json:"video"` // optional
107+ Voice Voice `json:"voice"` // optional
108+ Caption string `json:"caption"` // optional
109+ Contact Contact `json:"contact"` // optional
110+ Location Location `json:"location"` // optional
111+ Venue Venue `json:"venue"` // optional
112+ NewChatMember User `json:"new_chat_member"` // optional
113+ LeftChatMember User `json:"left_chat_member"` // optional
114+ NewChatTitle string `json:"new_chat_title"` // optional
115+ NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional
116+ DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
117+ GroupChatCreated bool `json:"group_chat_created"` // optional
118+ SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
119+ ChannelChatCreated bool `json:"channel_chat_created"` // optional
120+ MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
121+ MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional
122+ PinnedMessage * Message `json:"pinned_message"` // optional
118123}
119124
120125// Time converts the message timestamp into a Time.
@@ -161,6 +166,19 @@ func (m *Message) CommandArguments() string {
161166 return strings .SplitN (m .Text , " " , 2 )[1 ]
162167}
163168
169+ // MessageEntity contains information about data in a Message.
170+ type MessageEntity struct {
171+ Type string `json:"type"`
172+ Offset int `json:"offset"`
173+ Length int `json:"length"`
174+ URL string `json:"url"` // optional
175+ }
176+
177+ // ParseURL attempts to parse a URL contained within a MessageEntity.
178+ func (entity MessageEntity ) ParseURL () (* url.URL , error ) {
179+ return url .Parse (entity .URL )
180+ }
181+
164182// PhotoSize contains information about photos.
165183type PhotoSize struct {
166184 FileID string `json:"file_id"`
@@ -232,6 +250,14 @@ type Location struct {
232250 Latitude float32 `json:"latitude"`
233251}
234252
253+ // Venue contains information about a venue, including its Location.
254+ type Venue struct {
255+ Location Location `json:"location"`
256+ Title string `json:"title"`
257+ Address string `json:"address"`
258+ FoursquareID string `json:"foursquare_id"` // optional
259+ }
260+
235261// UserProfilePhotos contains a set of user profile photos.
236262type UserProfilePhotos struct {
237263 TotalCount int `json:"total_count"`
@@ -254,10 +280,17 @@ func (f *File) Link(token string) string {
254280
255281// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
256282type ReplyKeyboardMarkup struct {
257- Keyboard [][]string `json:"keyboard"`
258- ResizeKeyboard bool `json:"resize_keyboard"` // optional
259- OneTimeKeyboard bool `json:"one_time_keyboard"` // optional
260- Selective bool `json:"selective"` // optional
283+ Keyboard [][]KeyboardButton `json:"keyboard"`
284+ ResizeKeyboard bool `json:"resize_keyboard"` // optional
285+ OneTimeKeyboard bool `json:"one_time_keyboard"` // optional
286+ Selective bool `json:"selective"` // optional
287+ }
288+
289+ // KeyboardButton is a button within a custom keyboard.
290+ type KeyboardButton struct {
291+ Text string `json:"text"`
292+ RequestContact bool `json:"request_contact"`
293+ RequestLocation bool `json:"request_location"`
261294}
262295
263296// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
@@ -266,6 +299,33 @@ type ReplyKeyboardHide struct {
266299 Selective bool `json:"selective"` // optional
267300}
268301
302+ // InlineKeyboardMarkup is a custom keyboard presented for an inline bot.
303+ type InlineKeyboardMarkup struct {
304+ InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
305+ }
306+
307+ // InlineKeyboardButton is a button within a custom keyboard for
308+ // inline query responses.
309+ //
310+ // Note that some values are references as even an empty string
311+ // will change behavior.
312+ type InlineKeyboardButton struct {
313+ Text string `json:"text"`
314+ URL * string `json:"url"` // optional
315+ CallbackData * string `json:"callback_data"` // optional
316+ SwitchInlineQuery * string `json:"switch_inline_query"` // optional
317+ }
318+
319+ // CallbackQuery is data sent when a keyboard button with callback data
320+ // is clicked.
321+ type CallbackQuery struct {
322+ ID string `json:"id"`
323+ From User `json:"from"`
324+ Message Message `json:"message"` // optional
325+ InlineMessageID string `json:"inline_message_id"` // optional
326+ Data string `json:"data"` // optional
327+ }
328+
269329// ForceReply allows the Bot to have users directly reply to it without
270330// additional interaction.
271331type ForceReply struct {
@@ -275,10 +335,11 @@ type ForceReply struct {
275335
276336// InlineQuery is a Query from Telegram for an inline request.
277337type InlineQuery struct {
278- ID string `json:"id"`
279- From User `json:"from"`
280- Query string `json:"query"`
281- Offset string `json:"offset"`
338+ ID string `json:"id"`
339+ From User `json:"from"`
340+ Location Location `json:"location"` // optional
341+ Query string `json:"query"`
342+ Offset string `json:"offset"`
282343}
283344
284345// InlineQueryResultArticle is an inline query response article.
0 commit comments