Skip to content

Commit 18510df

Browse files
author
Syfaro
committed
Add some of the new methods and types.
1 parent 5c46b08 commit 18510df

File tree

3 files changed

+153
-40
lines changed

3 files changed

+153
-40
lines changed

bot.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,23 @@ func (bot *BotAPI) AnswerInlineQuery(config InlineConfig) (APIResponse, error) {
482482
return APIResponse{}, err
483483
}
484484
v.Add("results", string(data))
485+
v.Add("switch_pm_text", config.SwitchPMText)
486+
v.Add("switch_pm_parameter", config.SwitchPMParameter)
485487

486488
bot.debugLog("answerInlineQuery", v, nil)
487489

488490
return bot.MakeRequest("answerInlineQuery", v)
489491
}
492+
493+
// AnswerCallbackQuery sends a response to an inline query callback.
494+
func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, error) {
495+
v := url.Values{}
496+
497+
v.Add("callback_query_id", config.CallbackQueryID)
498+
v.Add("text", config.Text)
499+
v.Add("show_alert", strconv.FormatBool(config.ShowAlert))
500+
501+
bot.debugLog("answerCallbackQuery", v, nil)
502+
503+
return bot.MakeRequest("answerCallbackQuery", v)
504+
}

configs.go

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,34 @@ func (config LocationConfig) method() string {
454454
return "sendLocation"
455455
}
456456

457+
// VenueConfig contains information about a SendVenue request.
458+
type VenueConfig struct {
459+
BaseChat
460+
Latitude float64 // required
461+
Longitude float64 // required
462+
Title string // required
463+
Address string // required
464+
FoursquareID string
465+
}
466+
467+
func (config VenueConfig) values() (url.Values, error) {
468+
v, _ := config.BaseChat.values()
469+
470+
v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64))
471+
v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64))
472+
v.Add("title", config.Title)
473+
v.Add("address", config.Address)
474+
if config.FoursquareID != "" {
475+
v.Add("foursquare_id", config.FoursquareID)
476+
}
477+
478+
return v, nil
479+
}
480+
481+
func (config VenueConfig) method() string {
482+
return "sendVenue"
483+
}
484+
457485
// ChatActionConfig contains information about a SendChatAction request.
458486
type ChatActionConfig struct {
459487
BaseChat
@@ -516,9 +544,18 @@ type FileReader struct {
516544

517545
// InlineConfig contains information on making an InlineQuery response.
518546
type InlineConfig struct {
519-
InlineQueryID string `json:"inline_query_id"`
520-
Results []interface{} `json:"results"`
521-
CacheTime int `json:"cache_time"`
522-
IsPersonal bool `json:"is_personal"`
523-
NextOffset string `json:"next_offset"`
547+
InlineQueryID string `json:"inline_query_id"`
548+
Results []interface{} `json:"results"`
549+
CacheTime int `json:"cache_time"`
550+
IsPersonal bool `json:"is_personal"`
551+
NextOffset string `json:"next_offset"`
552+
SwitchPMText string `json:"switch_pm_text"`
553+
SwitchPMParameter string `json:"switch_pm_parameter"`
554+
}
555+
556+
// CallbackConfig contains information on making a CallbackQuery response.
557+
type CallbackConfig struct {
558+
CallbackQueryID string `json:"callback_query_id"`
559+
Text string `json:"text"`
560+
ShowAlert bool `json:"show_alert"`
524561
}

types.go

Lines changed: 96 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tgbotapi
33
import (
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.
9092
type 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.
165183
type 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.
236262
type 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.
256282
type 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.
271331
type ForceReply struct {
@@ -275,10 +335,11 @@ type ForceReply struct {
275335

276336
// InlineQuery is a Query from Telegram for an inline request.
277337
type 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

Comments
 (0)