Skip to content

Commit

Permalink
Additional changes for Telegram API updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Syfaro committed Nov 25, 2016
1 parent f3a33ae commit 0a57807
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 13 deletions.
1 change: 1 addition & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, erro
if config.URL != "" {
v.Add("url", config.URL)
}
v.Add("cache_time", strconv.Itoa(config.CacheTime))

bot.debugLog("answerCallbackQuery", v, nil)

Expand Down
44 changes: 41 additions & 3 deletions bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"testing"
"time"
)

const (
Expand All @@ -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()
}

Expand All @@ -35,6 +37,7 @@ func TestNewBotAPI_notoken(t *testing.T) {
_, err := tgbotapi.NewBotAPI("")

if err == nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -47,6 +50,7 @@ func TestGetUpdates(t *testing.T) {
_, err := bot.GetUpdates(u)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -59,6 +63,7 @@ func TestSendWithMessage(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -71,6 +76,7 @@ func TestSendWithMessageReply(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -82,6 +88,7 @@ func TestSendWithMessageForward(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -94,6 +101,7 @@ func TestSendWithNewPhoto(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -109,6 +117,7 @@ func TestSendWithNewPhotoWithFileBytes(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -124,6 +133,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -137,6 +147,7 @@ func TestSendWithNewPhotoReply(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -149,6 +160,7 @@ func TestSendWithExistingPhoto(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -160,6 +172,7 @@ func TestSendWithNewDocument(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -171,6 +184,7 @@ func TestSendWithExistingDocument(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -187,6 +201,7 @@ func TestSendWithNewAudio(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -202,6 +217,7 @@ func TestSendWithExistingAudio(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -214,6 +230,7 @@ func TestSendWithNewVoice(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -226,6 +243,7 @@ func TestSendWithExistingVoice(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -236,6 +254,7 @@ func TestSendWithContact(t *testing.T) {
contact := tgbotapi.NewContact(ChatID, "5551234567", "Test")

if _, err := bot.Send(contact); err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -246,6 +265,7 @@ func TestSendWithLocation(t *testing.T) {
_, err := bot.Send(tgbotapi.NewLocation(ChatID, 40, 40))

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -256,6 +276,7 @@ func TestSendWithVenue(t *testing.T) {
venue := tgbotapi.NewVenue(ChatID, "A Test Location", "123 Test Street", 40, 40)

if _, err := bot.Send(venue); err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -270,6 +291,7 @@ func TestSendWithNewVideo(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -284,6 +306,7 @@ func TestSendWithExistingVideo(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -296,6 +319,7 @@ func TestSendWithNewSticker(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -308,6 +332,7 @@ func TestSendWithExistingSticker(t *testing.T) {
_, err := bot.Send(msg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -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()
}
}
Expand All @@ -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()
}
}
Expand All @@ -346,6 +372,7 @@ func TestGetFile(t *testing.T) {
_, err := bot.GetFile(file)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -356,6 +383,7 @@ func TestSendChatConfig(t *testing.T) {
_, err := bot.Send(tgbotapi.NewChatAction(ChatID, tgbotapi.ChatTyping))

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -365,6 +393,7 @@ func TestSendEditMessage(t *testing.T) {

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

Expand All @@ -378,6 +407,7 @@ func TestSendEditMessage(t *testing.T) {

_, err = bot.Send(edit)
if err != nil {
t.Error(err)
t.Fail()
}
}
Expand All @@ -387,18 +417,22 @@ func TestGetUserProfilePhotos(t *testing.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()
}

Expand All @@ -408,11 +442,14 @@ func TestSetWebhookWithCert(t *testing.T) {
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()
}

Expand All @@ -427,6 +464,7 @@ func TestUpdatesChan(t *testing.T) {
_, err := bot.GetUpdatesChan(ucfg)

if err != nil {
t.Error(err)
t.Fail()
}
}
Expand Down
24 changes: 16 additions & 8 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ func (config AudioConfig) values() (url.Values, error) {
if config.Title != "" {
v.Add("title", config.Title)
}
if config.Caption != "" {
v.Add("caption", config.Caption)
}

return v, nil
}
Expand All @@ -314,6 +317,9 @@ func (config AudioConfig) params() (map[string]string, error) {
if config.Title != "" {
params["title"] = config.Title
}
if config.Caption != "" {
params["caption"] = config.Caption
}

return params, nil
}
Expand Down Expand Up @@ -561,13 +567,14 @@ func (config GameConfig) method() string {

// 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) {
Expand All @@ -585,7 +592,7 @@ func (config SetGameScoreConfig) values() (url.Values, error) {
} 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
}
Expand Down Expand Up @@ -756,6 +763,7 @@ type CallbackConfig struct {
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
Expand Down
Loading

0 comments on commit 0a57807

Please sign in to comment.