all repos — telegram-bot-api @ 0a57807db79efce7f6719fbb2c0e0f83fda79aec

Golang bindings for the Telegram Bot API

Additional changes for Telegram API updates.
Syfaro syfaro@foxpaw.in
Thu, 24 Nov 2016 23:50:35 -0600
commit

0a57807db79efce7f6719fbb2c0e0f83fda79aec

parent

f3a33ae6f1dd63dfb26816c8921617fc86478023

5 files changed, 82 insertions(+), 13 deletions(-)

jump to
M bot.gobot.go

@@ -525,6 +525,7 @@ 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)
M bot_test.gobot_test.go

@@ -7,6 +7,7 @@ "log"

"net/http" "os" "testing" + "time" ) const (

@@ -25,6 +26,7 @@ func getBot(t *testing.T) (*tgbotapi.BotAPI, error) {

bot, err := tgbotapi.NewBotAPI(TestToken) if err != nil { + t.Error(err) t.Fail() }

@@ -35,6 +37,7 @@ func TestNewBotAPI_notoken(t *testing.T) {

_, err := tgbotapi.NewBotAPI("") if err == nil { + t.Error(err) t.Fail() } }

@@ -47,6 +50,7 @@

_, err := bot.GetUpdates(u) if err != nil { + t.Error(err) t.Fail() } }

@@ -59,6 +63,7 @@ msg.ParseMode = "markdown"

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -71,6 +76,7 @@ msg.ReplyToMessageID = ReplyToMessageID

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -82,6 +88,7 @@ msg := tgbotapi.NewForward(ChatID, ChatID, ReplyToMessageID)

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -94,6 +101,7 @@ msg.Caption = "Test"

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -109,6 +117,7 @@ msg.Caption = "Test"

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -124,6 +133,7 @@ msg.Caption = "Test"

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -137,6 +147,7 @@

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -149,6 +160,7 @@ msg.Caption = "Test"

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -160,6 +172,7 @@ msg := tgbotapi.NewDocumentUpload(ChatID, "tests/image.jpg")

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -171,6 +184,7 @@ msg := tgbotapi.NewDocumentShare(ChatID, ExistingDocumentFileID)

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -187,6 +201,7 @@ msg.FileSize = 688

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -202,6 +217,7 @@

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -214,6 +230,7 @@ msg.Duration = 10

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -226,6 +243,7 @@ msg.Duration = 10

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -236,6 +254,7 @@

contact := tgbotapi.NewContact(ChatID, "5551234567", "Test") if _, err := bot.Send(contact); err != nil { + t.Error(err) t.Fail() } }

@@ -246,6 +265,7 @@

_, err := bot.Send(tgbotapi.NewLocation(ChatID, 40, 40)) if err != nil { + t.Error(err) t.Fail() } }

@@ -256,6 +276,7 @@

venue := tgbotapi.NewVenue(ChatID, "A Test Location", "123 Test Street", 40, 40) if _, err := bot.Send(venue); err != nil { + t.Error(err) t.Fail() } }

@@ -270,6 +291,7 @@

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -284,6 +306,7 @@

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -296,6 +319,7 @@

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -308,6 +332,7 @@

_, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -316,10 +341,11 @@ func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {

bot, _ := getBot(t) msg := tgbotapi.NewStickerUpload(ChatID, "tests/image.jpg") - msg.ReplyMarkup = tgbotapi.ReplyKeyboardHide{true, false} + msg.ReplyMarkup = tgbotapi.ReplyKeyboardRemove{true, false} _, err := bot.Send(msg) if err != nil { + t.Error(err) t.Fail() } }

@@ -328,12 +354,12 @@ func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) {

bot, _ := getBot(t) msg := tgbotapi.NewStickerShare(ChatID, ExistingStickerFileID) - msg.ReplyMarkup = tgbotapi.ReplyKeyboardHide{true, false} + msg.ReplyMarkup = tgbotapi.ReplyKeyboardRemove{true, false} _, err := bot.Send(msg) if err != nil { - + t.Error(err) t.Fail() } }

@@ -346,6 +372,7 @@

_, err := bot.GetFile(file) if err != nil { + t.Error(err) t.Fail() } }

@@ -356,6 +383,7 @@

_, err := bot.Send(tgbotapi.NewChatAction(ChatID, tgbotapi.ChatTyping)) if err != nil { + t.Error(err) t.Fail() } }

@@ -365,6 +393,7 @@ bot, _ := getBot(t)

msg, err := bot.Send(tgbotapi.NewMessage(ChatID, "Testing editing.")) if err != nil { + t.Error(err) t.Fail() }

@@ -378,6 +407,7 @@ }

_, err = bot.Send(edit) if err != nil { + t.Error(err) t.Fail() } }

@@ -387,18 +417,22 @@ bot, _ := getBot(t)

_, err := bot.GetUserProfilePhotos(tgbotapi.NewUserProfilePhotos(ChatID)) if err != nil { + t.Error(err) t.Fail() } } func TestSetWebhookWithCert(t *testing.T) { bot, _ := getBot(t) + + time.Sleep(time.Second * 2) bot.RemoveWebhook() wh := tgbotapi.NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, "tests/cert.pem") _, err := bot.SetWebhook(wh) if err != nil { + t.Error(err) t.Fail() }

@@ -407,12 +441,15 @@ }

func TestSetWebhookWithoutCert(t *testing.T) { bot, _ := getBot(t) + + time.Sleep(time.Second * 2) bot.RemoveWebhook() wh := tgbotapi.NewWebhook("https://example.com/tgbotapi-test/" + bot.Token) _, err := bot.SetWebhook(wh) if err != nil { + t.Error(err) t.Fail() }

@@ -427,6 +464,7 @@ ucfg.Timeout = 60

_, err := bot.GetUpdatesChan(ucfg) if err != nil { + t.Error(err) t.Fail() } }
M configs.goconfigs.go

@@ -296,6 +296,9 @@ }

if config.Title != "" { v.Add("title", config.Title) } + if config.Caption != "" { + v.Add("caption", config.Caption) + } return v, nil }

@@ -313,6 +316,9 @@ params["performer"] = config.Performer

} if config.Title != "" { params["title"] = config.Title + } + if config.Caption != "" { + params["caption"] = config.Caption } return params, nil

@@ -561,13 +567,14 @@ }

// SetGameScoreConfig allows you to update the game score in a chat. type SetGameScoreConfig struct { - UserID int - Score int - ChatID int - ChannelUsername string - MessageID int - InlineMessageID string - EditMessage bool + UserID int + Score int + Force bool + DisableEditMessage bool + ChatID int + ChannelUsername string + MessageID int + InlineMessageID string } func (config SetGameScoreConfig) values() (url.Values, error) {

@@ -585,7 +592,7 @@ v.Add("message_id", strconv.Itoa(config.MessageID))

} else { v.Add("inline_message_id", config.InlineMessageID) } - v.Add("edit_message", strconv.FormatBool(config.EditMessage)) + v.Add("disable_edit_message", strconv.FormatBool(config.DisableEditMessage)) return v, nil }

@@ -756,6 +763,7 @@ CallbackQueryID string `json:"callback_query_id"`

Text string `json:"text"` 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
M helpers.gohelpers.go

@@ -1,6 +1,7 @@

package tgbotapi import ( + "log" "net/url" )

@@ -20,6 +21,7 @@ }

// NewMessageToChannel creates a new Message that is sent to a channel // by username. +// // username is the username of the channel, text is the message text. func NewMessageToChannel(username string, text string) MessageConfig { return MessageConfig{

@@ -479,9 +481,20 @@

// NewHideKeyboard hides the keyboard, with the option for being selective // or hiding for everyone. func NewHideKeyboard(selective bool) ReplyKeyboardHide { + log.Println("NewHideKeyboard is deprecated, please use NewRemoveKeyboard") + return ReplyKeyboardHide{ HideKeyboard: true, 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, } }
M types.gotypes.go

@@ -21,8 +21,8 @@ }

// ResponseParameters are various errors that can be returned in APIResponse. type ResponseParameters struct { - MigrateToChatID int `json:"migrate_to_chat_id"` // optional - RetryAfter int `json:"retry_after"` // optional + MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional + RetryAfter int `json:"retry_after"` // optional } // Update is an update response, from GetUpdates.

@@ -30,6 +30,8 @@ type Update struct {

UpdateID int `json:"update_id"` Message *Message `json:"message"` EditedMessage *Message `json:"edited_message"` + ChannelPost *Message `json:"channel_post"` + EditedChannelPost *Message `json:"edited_channel_post"` InlineQuery *InlineQuery `json:"inline_query"` ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"` CallbackQuery *CallbackQuery `json:"callback_query"`

@@ -111,6 +113,7 @@ Date int `json:"date"`

Chat *Chat `json:"chat"` ForwardFrom *User `json:"forward_from"` // optional ForwardFromChat *Chat `json:"forward_from_chat"` // optional + ForwardFromMessageID int `json:"forward_from_message_id"` // optional ForwardDate int `json:"forward_date"` // optional ReplyToMessage *Message `json:"reply_to_message"` // optional EditDate int `json:"edit_date"` // optional

@@ -321,6 +324,12 @@ // ReplyKeyboardHide allows the Bot to hide a custom keyboard.

type ReplyKeyboardHide struct { HideKeyboard bool `json:"hide_keyboard"` 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.