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)
|
||||||
|
}
|
||||||
|
|
47
configs.go
47
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
|
||||||
|
@ -516,9 +544,18 @@ type FileReader struct {
|
||||||
|
|
||||||
// InlineConfig contains information on making an InlineQuery response.
|
// InlineConfig contains information on making an InlineQuery response.
|
||||||
type InlineConfig struct {
|
type InlineConfig struct {
|
||||||
InlineQueryID string `json:"inline_query_id"`
|
InlineQueryID string `json:"inline_query_id"`
|
||||||
Results []interface{} `json:"results"`
|
Results []interface{} `json:"results"`
|
||||||
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"`
|
||||||
}
|
}
|
||||||
|
|
131
types.go
131
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.
|
||||||
|
@ -88,33 +90,36 @@ func (c *Chat) IsChannel() bool {
|
||||||
// Message is returned by almost every request, and contains data about
|
// Message is returned by almost every request, and contains data about
|
||||||
// almost anything.
|
// almost anything.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
MessageID int `json:"message_id"`
|
MessageID int `json:"message_id"`
|
||||||
From User `json:"from"` // optional
|
From User `json:"from"` // optional
|
||||||
Date int `json:"date"`
|
Date int `json:"date"`
|
||||||
Chat Chat `json:"chat"`
|
Chat Chat `json:"chat"`
|
||||||
ForwardFrom User `json:"forward_from"` // optional
|
ForwardFrom User `json:"forward_from"` // optional
|
||||||
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
|
||||||
Audio Audio `json:"audio"` // optional
|
Entities []MessageEntity `json:"entities"` // optional
|
||||||
Document Document `json:"document"` // optional
|
Audio Audio `json:"audio"` // optional
|
||||||
Photo []PhotoSize `json:"photo"` // optional
|
Document Document `json:"document"` // optional
|
||||||
Sticker Sticker `json:"sticker"` // optional
|
Photo []PhotoSize `json:"photo"` // optional
|
||||||
Video Video `json:"video"` // optional
|
Sticker Sticker `json:"sticker"` // optional
|
||||||
Voice Voice `json:"voice"` // optional
|
Video Video `json:"video"` // optional
|
||||||
Caption string `json:"caption"` // optional
|
Voice Voice `json:"voice"` // optional
|
||||||
Contact Contact `json:"contact"` // optional
|
Caption string `json:"caption"` // optional
|
||||||
Location Location `json:"location"` // optional
|
Contact Contact `json:"contact"` // optional
|
||||||
NewChatParticipant User `json:"new_chat_participant"` // optional
|
Location Location `json:"location"` // optional
|
||||||
LeftChatParticipant User `json:"left_chat_participant"` // optional
|
Venue Venue `json:"venue"` // optional
|
||||||
NewChatTitle string `json:"new_chat_title"` // optional
|
NewChatMember User `json:"new_chat_member"` // optional
|
||||||
NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional
|
LeftChatMember User `json:"left_chat_member"` // optional
|
||||||
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
|
NewChatTitle string `json:"new_chat_title"` // optional
|
||||||
GroupChatCreated bool `json:"group_chat_created"` // optional
|
NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional
|
||||||
SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
|
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
|
||||||
ChannelChatCreated bool `json:"channel_chat_created"` // optional
|
GroupChatCreated bool `json:"group_chat_created"` // optional
|
||||||
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
|
SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
|
||||||
MigrateFromChatID int64 `json:"migrate_from_chat_id"` // 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.
|
// 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,10 +280,17 @@ 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.
|
||||||
|
@ -266,6 +299,33 @@ type ReplyKeyboardHide struct {
|
||||||
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 {
|
||||||
|
@ -275,10 +335,11 @@ type ForceReply struct {
|
||||||
|
|
||||||
// InlineQuery is a Query from Telegram for an inline request.
|
// InlineQuery is a Query from Telegram for an inline request.
|
||||||
type InlineQuery struct {
|
type InlineQuery struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
From User `json:"from"`
|
From User `json:"from"`
|
||||||
Query string `json:"query"`
|
Location Location `json:"location"` // optional
|
||||||
Offset string `json:"offset"`
|
Query string `json:"query"`
|
||||||
|
Offset string `json:"offset"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InlineQueryResultArticle is an inline query response article.
|
// InlineQueryResultArticle is an inline query response article.
|
||||||
|
|
Loading…
Reference in New Issue