all repos — telegram-bot-api @ a192540b8c20d382fe2c29616650ef449dd5a6d6

Golang bindings for the Telegram Bot API

Many tests added. Small fixes
Gleb Sinyavsky zhulik.gleb@gmail.com
Fri, 20 Nov 2015 20:26:12 +0300
commit

a192540b8c20d382fe2c29616650ef449dd5a6d6

parent

e16094f76a5f0642fe110299d3f557911dd7af7c

4 files changed, 134 insertions(+), 1 deletions(-)

jump to
M bot_test.gobot_test.go

@@ -57,6 +57,38 @@ t.Fail()

} msg := tgbotapi.NewMessage(76918703, "A test message from the test library in telegram-bot-api") + msg.ParseMode = "markdown" + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + +func TestSendWithMessageReply(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + msg := tgbotapi.NewMessage(76918703, "A test message from the test library in telegram-bot-api") + msg.ReplyToMessageID = 480 + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + +func TestSendWithMessageForward(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + msg := tgbotapi.NewForward(76918703, 76918703, 480) _, err = bot.Send(msg) if err != nil {

@@ -72,6 +104,7 @@ t.Fail()

} msg := tgbotapi.NewPhotoUpload(76918703, "tests/image.jpg") + msg.Caption = "Test" _, err = bot.Send(msg) if err != nil {

@@ -79,7 +112,22 @@ t.Fail()

} } +func TestSendWithNewPhotoReply(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + if err != nil { + t.Fail() + } + + msg := tgbotapi.NewPhotoUpload(76918703, "tests/image.jpg") + msg.ReplyToMessageID = 480 + + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} func TestSendWithExistingPhoto(t *testing.T) { bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN"))

@@ -89,6 +137,7 @@ t.Fail()

} msg := tgbotapi.NewPhotoShare(76918703, "AgADAgADxKcxG4cBswqt13DnHOgbmBxDhCoABC0h01_AL4SKe20BAAEC") + msg.Caption = "Test" _, err = bot.Send(msg) if err != nil {

@@ -126,6 +175,89 @@ t.Fail()

} } +func TestSendWithNewAudio(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + msg := tgbotapi.NewAudioUpload(76918703, "tests/audio.mp3") + msg.Title = "TEST" + msg.Duration = 10 + msg.Performer = "TEST" + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + +func TestSendWithExistingAudio(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + msg := tgbotapi.NewAudioShare(76918703, "BQADAgADMwADhwGzCkYFlCTpxiP6Ag") + msg.Title = "TEST" + msg.Duration = 10 + msg.Performer = "TEST" + + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + +func TestSendWithNewVoice(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + msg := tgbotapi.NewVoiceUpload(76918703, "tests/voice.ogg") + msg.Duration = 10 + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + +func TestSendWithExistingVoice(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + msg := tgbotapi.NewVoiceShare(76918703, "AwADAgADIgADhwGzCigyMW_GUtWIAg") + msg.Duration = 10 + _, err = bot.Send(msg) + + if err != nil { + t.Fail() + } +} + +func TestSendWithLocation(t *testing.T) { + bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN")) + + if err != nil { + t.Fail() + } + + _, err = bot.Send(tgbotapi.NewLocation(76918703, 40, 40)) + + if err != nil { + t.Fail() + } +} + func TestGetFile(t *testing.T) { bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_API_TOKEN"))

@@ -179,7 +311,7 @@

var ucfg tgbotapi.UpdateConfig = tgbotapi.NewUpdate(0) ucfg.Timeout = 60 err = bot.UpdatesChan(ucfg) - + if err != nil { t.Fail() }
M configs.goconfigs.go

@@ -165,6 +165,7 @@ }

func (config ForwardConfig) Values() (url.Values, error) { v, _ := config.BaseChat.Values() + v.Add("from_chat_id", strconv.Itoa(config.FromChatID)) v.Add("message_id", strconv.Itoa(config.MessageID)) return v, nil }