5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-26 12:21:35 +00:00

Update vendor (telegram)

This commit is contained in:
Wim 2017-01-27 00:23:14 +01:00
parent 09b243d8c2
commit 077d494c7b
5 changed files with 347 additions and 42 deletions

View File

@ -7,7 +7,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/technoweenie/multipartstreamer"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
@ -16,6 +15,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/technoweenie/multipartstreamer"
) )
// BotAPI allows you to interact with the Telegram Bot API. // BotAPI allows you to interact with the Telegram Bot API.
@ -80,7 +81,7 @@ func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse,
json.Unmarshal(bytes, &apiResp) json.Unmarshal(bytes, &apiResp)
if !apiResp.Ok { if !apiResp.Ok {
return APIResponse{}, errors.New(apiResp.Description) return apiResp, errors.New(apiResp.Description)
} }
return apiResp, nil return apiResp, nil
@ -105,16 +106,17 @@ func (bot *BotAPI) makeMessageRequest(endpoint string, params url.Values) (Messa
// //
// Requires the parameter to hold the file not be in the params. // Requires the parameter to hold the file not be in the params.
// File should be a string to a file path, a FileBytes struct, // File should be a string to a file path, a FileBytes struct,
// or a FileReader struct. // a FileReader struct, or a url.URL.
// //
// Note that if your FileReader has a size set to -1, it will read // Note that if your FileReader has a size set to -1, it will read
// the file into memory to calculate a size. // the file into memory to calculate a size.
func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldname string, file interface{}) (APIResponse, error) { func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldname string, file interface{}) (APIResponse, error) {
ms := multipartstreamer.New() ms := multipartstreamer.New()
ms.WriteFields(params)
switch f := file.(type) { switch f := file.(type) {
case string: case string:
ms.WriteFields(params)
fileHandle, err := os.Open(f) fileHandle, err := os.Open(f)
if err != nil { if err != nil {
return APIResponse{}, err return APIResponse{}, err
@ -128,9 +130,13 @@ func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldna
ms.WriteReader(fieldname, fileHandle.Name(), fi.Size(), fileHandle) ms.WriteReader(fieldname, fileHandle.Name(), fi.Size(), fileHandle)
case FileBytes: case FileBytes:
ms.WriteFields(params)
buf := bytes.NewBuffer(f.Bytes) buf := bytes.NewBuffer(f.Bytes)
ms.WriteReader(fieldname, f.Name, int64(len(f.Bytes)), buf) ms.WriteReader(fieldname, f.Name, int64(len(f.Bytes)), buf)
case FileReader: case FileReader:
ms.WriteFields(params)
if f.Size != -1 { if f.Size != -1 {
ms.WriteReader(fieldname, f.Name, f.Size, f.Reader) ms.WriteReader(fieldname, f.Name, f.Size, f.Reader)
@ -145,6 +151,10 @@ func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldna
buf := bytes.NewBuffer(data) buf := bytes.NewBuffer(data)
ms.WriteReader(fieldname, f.Name, int64(len(data)), buf) ms.WriteReader(fieldname, f.Name, int64(len(data)), buf)
case url.URL:
params[fieldname] = f.String()
ms.WriteFields(params)
default: default:
return APIResponse{}, errors.New(ErrBadFileType) return APIResponse{}, errors.New(ErrBadFileType)
} }
@ -399,15 +409,22 @@ func (bot *BotAPI) RemoveWebhook() (APIResponse, error) {
// If you do not have a legitimate TLS certificate, you need to include // If you do not have a legitimate TLS certificate, you need to include
// your self signed certificate with the config. // your self signed certificate with the config.
func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) { func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
if config.Certificate == nil { if config.Certificate == nil {
v := url.Values{} v := url.Values{}
v.Add("url", config.URL.String()) v.Add("url", config.URL.String())
if config.MaxConnections != 0 {
v.Add("max_connections", strconv.Itoa(config.MaxConnections))
}
return bot.MakeRequest("setWebhook", v) return bot.MakeRequest("setWebhook", v)
} }
params := make(map[string]string) params := make(map[string]string)
params["url"] = config.URL.String() params["url"] = config.URL.String()
if config.MaxConnections != 0 {
params["max_connections"] = strconv.Itoa(config.MaxConnections)
}
resp, err := bot.UploadFile("setWebhook", params, "certificate", config.Certificate) resp, err := bot.UploadFile("setWebhook", params, "certificate", config.Certificate)
if err != nil { if err != nil {
@ -424,9 +441,23 @@ func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
return apiResp, nil return apiResp, nil
} }
// GetWebhookInfo allows you to fetch information about a webhook and if
// one currently is set, along with pending update count and error messages.
func (bot *BotAPI) GetWebhookInfo() (WebhookInfo, error) {
resp, err := bot.MakeRequest("getWebhookInfo", url.Values{})
if err != nil {
return WebhookInfo{}, err
}
var info WebhookInfo
err = json.Unmarshal(resp.Result, &info)
return info, err
}
// GetUpdatesChan starts and returns a channel for getting updates. // GetUpdatesChan starts and returns a channel for getting updates.
func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (<-chan Update, error) { func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) {
updatesChan := make(chan Update, 100) ch := make(chan Update, 100)
go func() { go func() {
for { for {
@ -442,18 +473,18 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (<-chan Update, error) {
for _, update := range updates { for _, update := range updates {
if update.UpdateID >= config.Offset { if update.UpdateID >= config.Offset {
config.Offset = update.UpdateID + 1 config.Offset = update.UpdateID + 1
updatesChan <- update ch <- update
} }
} }
} }
}() }()
return updatesChan, nil return ch, nil
} }
// ListenForWebhook registers a http handler for a webhook. // ListenForWebhook registers a http handler for a webhook.
func (bot *BotAPI) ListenForWebhook(pattern string) <-chan Update { func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel {
updatesChan := make(chan Update, 100) ch := make(chan Update, 100)
http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
bytes, _ := ioutil.ReadAll(r.Body) bytes, _ := ioutil.ReadAll(r.Body)
@ -461,10 +492,10 @@ func (bot *BotAPI) ListenForWebhook(pattern string) <-chan Update {
var update Update var update Update
json.Unmarshal(bytes, &update) json.Unmarshal(bytes, &update)
updatesChan <- update ch <- update
}) })
return updatesChan return ch
} }
// AnswerInlineQuery sends a response to an inline query. // AnswerInlineQuery sends a response to an inline query.
@ -495,8 +526,14 @@ func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, erro
v := url.Values{} v := url.Values{}
v.Add("callback_query_id", config.CallbackQueryID) v.Add("callback_query_id", config.CallbackQueryID)
if config.Text != "" {
v.Add("text", config.Text) v.Add("text", config.Text)
}
v.Add("show_alert", strconv.FormatBool(config.ShowAlert)) v.Add("show_alert", strconv.FormatBool(config.ShowAlert))
if config.URL != "" {
v.Add("url", config.URL)
}
v.Add("cache_time", strconv.Itoa(config.CacheTime))
bot.debugLog("answerCallbackQuery", v, nil) bot.debugLog("answerCallbackQuery", v, nil)
@ -648,3 +685,18 @@ func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error)
return bot.MakeRequest("unbanChatMember", v) return bot.MakeRequest("unbanChatMember", v)
} }
// GetGameHighScores allows you to get the high scores for a game.
func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) {
v, _ := config.values()
resp, err := bot.MakeRequest(config.method(), v)
if err != nil {
return []GameHighScore{}, err
}
var highScores []GameHighScore
err = json.Unmarshal(resp.Result, &highScores)
return highScores, err
}

View File

@ -198,7 +198,10 @@ type MessageConfig struct {
// values returns a url.Values representation of MessageConfig. // values returns a url.Values representation of MessageConfig.
func (config MessageConfig) values() (url.Values, error) { func (config MessageConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("text", config.Text) v.Add("text", config.Text)
v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview)) v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview))
if config.ParseMode != "" { if config.ParseMode != "" {
@ -223,7 +226,10 @@ type ForwardConfig struct {
// values returns a url.Values representation of ForwardConfig. // values returns a url.Values representation of ForwardConfig.
func (config ForwardConfig) values() (url.Values, error) { func (config ForwardConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("from_chat_id", strconv.FormatInt(config.FromChatID, 10)) v.Add("from_chat_id", strconv.FormatInt(config.FromChatID, 10))
v.Add("message_id", strconv.Itoa(config.MessageID)) v.Add("message_id", strconv.Itoa(config.MessageID))
return v, nil return v, nil
@ -253,7 +259,10 @@ func (config PhotoConfig) params() (map[string]string, error) {
// Values returns a url.Values representation of PhotoConfig. // Values returns a url.Values representation of PhotoConfig.
func (config PhotoConfig) values() (url.Values, error) { func (config PhotoConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID) v.Add(config.name(), config.FileID)
if config.Caption != "" { if config.Caption != "" {
@ -275,6 +284,7 @@ func (config PhotoConfig) method() string {
// AudioConfig contains information about a SendAudio request. // AudioConfig contains information about a SendAudio request.
type AudioConfig struct { type AudioConfig struct {
BaseFile BaseFile
Caption string
Duration int Duration int
Performer string Performer string
Title string Title string
@ -282,7 +292,10 @@ type AudioConfig struct {
// values returns a url.Values representation of AudioConfig. // values returns a url.Values representation of AudioConfig.
func (config AudioConfig) values() (url.Values, error) { func (config AudioConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID) v.Add(config.name(), config.FileID)
if config.Duration != 0 { if config.Duration != 0 {
@ -295,6 +308,9 @@ func (config AudioConfig) values() (url.Values, error) {
if config.Title != "" { if config.Title != "" {
v.Add("title", config.Title) v.Add("title", config.Title)
} }
if config.Caption != "" {
v.Add("caption", config.Caption)
}
return v, nil return v, nil
} }
@ -313,6 +329,9 @@ func (config AudioConfig) params() (map[string]string, error) {
if config.Title != "" { if config.Title != "" {
params["title"] = config.Title params["title"] = config.Title
} }
if config.Caption != "" {
params["caption"] = config.Caption
}
return params, nil return params, nil
} }
@ -334,7 +353,10 @@ type DocumentConfig struct {
// values returns a url.Values representation of DocumentConfig. // values returns a url.Values representation of DocumentConfig.
func (config DocumentConfig) values() (url.Values, error) { func (config DocumentConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID) v.Add(config.name(), config.FileID)
@ -365,7 +387,10 @@ type StickerConfig struct {
// values returns a url.Values representation of StickerConfig. // values returns a url.Values representation of StickerConfig.
func (config StickerConfig) values() (url.Values, error) { func (config StickerConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID) v.Add(config.name(), config.FileID)
@ -398,7 +423,10 @@ type VideoConfig struct {
// values returns a url.Values representation of VideoConfig. // values returns a url.Values representation of VideoConfig.
func (config VideoConfig) values() (url.Values, error) { func (config VideoConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID) v.Add(config.name(), config.FileID)
if config.Duration != 0 { if config.Duration != 0 {
@ -431,12 +459,16 @@ func (config VideoConfig) method() string {
// VoiceConfig contains information about a SendVoice request. // VoiceConfig contains information about a SendVoice request.
type VoiceConfig struct { type VoiceConfig struct {
BaseFile BaseFile
Caption string
Duration int Duration int
} }
// values returns a url.Values representation of VoiceConfig. // values returns a url.Values representation of VoiceConfig.
func (config VoiceConfig) values() (url.Values, error) { func (config VoiceConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID) v.Add(config.name(), config.FileID)
if config.Duration != 0 { if config.Duration != 0 {
@ -476,7 +508,10 @@ type LocationConfig struct {
// values returns a url.Values representation of LocationConfig. // values returns a url.Values representation of LocationConfig.
func (config LocationConfig) values() (url.Values, error) { func (config LocationConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64)) v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64))
v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64)) v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64))
@ -500,7 +535,10 @@ type VenueConfig struct {
} }
func (config VenueConfig) values() (url.Values, error) { func (config VenueConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64)) v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64))
v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64)) v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64))
@ -526,7 +564,10 @@ type ContactConfig struct {
} }
func (config ContactConfig) values() (url.Values, error) { func (config ContactConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("phone_number", config.PhoneNumber) v.Add("phone_number", config.PhoneNumber)
v.Add("first_name", config.FirstName) v.Add("first_name", config.FirstName)
@ -539,6 +580,94 @@ func (config ContactConfig) method() string {
return "sendContact" return "sendContact"
} }
// GameConfig allows you to send a game.
type GameConfig struct {
BaseChat
GameShortName string
}
func (config GameConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("game_short_name", config.GameShortName)
return v, nil
}
func (config GameConfig) method() string {
return "sendGame"
}
// SetGameScoreConfig allows you to update the game score in a chat.
type SetGameScoreConfig struct {
UserID int
Score int
Force bool
DisableEditMessage bool
ChatID int
ChannelUsername string
MessageID int
InlineMessageID string
}
func (config SetGameScoreConfig) values() (url.Values, error) {
v := url.Values{}
v.Add("user_id", strconv.Itoa(config.UserID))
v.Add("score", strconv.Itoa(config.Score))
if config.InlineMessageID == "" {
if config.ChannelUsername == "" {
v.Add("chat_id", strconv.Itoa(config.ChatID))
} else {
v.Add("chat_id", config.ChannelUsername)
}
v.Add("message_id", strconv.Itoa(config.MessageID))
} else {
v.Add("inline_message_id", config.InlineMessageID)
}
v.Add("disable_edit_message", strconv.FormatBool(config.DisableEditMessage))
return v, nil
}
func (config SetGameScoreConfig) method() string {
return "setGameScore"
}
// GetGameHighScoresConfig allows you to fetch the high scores for a game.
type GetGameHighScoresConfig struct {
UserID int
ChatID int
ChannelUsername string
MessageID int
InlineMessageID string
}
func (config GetGameHighScoresConfig) values() (url.Values, error) {
v := url.Values{}
v.Add("user_id", strconv.Itoa(config.UserID))
if config.InlineMessageID == "" {
if config.ChannelUsername == "" {
v.Add("chat_id", strconv.Itoa(config.ChatID))
} else {
v.Add("chat_id", config.ChannelUsername)
}
v.Add("message_id", strconv.Itoa(config.MessageID))
} else {
v.Add("inline_message_id", config.InlineMessageID)
}
return v, nil
}
func (config GetGameHighScoresConfig) method() string {
return "getGameHighScores"
}
// ChatActionConfig contains information about a SendChatAction request. // ChatActionConfig contains information about a SendChatAction request.
type ChatActionConfig struct { type ChatActionConfig struct {
BaseChat BaseChat
@ -547,7 +676,10 @@ type ChatActionConfig struct {
// values returns a url.Values representation of ChatActionConfig. // values returns a url.Values representation of ChatActionConfig.
func (config ChatActionConfig) values() (url.Values, error) { func (config ChatActionConfig) values() (url.Values, error) {
v, _ := config.BaseChat.values() v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("action", config.Action) v.Add("action", config.Action)
return v, nil return v, nil
} }
@ -566,7 +698,10 @@ type EditMessageTextConfig struct {
} }
func (config EditMessageTextConfig) values() (url.Values, error) { func (config EditMessageTextConfig) values() (url.Values, error) {
v, _ := config.BaseEdit.values() v, err := config.BaseEdit.values()
if err != nil {
return v, err
}
v.Add("text", config.Text) v.Add("text", config.Text)
v.Add("parse_mode", config.ParseMode) v.Add("parse_mode", config.ParseMode)
@ -635,6 +770,7 @@ type UpdateConfig struct {
type WebhookConfig struct { type WebhookConfig struct {
URL *url.URL URL *url.URL
Certificate interface{} Certificate interface{}
MaxConnections int
} }
// FileBytes contains information about a set of bytes to upload // FileBytes contains information about a set of bytes to upload
@ -669,6 +805,8 @@ type CallbackConfig struct {
CallbackQueryID string `json:"callback_query_id"` CallbackQueryID string `json:"callback_query_id"`
Text string `json:"text"` Text string `json:"text"`
ShowAlert bool `json:"show_alert"` ShowAlert bool `json:"show_alert"`
URL string `json:"url"`
CacheTime int `json:"cache_time"`
} }
// ChatMemberConfig contains information about a user in a chat for use // ChatMemberConfig contains information about a user in a chat for use

View File

@ -1,6 +1,7 @@
package tgbotapi package tgbotapi
import ( import (
"log"
"net/url" "net/url"
) )
@ -20,6 +21,7 @@ func NewMessage(chatID int64, text string) MessageConfig {
// NewMessageToChannel creates a new Message that is sent to a channel // NewMessageToChannel creates a new Message that is sent to a channel
// by username. // by username.
//
// username is the username of the channel, text is the message text. // username is the username of the channel, text is the message text.
func NewMessageToChannel(username string, text string) MessageConfig { func NewMessageToChannel(username string, text string) MessageConfig {
return MessageConfig{ return MessageConfig{
@ -316,6 +318,21 @@ func NewWebhookWithCert(link string, file interface{}) WebhookConfig {
} }
} }
// NewWebhookWithCert creates a new webhook with a certificate and max_connections.
//
// link is the url you wish to get webhooks,
// file contains a string to a file, FileReader, or FileBytes.
// maxConnections defines maximum number of connections from telegram to your server
func NewWebhookWithCertAndMaxConnections(link string, file interface{}, maxConnections int) WebhookConfig {
u, _ := url.Parse(link)
return WebhookConfig{
URL: u,
Certificate: file,
MaxConnections: maxConnections,
}
}
// NewInlineQueryResultArticle creates a new inline query article. // NewInlineQueryResultArticle creates a new inline query article.
func NewInlineQueryResultArticle(id, title, messageText string) InlineQueryResultArticle { func NewInlineQueryResultArticle(id, title, messageText string) InlineQueryResultArticle {
return InlineQueryResultArticle{ return InlineQueryResultArticle{
@ -479,12 +496,23 @@ func NewEditMessageReplyMarkup(chatID int64, messageID int, replyMarkup InlineKe
// NewHideKeyboard hides the keyboard, with the option for being selective // NewHideKeyboard hides the keyboard, with the option for being selective
// or hiding for everyone. // or hiding for everyone.
func NewHideKeyboard(selective bool) ReplyKeyboardHide { func NewHideKeyboard(selective bool) ReplyKeyboardHide {
log.Println("NewHideKeyboard is deprecated, please use NewRemoveKeyboard")
return ReplyKeyboardHide{ return ReplyKeyboardHide{
HideKeyboard: true, HideKeyboard: true,
Selective: selective, Selective: selective,
} }
} }
// NewRemoveKeyboard hides the keyboard, with the option for being selective
// or hiding for everyone.
func NewRemoveKeyboard(selective bool) ReplyKeyboardRemove {
return ReplyKeyboardRemove{
RemoveKeyboard: true,
Selective: selective,
}
}
// NewKeyboardButton creates a regular keyboard button. // NewKeyboardButton creates a regular keyboard button.
func NewKeyboardButton(text string) KeyboardButton { func NewKeyboardButton(text string) KeyboardButton {
return KeyboardButton{ return KeyboardButton{

View File

@ -16,6 +16,13 @@ type APIResponse struct {
Result json.RawMessage `json:"result"` Result json.RawMessage `json:"result"`
ErrorCode int `json:"error_code"` ErrorCode int `json:"error_code"`
Description string `json:"description"` Description string `json:"description"`
Parameters *ResponseParameters `json:"parameters"`
}
// ResponseParameters are various errors that can be returned in APIResponse.
type ResponseParameters struct {
MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
RetryAfter int `json:"retry_after"` // optional
} }
// Update is an update response, from GetUpdates. // Update is an update response, from GetUpdates.
@ -23,11 +30,23 @@ type Update struct {
UpdateID int `json:"update_id"` UpdateID int `json:"update_id"`
Message *Message `json:"message"` Message *Message `json:"message"`
EditedMessage *Message `json:"edited_message"` EditedMessage *Message `json:"edited_message"`
ChannelPost *Message `json:"channel_post"`
EditedChannelPost *Message `json:"edited_channel_post"`
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"` CallbackQuery *CallbackQuery `json:"callback_query"`
} }
// UpdatesChannel is the channel for getting updates.
type UpdatesChannel <-chan Update
// Clear discards all unprocessed incoming updates.
func (ch UpdatesChannel) Clear() {
for len(ch) != 0 {
<-ch
}
}
// User is a user on Telegram. // User is a user on Telegram.
type User struct { type User struct {
ID int `json:"id"` ID int `json:"id"`
@ -67,6 +86,7 @@ type Chat struct {
UserName string `json:"username"` // optional UserName string `json:"username"` // optional
FirstName string `json:"first_name"` // optional FirstName string `json:"first_name"` // optional
LastName string `json:"last_name"` // optional LastName string `json:"last_name"` // optional
AllMembersAreAdmins bool `json:"all_members_are_administrators"` // optional
} }
// IsPrivate returns if the Chat is a private conversation. // IsPrivate returns if the Chat is a private conversation.
@ -103,6 +123,7 @@ type Message struct {
Chat *Chat `json:"chat"` Chat *Chat `json:"chat"`
ForwardFrom *User `json:"forward_from"` // optional ForwardFrom *User `json:"forward_from"` // optional
ForwardFromChat *Chat `json:"forward_from_chat"` // optional ForwardFromChat *Chat `json:"forward_from_chat"` // optional
ForwardFromMessageID int `json:"forward_from_message_id"` // 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
EditDate int `json:"edit_date"` // optional EditDate int `json:"edit_date"` // optional
@ -110,6 +131,7 @@ type Message struct {
Entities *[]MessageEntity `json:"entities"` // 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
Game *Game `json:"game"` // optional
Photo *[]PhotoSize `json:"photo"` // optional Photo *[]PhotoSize `json:"photo"` // optional
Sticker *Sticker `json:"sticker"` // optional Sticker *Sticker `json:"sticker"` // optional
Video *Video `json:"video"` // optional Video *Video `json:"video"` // optional
@ -314,6 +336,12 @@ type ReplyKeyboardHide struct {
Selective bool `json:"selective"` // optional Selective bool `json:"selective"` // optional
} }
// ReplyKeyboardRemove allows the Bot to hide a custom keyboard.
type ReplyKeyboardRemove struct {
RemoveKeyboard bool `json:"remove_keyboard"`
Selective bool `json:"selective"`
}
// InlineKeyboardMarkup is a custom keyboard presented for an inline bot. // InlineKeyboardMarkup is a custom keyboard presented for an inline bot.
type InlineKeyboardMarkup struct { type InlineKeyboardMarkup struct {
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"` InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
@ -324,11 +352,15 @@ type InlineKeyboardMarkup struct {
// //
// Note that some values are references as even an empty string // Note that some values are references as even an empty string
// will change behavior. // will change behavior.
//
// CallbackGame, if set, MUST be first button in first row.
type InlineKeyboardButton struct { type InlineKeyboardButton struct {
Text string `json:"text"` Text string `json:"text"`
URL *string `json:"url,omitempty"` // optional URL *string `json:"url,omitempty"` // optional
CallbackData *string `json:"callback_data,omitempty"` // optional CallbackData *string `json:"callback_data,omitempty"` // optional
SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional
SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // optional
CallbackGame *CallbackGame `json:"callback_game,omitempty"` // optional
} }
// CallbackQuery is data sent when a keyboard button with callback data // CallbackQuery is data sent when a keyboard button with callback data
@ -338,7 +370,9 @@ type CallbackQuery struct {
From *User `json:"from"` From *User `json:"from"`
Message *Message `json:"message"` // optional Message *Message `json:"message"` // optional
InlineMessageID string `json:"inline_message_id"` // optional InlineMessageID string `json:"inline_message_id"` // optional
ChatInstance string `json:"chat_instance"`
Data string `json:"data"` // optional Data string `json:"data"` // optional
GameShortName string `json:"game_short_name"` // 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
@ -369,6 +403,49 @@ func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
// WasKicked returns if the ChatMember was kicked from the chat. // WasKicked returns if the ChatMember was kicked from the chat.
func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" } func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
// Game is a game within Telegram.
type Game struct {
Title string `json:"title"`
Description string `json:"description"`
Photo []PhotoSize `json:"photo"`
Text string `json:"text"`
TextEntities []MessageEntity `json:"text_entities"`
Animation Animation `json:"animation"`
}
// Animation is a GIF animation demonstrating the game.
type Animation struct {
FileID string `json:"file_id"`
Thumb PhotoSize `json:"thumb"`
FileName string `json:"file_name"`
MimeType string `json:"mime_type"`
FileSize int `json:"file_size"`
}
// GameHighScore is a user's score and position on the leaderboard.
type GameHighScore struct {
Position int `json:"position"`
User User `json:"user"`
Score int `json:"score"`
}
// CallbackGame is for starting a game in an inline keyboard button.
type CallbackGame struct{}
// WebhookInfo is information about a currently set webhook.
type WebhookInfo struct {
URL string `json:"url"`
HasCustomCertificate bool `json:"has_custom_certificate"`
PendingUpdateCount int `json:"pending_update_count"`
LastErrorDate int `json:"last_error_date"` // optional
LastErrorMessage string `json:"last_error_message"` // optional
}
// IsSet returns true if a webhook is currently set.
func (info WebhookInfo) IsSet() bool {
return info.URL != ""
}
// 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"`
@ -460,6 +537,7 @@ type InlineQueryResultAudio struct {
ID string `json:"id"` // required ID string `json:"id"` // required
URL string `json:"audio_url"` // required URL string `json:"audio_url"` // required
Title string `json:"title"` // required Title string `json:"title"` // required
Caption string `json:"caption"`
Performer string `json:"performer"` Performer string `json:"performer"`
Duration int `json:"audio_duration"` Duration int `json:"audio_duration"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
@ -472,6 +550,7 @@ type InlineQueryResultVoice struct {
ID string `json:"id"` // required ID string `json:"id"` // required
URL string `json:"voice_url"` // required URL string `json:"voice_url"` // required
Title string `json:"title"` // required Title string `json:"title"` // required
Caption string `json:"caption"`
Duration int `json:"voice_duration"` Duration int `json:"voice_duration"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
InputMessageContent interface{} `json:"input_message_content,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"`
@ -507,6 +586,14 @@ type InlineQueryResultLocation struct {
ThumbHeight int `json:"thumb_height"` ThumbHeight int `json:"thumb_height"`
} }
// InlineQueryResultGame is an inline query response game.
type InlineQueryResultGame struct {
Type string `json:"type"`
ID string `json:"id"`
GameShortName string `json:"game_short_name"`
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`
}
// ChosenInlineResult is an inline query result chosen by a User // ChosenInlineResult is an inline query result chosen by a User
type ChosenInlineResult struct { type ChosenInlineResult struct {
ResultID string `json:"result_id"` ResultID string `json:"result_id"`

2
vendor/manifest vendored
View File

@ -63,7 +63,7 @@
"importpath": "github.com/go-telegram-bot-api/telegram-bot-api", "importpath": "github.com/go-telegram-bot-api/telegram-bot-api",
"repository": "https://github.com/go-telegram-bot-api/telegram-bot-api", "repository": "https://github.com/go-telegram-bot-api/telegram-bot-api",
"vcs": "git", "vcs": "git",
"revision": "a7f48eb2dd301356942677e65bebe0c9aef07013", "revision": "3293f3ad8411de32d99e443cd82aec7c3bb01a5a",
"branch": "master", "branch": "master",
"notests": true "notests": true
}, },