Add some of the new methods and types.
Syfaro syfaro@foxpaw.in
Tue, 12 Apr 2016 08:28:46 -0500
3 files changed,
153 insertions(+),
40 deletions(-)
M
bot.go
→
bot.go
@@ -482,8 +482,23 @@ if err != nil {
return APIResponse{}, err } v.Add("results", string(data)) + v.Add("switch_pm_text", config.SwitchPMText) + v.Add("switch_pm_parameter", config.SwitchPMParameter) bot.debugLog("answerInlineQuery", v, nil) return bot.MakeRequest("answerInlineQuery", v) } + +// AnswerCallbackQuery sends a response to an inline query callback. +func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, error) { + v := url.Values{} + + v.Add("callback_query_id", config.CallbackQueryID) + v.Add("text", config.Text) + v.Add("show_alert", strconv.FormatBool(config.ShowAlert)) + + bot.debugLog("answerCallbackQuery", v, nil) + + return bot.MakeRequest("answerCallbackQuery", v) +}
M
configs.go
→
configs.go
@@ -454,6 +454,34 @@ func (config LocationConfig) method() string {
return "sendLocation" } +// VenueConfig contains information about a SendVenue request. +type VenueConfig struct { + BaseChat + Latitude float64 // required + Longitude float64 // required + Title string // required + Address string // required + FoursquareID string +} + +func (config VenueConfig) values() (url.Values, error) { + v, _ := config.BaseChat.values() + + v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64)) + v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64)) + v.Add("title", config.Title) + v.Add("address", config.Address) + if config.FoursquareID != "" { + v.Add("foursquare_id", config.FoursquareID) + } + + return v, nil +} + +func (config VenueConfig) method() string { + return "sendVenue" +} + // ChatActionConfig contains information about a SendChatAction request. type ChatActionConfig struct { BaseChat@@ -516,9 +544,18 @@ }
// InlineConfig contains information on making an InlineQuery response. type InlineConfig struct { - InlineQueryID string `json:"inline_query_id"` - Results []interface{} `json:"results"` - CacheTime int `json:"cache_time"` - IsPersonal bool `json:"is_personal"` - NextOffset string `json:"next_offset"` + InlineQueryID string `json:"inline_query_id"` + Results []interface{} `json:"results"` + CacheTime int `json:"cache_time"` + IsPersonal bool `json:"is_personal"` + NextOffset string `json:"next_offset"` + SwitchPMText string `json:"switch_pm_text"` + SwitchPMParameter string `json:"switch_pm_parameter"` +} + +// CallbackConfig contains information on making a CallbackQuery response. +type CallbackConfig struct { + CallbackQueryID string `json:"callback_query_id"` + Text string `json:"text"` + ShowAlert bool `json:"show_alert"` }
M
types.go
→
types.go
@@ -3,6 +3,7 @@
import ( "encoding/json" "fmt" + "net/url" "strings" "time" )@@ -22,6 +23,7 @@ UpdateID int `json:"update_id"`
Message Message `json:"message"` InlineQuery InlineQuery `json:"inline_query"` ChosenInlineResult ChosenInlineResult `json:"chosen_inline_result"` + CallbackQuery CallbackQuery `json:"callback_query"` } // User is a user on Telegram.@@ -88,33 +90,36 @@
// Message is returned by almost every request, and contains data about // almost anything. type Message struct { - MessageID int `json:"message_id"` - From User `json:"from"` // optional - Date int `json:"date"` - Chat Chat `json:"chat"` - ForwardFrom User `json:"forward_from"` // optional - ForwardDate int `json:"forward_date"` // optional - ReplyToMessage *Message `json:"reply_to_message"` // optional - Text string `json:"text"` // optional - Audio Audio `json:"audio"` // optional - Document Document `json:"document"` // optional - Photo []PhotoSize `json:"photo"` // optional - Sticker Sticker `json:"sticker"` // optional - Video Video `json:"video"` // optional - Voice Voice `json:"voice"` // optional - Caption string `json:"caption"` // optional - Contact Contact `json:"contact"` // optional - Location Location `json:"location"` // optional - NewChatParticipant User `json:"new_chat_participant"` // optional - LeftChatParticipant User `json:"left_chat_participant"` // optional - NewChatTitle string `json:"new_chat_title"` // optional - NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional - DeleteChatPhoto bool `json:"delete_chat_photo"` // optional - GroupChatCreated bool `json:"group_chat_created"` // optional - SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional - ChannelChatCreated bool `json:"channel_chat_created"` // optional - MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional - MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional + MessageID int `json:"message_id"` + From User `json:"from"` // optional + Date int `json:"date"` + Chat Chat `json:"chat"` + ForwardFrom User `json:"forward_from"` // optional + ForwardDate int `json:"forward_date"` // optional + ReplyToMessage *Message `json:"reply_to_message"` // optional + Text string `json:"text"` // optional + Entities []MessageEntity `json:"entities"` // optional + Audio Audio `json:"audio"` // optional + Document Document `json:"document"` // optional + Photo []PhotoSize `json:"photo"` // optional + Sticker Sticker `json:"sticker"` // optional + Video Video `json:"video"` // optional + Voice Voice `json:"voice"` // optional + Caption string `json:"caption"` // optional + Contact Contact `json:"contact"` // optional + Location Location `json:"location"` // optional + Venue Venue `json:"venue"` // optional + NewChatMember User `json:"new_chat_member"` // optional + LeftChatMember User `json:"left_chat_member"` // optional + NewChatTitle string `json:"new_chat_title"` // optional + NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional + DeleteChatPhoto bool `json:"delete_chat_photo"` // optional + GroupChatCreated bool `json:"group_chat_created"` // optional + SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional + ChannelChatCreated bool `json:"channel_chat_created"` // optional + MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional + MigrateFromChatID int64 `json:"migrate_from_chat_id"` // optional + PinnedMessage *Message `json:"pinned_message"` // optional } // Time converts the message timestamp into a Time.@@ -161,6 +166,19 @@
return strings.SplitN(m.Text, " ", 2)[1] } +// MessageEntity contains information about data in a Message. +type MessageEntity struct { + Type string `json:"type"` + Offset int `json:"offset"` + Length int `json:"length"` + URL string `json:"url"` // optional +} + +// ParseURL attempts to parse a URL contained within a MessageEntity. +func (entity MessageEntity) ParseURL() (*url.URL, error) { + return url.Parse(entity.URL) +} + // PhotoSize contains information about photos. type PhotoSize struct { FileID string `json:"file_id"`@@ -232,6 +250,14 @@ Longitude float32 `json:"longitude"`
Latitude float32 `json:"latitude"` } +// Venue contains information about a venue, including its Location. +type Venue struct { + Location Location `json:"location"` + Title string `json:"title"` + Address string `json:"address"` + FoursquareID string `json:"foursquare_id"` // optional +} + // UserProfilePhotos contains a set of user profile photos. type UserProfilePhotos struct { TotalCount int `json:"total_count"`@@ -254,10 +280,17 @@ }
// ReplyKeyboardMarkup allows the Bot to set a custom keyboard. type ReplyKeyboardMarkup struct { - Keyboard [][]string `json:"keyboard"` - ResizeKeyboard bool `json:"resize_keyboard"` // optional - OneTimeKeyboard bool `json:"one_time_keyboard"` // optional - Selective bool `json:"selective"` // optional + Keyboard [][]KeyboardButton `json:"keyboard"` + ResizeKeyboard bool `json:"resize_keyboard"` // optional + OneTimeKeyboard bool `json:"one_time_keyboard"` // optional + Selective bool `json:"selective"` // optional +} + +// KeyboardButton is a button within a custom keyboard. +type KeyboardButton struct { + Text string `json:"text"` + RequestContact bool `json:"request_contact"` + RequestLocation bool `json:"request_location"` } // ReplyKeyboardHide allows the Bot to hide a custom keyboard.@@ -266,6 +299,33 @@ HideKeyboard bool `json:"hide_keyboard"`
Selective bool `json:"selective"` // optional } +// InlineKeyboardMarkup is a custom keyboard presented for an inline bot. +type InlineKeyboardMarkup struct { + InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"` +} + +// InlineKeyboardButton is a button within a custom keyboard for +// inline query responses. +// +// Note that some values are references as even an empty string +// will change behavior. +type InlineKeyboardButton struct { + Text string `json:"text"` + URL *string `json:"url"` // optional + CallbackData *string `json:"callback_data"` // optional + SwitchInlineQuery *string `json:"switch_inline_query"` // optional +} + +// CallbackQuery is data sent when a keyboard button with callback data +// is clicked. +type CallbackQuery struct { + ID string `json:"id"` + From User `json:"from"` + Message Message `json:"message"` // optional + InlineMessageID string `json:"inline_message_id"` // optional + Data string `json:"data"` // optional +} + // ForceReply allows the Bot to have users directly reply to it without // additional interaction. type ForceReply struct {@@ -275,10 +335,11 @@ }
// InlineQuery is a Query from Telegram for an inline request. type InlineQuery struct { - ID string `json:"id"` - From User `json:"from"` - Query string `json:"query"` - Offset string `json:"offset"` + ID string `json:"id"` + From User `json:"from"` + Location Location `json:"location"` // optional + Query string `json:"query"` + Offset string `json:"offset"` } // InlineQueryResultArticle is an inline query response article.