Add some of the new methods and types.
parent
5c46b08c56
commit
18510df3c9
15
bot.go
15
bot.go
|
@ -482,8 +482,23 @@ func (bot *BotAPI) AnswerInlineQuery(config InlineConfig) (APIResponse, error) {
|
||||||
return APIResponse{}, err
|
return APIResponse{}, err
|
||||||
}
|
}
|
||||||
v.Add("results", string(data))
|
v.Add("results", string(data))
|
||||||
|
v.Add("switch_pm_text", config.SwitchPMText)
|
||||||
|
v.Add("switch_pm_parameter", config.SwitchPMParameter)
|
||||||
|
|
||||||
bot.debugLog("answerInlineQuery", v, nil)
|
bot.debugLog("answerInlineQuery", v, nil)
|
||||||
|
|
||||||
return bot.MakeRequest("answerInlineQuery", v)
|
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)
|
||||||
|
}
|
||||||
|
|
37
configs.go
37
configs.go
|
@ -454,6 +454,34 @@ func (config LocationConfig) method() string {
|
||||||
return "sendLocation"
|
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.
|
// ChatActionConfig contains information about a SendChatAction request.
|
||||||
type ChatActionConfig struct {
|
type ChatActionConfig struct {
|
||||||
BaseChat
|
BaseChat
|
||||||
|
@ -521,4 +549,13 @@ type InlineConfig struct {
|
||||||
CacheTime int `json:"cache_time"`
|
CacheTime int `json:"cache_time"`
|
||||||
IsPersonal bool `json:"is_personal"`
|
IsPersonal bool `json:"is_personal"`
|
||||||
NextOffset string `json:"next_offset"`
|
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"`
|
||||||
}
|
}
|
||||||
|
|
67
types.go
67
types.go
|
@ -3,6 +3,7 @@ package tgbotapi
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -22,6 +23,7 @@ type Update struct {
|
||||||
Message Message `json:"message"`
|
Message Message `json:"message"`
|
||||||
InlineQuery InlineQuery `json:"inline_query"`
|
InlineQuery InlineQuery `json:"inline_query"`
|
||||||
ChosenInlineResult ChosenInlineResult `json:"chosen_inline_result"`
|
ChosenInlineResult ChosenInlineResult `json:"chosen_inline_result"`
|
||||||
|
CallbackQuery CallbackQuery `json:"callback_query"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// User is a user on Telegram.
|
// User is a user on Telegram.
|
||||||
|
@ -96,6 +98,7 @@ type Message struct {
|
||||||
ForwardDate int `json:"forward_date"` // optional
|
ForwardDate int `json:"forward_date"` // optional
|
||||||
ReplyToMessage *Message `json:"reply_to_message"` // optional
|
ReplyToMessage *Message `json:"reply_to_message"` // optional
|
||||||
Text string `json:"text"` // optional
|
Text string `json:"text"` // optional
|
||||||
|
Entities []MessageEntity `json:"entities"` // optional
|
||||||
Audio Audio `json:"audio"` // optional
|
Audio Audio `json:"audio"` // optional
|
||||||
Document Document `json:"document"` // optional
|
Document Document `json:"document"` // optional
|
||||||
Photo []PhotoSize `json:"photo"` // optional
|
Photo []PhotoSize `json:"photo"` // optional
|
||||||
|
@ -105,8 +108,9 @@ type Message struct {
|
||||||
Caption string `json:"caption"` // optional
|
Caption string `json:"caption"` // optional
|
||||||
Contact Contact `json:"contact"` // optional
|
Contact Contact `json:"contact"` // optional
|
||||||
Location Location `json:"location"` // optional
|
Location Location `json:"location"` // optional
|
||||||
NewChatParticipant User `json:"new_chat_participant"` // optional
|
Venue Venue `json:"venue"` // optional
|
||||||
LeftChatParticipant User `json:"left_chat_participant"` // optional
|
NewChatMember User `json:"new_chat_member"` // optional
|
||||||
|
LeftChatMember User `json:"left_chat_member"` // optional
|
||||||
NewChatTitle string `json:"new_chat_title"` // optional
|
NewChatTitle string `json:"new_chat_title"` // optional
|
||||||
NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional
|
NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional
|
||||||
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
|
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
|
||||||
|
@ -115,6 +119,7 @@ type Message struct {
|
||||||
ChannelChatCreated bool `json:"channel_chat_created"` // optional
|
ChannelChatCreated bool `json:"channel_chat_created"` // optional
|
||||||
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
|
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
|
||||||
MigrateFromChatID int64 `json:"migrate_from_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.
|
// Time converts the message timestamp into a Time.
|
||||||
|
@ -161,6 +166,19 @@ func (m *Message) CommandArguments() string {
|
||||||
return strings.SplitN(m.Text, " ", 2)[1]
|
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.
|
// PhotoSize contains information about photos.
|
||||||
type PhotoSize struct {
|
type PhotoSize struct {
|
||||||
FileID string `json:"file_id"`
|
FileID string `json:"file_id"`
|
||||||
|
@ -232,6 +250,14 @@ type Location struct {
|
||||||
Latitude float32 `json:"latitude"`
|
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.
|
// UserProfilePhotos contains a set of user profile photos.
|
||||||
type UserProfilePhotos struct {
|
type UserProfilePhotos struct {
|
||||||
TotalCount int `json:"total_count"`
|
TotalCount int `json:"total_count"`
|
||||||
|
@ -254,18 +280,52 @@ func (f *File) Link(token string) string {
|
||||||
|
|
||||||
// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
|
// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
|
||||||
type ReplyKeyboardMarkup struct {
|
type ReplyKeyboardMarkup struct {
|
||||||
Keyboard [][]string `json:"keyboard"`
|
Keyboard [][]KeyboardButton `json:"keyboard"`
|
||||||
ResizeKeyboard bool `json:"resize_keyboard"` // optional
|
ResizeKeyboard bool `json:"resize_keyboard"` // optional
|
||||||
OneTimeKeyboard bool `json:"one_time_keyboard"` // optional
|
OneTimeKeyboard bool `json:"one_time_keyboard"` // optional
|
||||||
Selective bool `json:"selective"` // 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.
|
// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
|
||||||
type ReplyKeyboardHide struct {
|
type ReplyKeyboardHide struct {
|
||||||
HideKeyboard bool `json:"hide_keyboard"`
|
HideKeyboard bool `json:"hide_keyboard"`
|
||||||
Selective bool `json:"selective"` // optional
|
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
|
// ForceReply allows the Bot to have users directly reply to it without
|
||||||
// additional interaction.
|
// additional interaction.
|
||||||
type ForceReply struct {
|
type ForceReply struct {
|
||||||
|
@ -277,6 +337,7 @@ type ForceReply struct {
|
||||||
type InlineQuery struct {
|
type InlineQuery struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
From User `json:"from"`
|
From User `json:"from"`
|
||||||
|
Location Location `json:"location"` // optional
|
||||||
Query string `json:"query"`
|
Query string `json:"query"`
|
||||||
Offset string `json:"offset"`
|
Offset string `json:"offset"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue