all repos — telegram-bot-api @ 17d3e395d52d40e76b22f043424937a4e8d2f58c

Golang bindings for the Telegram Bot API

bot_test.go (view raw)

   1package tgbotapi
   2
   3import (
   4	"net/http"
   5	"os"
   6	"testing"
   7	"time"
   8)
   9
  10const (
  11	TestToken               = "153667468:AAHlSHlMqSt1f_uFmVRJbm5gntu2HI4WW8I"
  12	ChatID                  = 76918703
  13	Channel                 = "@tgbotapitest"
  14	SupergroupChatID        = -1001120141283
  15	ReplyToMessageID        = 35
  16	ExistingPhotoFileID     = "AgACAgIAAxkDAAEBFUZhIALQ9pZN4BUe8ZSzUU_2foSo1AACnrMxG0BucEhezsBWOgcikQEAAwIAA20AAyAE"
  17	ExistingDocumentFileID  = "BQADAgADOQADjMcoCcioX1GrDvp3Ag"
  18	ExistingAudioFileID     = "BQADAgADRgADjMcoCdXg3lSIN49lAg"
  19	ExistingVoiceFileID     = "AwADAgADWQADjMcoCeul6r_q52IyAg"
  20	ExistingVideoFileID     = "BAADAgADZgADjMcoCav432kYe0FRAg"
  21	ExistingVideoNoteFileID = "DQADAgADdQAD70cQSUK41dLsRMqfAg"
  22	ExistingStickerFileID   = "BQADAgADcwADjMcoCbdl-6eB--YPAg"
  23)
  24
  25type testLogger struct {
  26	t *testing.T
  27}
  28
  29func (t testLogger) Println(v ...interface{}) {
  30	t.t.Log(v...)
  31}
  32
  33func (t testLogger) Printf(format string, v ...interface{}) {
  34	t.t.Logf(format, v...)
  35}
  36
  37func getBot(t *testing.T) (*BotAPI, error) {
  38	bot, err := NewBotAPI(TestToken)
  39	bot.Debug = true
  40
  41	logger := testLogger{t}
  42	SetLogger(logger)
  43
  44	if err != nil {
  45		t.Error(err)
  46	}
  47
  48	return bot, err
  49}
  50
  51func TestNewBotAPI_notoken(t *testing.T) {
  52	_, err := NewBotAPI("")
  53
  54	if err == nil {
  55		t.Error(err)
  56	}
  57}
  58
  59func TestGetUpdates(t *testing.T) {
  60	bot, _ := getBot(t)
  61
  62	u := NewUpdate(0)
  63
  64	_, err := bot.GetUpdates(u)
  65
  66	if err != nil {
  67		t.Error(err)
  68	}
  69}
  70
  71func TestSendWithMessage(t *testing.T) {
  72	bot, _ := getBot(t)
  73
  74	msg := NewMessage(ChatID, "A test message from the test library in telegram-bot-api")
  75	msg.ParseMode = ModeMarkdown
  76	_, err := bot.Send(msg)
  77
  78	if err != nil {
  79		t.Error(err)
  80	}
  81}
  82
  83func TestSendWithMessageReply(t *testing.T) {
  84	bot, _ := getBot(t)
  85
  86	msg := NewMessage(ChatID, "A test message from the test library in telegram-bot-api")
  87	msg.ReplyToMessageID = ReplyToMessageID
  88	_, err := bot.Send(msg)
  89
  90	if err != nil {
  91		t.Error(err)
  92	}
  93}
  94
  95func TestSendWithMessageForward(t *testing.T) {
  96	bot, _ := getBot(t)
  97
  98	msg := NewForward(ChatID, ChatID, ReplyToMessageID)
  99	_, err := bot.Send(msg)
 100
 101	if err != nil {
 102		t.Error(err)
 103	}
 104}
 105
 106func TestCopyMessage(t *testing.T) {
 107	bot, _ := getBot(t)
 108
 109	msg := NewMessage(ChatID, "A test message from the test library in telegram-bot-api")
 110	message, err := bot.Send(msg)
 111	if err != nil {
 112		t.Error(err)
 113	}
 114
 115	copyMessageConfig := NewCopyMessage(SupergroupChatID, message.Chat.ID, message.MessageID)
 116	messageID, err := bot.CopyMessage(copyMessageConfig)
 117	if err != nil {
 118		t.Error(err)
 119	}
 120
 121	if messageID.MessageID == message.MessageID {
 122		t.Error("copied message ID was the same as original message")
 123	}
 124}
 125
 126func TestSendWithNewPhoto(t *testing.T) {
 127	bot, _ := getBot(t)
 128
 129	msg := NewPhoto(ChatID, FilePath("tests/image.jpg"))
 130	msg.Caption = "Test"
 131	_, err := bot.Send(msg)
 132
 133	if err != nil {
 134		t.Error(err)
 135	}
 136}
 137
 138func TestSendWithNewPhotoWithFileBytes(t *testing.T) {
 139	bot, _ := getBot(t)
 140
 141	data, _ := os.ReadFile("tests/image.jpg")
 142	b := FileBytes{Name: "image.jpg", Bytes: data}
 143
 144	msg := NewPhoto(ChatID, b)
 145	msg.Caption = "Test"
 146	_, err := bot.Send(msg)
 147
 148	if err != nil {
 149		t.Error(err)
 150	}
 151}
 152
 153func TestSendWithNewPhotoWithFileReader(t *testing.T) {
 154	bot, _ := getBot(t)
 155
 156	f, _ := os.Open("tests/image.jpg")
 157	reader := FileReader{Name: "image.jpg", Reader: f}
 158
 159	msg := NewPhoto(ChatID, reader)
 160	msg.Caption = "Test"
 161	_, err := bot.Send(msg)
 162
 163	if err != nil {
 164		t.Error(err)
 165	}
 166}
 167
 168func TestSendWithNewPhotoReply(t *testing.T) {
 169	bot, _ := getBot(t)
 170
 171	msg := NewPhoto(ChatID, FilePath("tests/image.jpg"))
 172	msg.ReplyToMessageID = ReplyToMessageID
 173
 174	_, err := bot.Send(msg)
 175
 176	if err != nil {
 177		t.Error(err)
 178	}
 179}
 180
 181func TestSendNewPhotoToChannel(t *testing.T) {
 182	bot, _ := getBot(t)
 183
 184	msg := NewPhotoToChannel(Channel, FilePath("tests/image.jpg"))
 185	msg.Caption = "Test"
 186	_, err := bot.Send(msg)
 187
 188	if err != nil {
 189		t.Error(err)
 190		t.Fail()
 191	}
 192}
 193
 194func TestSendNewPhotoToChannelFileBytes(t *testing.T) {
 195	bot, _ := getBot(t)
 196
 197	data, _ := os.ReadFile("tests/image.jpg")
 198	b := FileBytes{Name: "image.jpg", Bytes: data}
 199
 200	msg := NewPhotoToChannel(Channel, b)
 201	msg.Caption = "Test"
 202	_, err := bot.Send(msg)
 203
 204	if err != nil {
 205		t.Error(err)
 206		t.Fail()
 207	}
 208}
 209
 210func TestSendNewPhotoToChannelFileReader(t *testing.T) {
 211	bot, _ := getBot(t)
 212
 213	f, _ := os.Open("tests/image.jpg")
 214	reader := FileReader{Name: "image.jpg", Reader: f}
 215
 216	msg := NewPhotoToChannel(Channel, reader)
 217	msg.Caption = "Test"
 218	_, err := bot.Send(msg)
 219
 220	if err != nil {
 221		t.Error(err)
 222		t.Fail()
 223	}
 224}
 225
 226func TestSendWithExistingPhoto(t *testing.T) {
 227	bot, _ := getBot(t)
 228
 229	msg := NewPhoto(ChatID, FileID(ExistingPhotoFileID))
 230	msg.Caption = "Test"
 231	_, err := bot.Send(msg)
 232
 233	if err != nil {
 234		t.Error(err)
 235	}
 236}
 237
 238func TestSendWithNewDocument(t *testing.T) {
 239	bot, _ := getBot(t)
 240
 241	msg := NewDocument(ChatID, FilePath("tests/image.jpg"))
 242	_, err := bot.Send(msg)
 243
 244	if err != nil {
 245		t.Error(err)
 246	}
 247}
 248
 249func TestSendWithNewDocumentAndThumb(t *testing.T) {
 250	bot, _ := getBot(t)
 251
 252	msg := NewDocument(ChatID, FilePath("tests/voice.ogg"))
 253	msg.Thumb = FilePath("tests/image.jpg")
 254	_, err := bot.Send(msg)
 255
 256	if err != nil {
 257		t.Error(err)
 258	}
 259}
 260
 261func TestSendWithExistingDocument(t *testing.T) {
 262	bot, _ := getBot(t)
 263
 264	msg := NewDocument(ChatID, FileID(ExistingDocumentFileID))
 265	_, err := bot.Send(msg)
 266
 267	if err != nil {
 268		t.Error(err)
 269	}
 270}
 271
 272func TestSendWithNewAudio(t *testing.T) {
 273	bot, _ := getBot(t)
 274
 275	msg := NewAudio(ChatID, FilePath("tests/audio.mp3"))
 276	msg.Title = "TEST"
 277	msg.Duration = 10
 278	msg.Performer = "TEST"
 279	_, err := bot.Send(msg)
 280
 281	if err != nil {
 282		t.Error(err)
 283	}
 284}
 285
 286func TestSendWithExistingAudio(t *testing.T) {
 287	bot, _ := getBot(t)
 288
 289	msg := NewAudio(ChatID, FileID(ExistingAudioFileID))
 290	msg.Title = "TEST"
 291	msg.Duration = 10
 292	msg.Performer = "TEST"
 293
 294	_, err := bot.Send(msg)
 295
 296	if err != nil {
 297		t.Error(err)
 298	}
 299}
 300
 301func TestSendWithNewVoice(t *testing.T) {
 302	bot, _ := getBot(t)
 303
 304	msg := NewVoice(ChatID, FilePath("tests/voice.ogg"))
 305	msg.Duration = 10
 306	_, err := bot.Send(msg)
 307
 308	if err != nil {
 309		t.Error(err)
 310	}
 311}
 312
 313func TestSendWithExistingVoice(t *testing.T) {
 314	bot, _ := getBot(t)
 315
 316	msg := NewVoice(ChatID, FileID(ExistingVoiceFileID))
 317	msg.Duration = 10
 318	_, err := bot.Send(msg)
 319
 320	if err != nil {
 321		t.Error(err)
 322	}
 323}
 324
 325func TestSendWithContact(t *testing.T) {
 326	bot, _ := getBot(t)
 327
 328	contact := NewContact(ChatID, "5551234567", "Test")
 329
 330	if _, err := bot.Send(contact); err != nil {
 331		t.Error(err)
 332	}
 333}
 334
 335func TestSendWithLocation(t *testing.T) {
 336	bot, _ := getBot(t)
 337
 338	_, err := bot.Send(NewLocation(ChatID, 40, 40))
 339
 340	if err != nil {
 341		t.Error(err)
 342	}
 343}
 344
 345func TestSendWithVenue(t *testing.T) {
 346	bot, _ := getBot(t)
 347
 348	venue := NewVenue(ChatID, "A Test Location", "123 Test Street", 40, 40)
 349
 350	if _, err := bot.Send(venue); err != nil {
 351		t.Error(err)
 352	}
 353}
 354
 355func TestSendWithNewVideo(t *testing.T) {
 356	bot, _ := getBot(t)
 357
 358	msg := NewVideo(ChatID, FilePath("tests/video.mp4"))
 359	msg.Duration = 10
 360	msg.Caption = "TEST"
 361
 362	_, err := bot.Send(msg)
 363
 364	if err != nil {
 365		t.Error(err)
 366	}
 367}
 368
 369func TestSendWithExistingVideo(t *testing.T) {
 370	bot, _ := getBot(t)
 371
 372	msg := NewVideo(ChatID, FileID(ExistingVideoFileID))
 373	msg.Duration = 10
 374	msg.Caption = "TEST"
 375
 376	_, err := bot.Send(msg)
 377
 378	if err != nil {
 379		t.Error(err)
 380	}
 381}
 382
 383func TestSendWithNewVideoNote(t *testing.T) {
 384	bot, _ := getBot(t)
 385
 386	msg := NewVideoNote(ChatID, 240, FilePath("tests/videonote.mp4"))
 387	msg.Duration = 10
 388
 389	_, err := bot.Send(msg)
 390
 391	if err != nil {
 392		t.Error(err)
 393	}
 394}
 395
 396func TestSendWithExistingVideoNote(t *testing.T) {
 397	bot, _ := getBot(t)
 398
 399	msg := NewVideoNote(ChatID, 240, FileID(ExistingVideoNoteFileID))
 400	msg.Duration = 10
 401
 402	_, err := bot.Send(msg)
 403
 404	if err != nil {
 405		t.Error(err)
 406	}
 407}
 408
 409func TestSendWithNewSticker(t *testing.T) {
 410	bot, _ := getBot(t)
 411
 412	msg := NewSticker(ChatID, FilePath("tests/image.jpg"))
 413
 414	_, err := bot.Send(msg)
 415
 416	if err != nil {
 417		t.Error(err)
 418	}
 419}
 420
 421func TestSendWithExistingSticker(t *testing.T) {
 422	bot, _ := getBot(t)
 423
 424	msg := NewSticker(ChatID, FileID(ExistingStickerFileID))
 425
 426	_, err := bot.Send(msg)
 427
 428	if err != nil {
 429		t.Error(err)
 430	}
 431}
 432
 433func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
 434	bot, _ := getBot(t)
 435
 436	msg := NewSticker(ChatID, FilePath("tests/image.jpg"))
 437	msg.ReplyMarkup = ReplyKeyboardRemove{
 438		RemoveKeyboard: true,
 439		Selective:      false,
 440	}
 441	_, err := bot.Send(msg)
 442
 443	if err != nil {
 444		t.Error(err)
 445	}
 446}
 447
 448func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) {
 449	bot, _ := getBot(t)
 450
 451	msg := NewSticker(ChatID, FileID(ExistingStickerFileID))
 452	msg.ReplyMarkup = ReplyKeyboardRemove{
 453		RemoveKeyboard: true,
 454		Selective:      false,
 455	}
 456
 457	_, err := bot.Send(msg)
 458
 459	if err != nil {
 460		t.Error(err)
 461	}
 462}
 463
 464func TestSendWithDice(t *testing.T) {
 465	bot, _ := getBot(t)
 466
 467	msg := NewDice(ChatID)
 468	_, err := bot.Send(msg)
 469
 470	if err != nil {
 471		t.Error(err)
 472		t.Fail()
 473	}
 474
 475}
 476
 477func TestSendWithDiceWithEmoji(t *testing.T) {
 478	bot, _ := getBot(t)
 479
 480	msg := NewDiceWithEmoji(ChatID, "🏀")
 481	_, err := bot.Send(msg)
 482
 483	if err != nil {
 484		t.Error(err)
 485		t.Fail()
 486	}
 487
 488}
 489
 490func TestGetFile(t *testing.T) {
 491	bot, _ := getBot(t)
 492
 493	file := FileConfig{
 494		FileID: ExistingPhotoFileID,
 495	}
 496
 497	_, err := bot.GetFile(file)
 498
 499	if err != nil {
 500		t.Error(err)
 501	}
 502}
 503
 504func TestSendChatConfig(t *testing.T) {
 505	bot, _ := getBot(t)
 506
 507	_, err := bot.Request(NewChatAction(ChatID, ChatTyping))
 508
 509	if err != nil {
 510		t.Error(err)
 511	}
 512}
 513
 514// TODO: identify why this isn't working
 515// func TestSendEditMessage(t *testing.T) {
 516// 	bot, _ := getBot(t)
 517
 518// 	msg, err := bot.Send(NewMessage(ChatID, "Testing editing."))
 519// 	if err != nil {
 520// 		t.Error(err)
 521// 	}
 522
 523// 	edit := EditMessageTextConfig{
 524// 		BaseEdit: BaseEdit{
 525// 			ChatID:    ChatID,
 526// 			MessageID: msg.MessageID,
 527// 		},
 528// 		Text: "Updated text.",
 529// 	}
 530
 531// 	_, err = bot.Send(edit)
 532// 	if err != nil {
 533// 		t.Error(err)
 534// 	}
 535// }
 536
 537func TestGetUserProfilePhotos(t *testing.T) {
 538	bot, _ := getBot(t)
 539
 540	_, err := bot.GetUserProfilePhotos(NewUserProfilePhotos(ChatID))
 541	if err != nil {
 542		t.Error(err)
 543	}
 544}
 545
 546func TestSetWebhookWithCert(t *testing.T) {
 547	bot, _ := getBot(t)
 548
 549	time.Sleep(time.Second * 2)
 550
 551	bot.Request(DeleteWebhookConfig{})
 552
 553	wh, err := NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, FilePath("tests/cert.pem"))
 554
 555	if err != nil {
 556		t.Error(err)
 557	}
 558	_, err = bot.Request(wh)
 559
 560	if err != nil {
 561		t.Error(err)
 562	}
 563
 564	_, err = bot.GetWebhookInfo()
 565
 566	if err != nil {
 567		t.Error(err)
 568	}
 569
 570	bot.Request(DeleteWebhookConfig{})
 571}
 572
 573func TestSetWebhookWithoutCert(t *testing.T) {
 574	bot, _ := getBot(t)
 575
 576	time.Sleep(time.Second * 2)
 577
 578	bot.Request(DeleteWebhookConfig{})
 579
 580	wh, err := NewWebhook("https://example.com/tgbotapi-test/" + bot.Token)
 581
 582	if err != nil {
 583		t.Error(err)
 584	}
 585
 586	_, err = bot.Request(wh)
 587
 588	if err != nil {
 589		t.Error(err)
 590	}
 591
 592	info, err := bot.GetWebhookInfo()
 593
 594	if err != nil {
 595		t.Error(err)
 596	}
 597	if info.MaxConnections == 0 {
 598		t.Errorf("Expected maximum connections to be greater than 0")
 599	}
 600	if info.LastErrorDate != 0 {
 601		t.Errorf("failed to set webhook: %s", info.LastErrorMessage)
 602	}
 603
 604	bot.Request(DeleteWebhookConfig{})
 605}
 606
 607func TestSendWithMediaGroupPhotoVideo(t *testing.T) {
 608	bot, _ := getBot(t)
 609
 610	cfg := NewMediaGroup(ChatID, []interface{}{
 611		NewInputMediaPhoto(FileURL("https://github.com/go-telegram-bot-api/telegram-bot-api/raw/0a3a1c8716c4cd8d26a262af9f12dcbab7f3f28c/tests/image.jpg")),
 612		NewInputMediaPhoto(FilePath("tests/image.jpg")),
 613		NewInputMediaVideo(FilePath("tests/video.mp4")),
 614	})
 615
 616	messages, err := bot.SendMediaGroup(cfg)
 617	if err != nil {
 618		t.Error(err)
 619	}
 620
 621	if messages == nil {
 622		t.Error("No received messages")
 623	}
 624
 625	if len(messages) != len(cfg.Media) {
 626		t.Errorf("Different number of messages: %d", len(messages))
 627	}
 628}
 629
 630func TestSendWithMediaGroupDocument(t *testing.T) {
 631	bot, _ := getBot(t)
 632
 633	cfg := NewMediaGroup(ChatID, []interface{}{
 634		NewInputMediaDocument(FileURL("https://i.imgur.com/unQLJIb.jpg")),
 635		NewInputMediaDocument(FilePath("tests/image.jpg")),
 636	})
 637
 638	messages, err := bot.SendMediaGroup(cfg)
 639	if err != nil {
 640		t.Error(err)
 641	}
 642
 643	if messages == nil {
 644		t.Error("No received messages")
 645	}
 646
 647	if len(messages) != len(cfg.Media) {
 648		t.Errorf("Different number of messages: %d", len(messages))
 649	}
 650}
 651
 652func TestSendWithMediaGroupAudio(t *testing.T) {
 653	bot, _ := getBot(t)
 654
 655	cfg := NewMediaGroup(ChatID, []interface{}{
 656		NewInputMediaAudio(FilePath("tests/audio.mp3")),
 657		NewInputMediaAudio(FilePath("tests/audio.mp3")),
 658	})
 659
 660	messages, err := bot.SendMediaGroup(cfg)
 661	if err != nil {
 662		t.Error(err)
 663	}
 664
 665	if messages == nil {
 666		t.Error("No received messages")
 667	}
 668
 669	if len(messages) != len(cfg.Media) {
 670		t.Errorf("Different number of messages: %d", len(messages))
 671	}
 672}
 673
 674func ExampleNewBotAPI() {
 675	bot, err := NewBotAPI("MyAwesomeBotToken")
 676	if err != nil {
 677		panic(err)
 678	}
 679
 680	bot.Debug = true
 681
 682	log.Printf("Authorized on account %s", bot.Self.UserName)
 683
 684	u := NewUpdate(0)
 685	u.Timeout = 60
 686
 687	updates := bot.GetUpdatesChan(u)
 688
 689	// Optional: wait for updates and clear them if you don't want to handle
 690	// a large backlog of old messages
 691	time.Sleep(time.Millisecond * 500)
 692	updates.Clear()
 693
 694	for update := range updates {
 695		if update.Message == nil {
 696			continue
 697		}
 698
 699		log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
 700
 701		msg := NewMessage(update.Message.Chat.ID, update.Message.Text)
 702		msg.ReplyToMessageID = update.Message.MessageID
 703
 704		bot.Send(msg)
 705	}
 706}
 707
 708func ExampleNewWebhook() {
 709	bot, err := NewBotAPI("MyAwesomeBotToken")
 710	if err != nil {
 711		panic(err)
 712	}
 713
 714	bot.Debug = true
 715
 716	log.Printf("Authorized on account %s", bot.Self.UserName)
 717
 718	wh, err := NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, FilePath("cert.pem"))
 719
 720	if err != nil {
 721		panic(err)
 722	}
 723
 724	_, err = bot.Request(wh)
 725
 726	if err != nil {
 727		panic(err)
 728	}
 729
 730	info, err := bot.GetWebhookInfo()
 731
 732	if err != nil {
 733		panic(err)
 734	}
 735
 736	if info.LastErrorDate != 0 {
 737		log.Printf("failed to set webhook: %s", info.LastErrorMessage)
 738	}
 739
 740	updates := bot.ListenForWebhook("/" + bot.Token)
 741	go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)
 742
 743	for update := range updates {
 744		log.Printf("%+v\n", update)
 745	}
 746}
 747
 748func ExampleWebhookHandler() {
 749	bot, err := NewBotAPI("MyAwesomeBotToken")
 750	if err != nil {
 751		panic(err)
 752	}
 753
 754	bot.Debug = true
 755
 756	log.Printf("Authorized on account %s", bot.Self.UserName)
 757
 758	wh, err := NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, FilePath("cert.pem"))
 759
 760	if err != nil {
 761		panic(err)
 762	}
 763
 764	_, err = bot.Request(wh)
 765	if err != nil {
 766		panic(err)
 767	}
 768	info, err := bot.GetWebhookInfo()
 769	if err != nil {
 770		panic(err)
 771	}
 772	if info.LastErrorDate != 0 {
 773		log.Printf("[Telegram callback failed]%s", info.LastErrorMessage)
 774	}
 775
 776	http.HandleFunc("/"+bot.Token, func(w http.ResponseWriter, r *http.Request) {
 777		update, err := bot.HandleUpdate(r)
 778		if err != nil {
 779			log.Printf("%+v\n", err.Error())
 780		} else {
 781			log.Printf("%+v\n", *update)
 782		}
 783	})
 784
 785	go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)
 786}
 787
 788func ExampleInlineConfig() {
 789	bot, err := NewBotAPI("MyAwesomeBotToken") // create new bot
 790	if err != nil {
 791		panic(err)
 792	}
 793
 794	log.Printf("Authorized on account %s", bot.Self.UserName)
 795
 796	u := NewUpdate(0)
 797	u.Timeout = 60
 798
 799	updates := bot.GetUpdatesChan(u)
 800
 801	for update := range updates {
 802		if update.InlineQuery == nil { // if no inline query, ignore it
 803			continue
 804		}
 805
 806		article := NewInlineQueryResultArticle(update.InlineQuery.ID, "Echo", update.InlineQuery.Query)
 807		article.Description = update.InlineQuery.Query
 808
 809		inlineConf := InlineConfig{
 810			InlineQueryID: update.InlineQuery.ID,
 811			IsPersonal:    true,
 812			CacheTime:     0,
 813			Results:       []interface{}{article},
 814		}
 815
 816		if _, err := bot.Request(inlineConf); err != nil {
 817			log.Println(err)
 818		}
 819	}
 820}
 821
 822func TestDeleteMessage(t *testing.T) {
 823	bot, _ := getBot(t)
 824
 825	msg := NewMessage(ChatID, "A test message from the test library in telegram-bot-api")
 826	msg.ParseMode = ModeMarkdown
 827	message, _ := bot.Send(msg)
 828
 829	deleteMessageConfig := DeleteMessageConfig{
 830		ChatID:    message.Chat.ID,
 831		MessageID: message.MessageID,
 832	}
 833	_, err := bot.Request(deleteMessageConfig)
 834
 835	if err != nil {
 836		t.Error(err)
 837	}
 838}
 839
 840func TestPinChatMessage(t *testing.T) {
 841	bot, _ := getBot(t)
 842
 843	msg := NewMessage(SupergroupChatID, "A test message from the test library in telegram-bot-api")
 844	msg.ParseMode = ModeMarkdown
 845	message, _ := bot.Send(msg)
 846
 847	pinChatMessageConfig := PinChatMessageConfig{
 848		ChatID:              message.Chat.ID,
 849		MessageID:           message.MessageID,
 850		DisableNotification: false,
 851	}
 852	_, err := bot.Request(pinChatMessageConfig)
 853
 854	if err != nil {
 855		t.Error(err)
 856	}
 857}
 858
 859func TestUnpinChatMessage(t *testing.T) {
 860	bot, _ := getBot(t)
 861
 862	msg := NewMessage(SupergroupChatID, "A test message from the test library in telegram-bot-api")
 863	msg.ParseMode = ModeMarkdown
 864	message, _ := bot.Send(msg)
 865
 866	// We need pin message to unpin something
 867	pinChatMessageConfig := PinChatMessageConfig{
 868		ChatID:              message.Chat.ID,
 869		MessageID:           message.MessageID,
 870		DisableNotification: false,
 871	}
 872
 873	if _, err := bot.Request(pinChatMessageConfig); err != nil {
 874		t.Error(err)
 875	}
 876
 877	unpinChatMessageConfig := UnpinChatMessageConfig{
 878		ChatID:    message.Chat.ID,
 879		MessageID: message.MessageID,
 880	}
 881
 882	if _, err := bot.Request(unpinChatMessageConfig); err != nil {
 883		t.Error(err)
 884	}
 885}
 886
 887func TestUnpinAllChatMessages(t *testing.T) {
 888	bot, _ := getBot(t)
 889
 890	msg := NewMessage(SupergroupChatID, "A test message from the test library in telegram-bot-api")
 891	msg.ParseMode = ModeMarkdown
 892	message, _ := bot.Send(msg)
 893
 894	pinChatMessageConfig := PinChatMessageConfig{
 895		ChatID:              message.Chat.ID,
 896		MessageID:           message.MessageID,
 897		DisableNotification: true,
 898	}
 899
 900	if _, err := bot.Request(pinChatMessageConfig); err != nil {
 901		t.Error(err)
 902	}
 903
 904	unpinAllChatMessagesConfig := UnpinAllChatMessagesConfig{
 905		ChatID: message.Chat.ID,
 906	}
 907
 908	if _, err := bot.Request(unpinAllChatMessagesConfig); err != nil {
 909		t.Error(err)
 910	}
 911}
 912
 913func TestPolls(t *testing.T) {
 914	bot, _ := getBot(t)
 915
 916	poll := NewPoll(SupergroupChatID, "Are polls working?", "Yes", "No")
 917
 918	msg, err := bot.Send(poll)
 919	if err != nil {
 920		t.Error(err)
 921	}
 922
 923	result, err := bot.StopPoll(NewStopPoll(SupergroupChatID, msg.MessageID))
 924	if err != nil {
 925		t.Error(err)
 926	}
 927
 928	if result.Question != "Are polls working?" {
 929		t.Error("Poll question did not match")
 930	}
 931
 932	if !result.IsClosed {
 933		t.Error("Poll did not end")
 934	}
 935
 936	if result.Options[0].Text != "Yes" || result.Options[0].VoterCount != 0 || result.Options[1].Text != "No" || result.Options[1].VoterCount != 0 {
 937		t.Error("Poll options were incorrect")
 938	}
 939}
 940
 941func TestSendDice(t *testing.T) {
 942	bot, _ := getBot(t)
 943
 944	dice := NewDice(ChatID)
 945
 946	msg, err := bot.Send(dice)
 947	if err != nil {
 948		t.Error("Unable to send dice roll")
 949	}
 950
 951	if msg.Dice == nil {
 952		t.Error("Dice roll was not received")
 953	}
 954}
 955
 956func TestCommands(t *testing.T) {
 957	bot, _ := getBot(t)
 958
 959	setCommands := NewSetMyCommands(BotCommand{
 960		Command:     "test",
 961		Description: "a test command",
 962	})
 963
 964	if _, err := bot.Request(setCommands); err != nil {
 965		t.Error("Unable to set commands")
 966	}
 967
 968	commands, err := bot.GetMyCommands()
 969	if err != nil {
 970		t.Error("Unable to get commands")
 971	}
 972
 973	if len(commands) != 1 {
 974		t.Error("Incorrect number of commands returned")
 975	}
 976
 977	if commands[0].Command != "test" || commands[0].Description != "a test command" {
 978		t.Error("Commands were incorrectly set")
 979	}
 980
 981	setCommands = NewSetMyCommandsWithScope(NewBotCommandScopeAllPrivateChats(), BotCommand{
 982		Command:     "private",
 983		Description: "a private command",
 984	})
 985
 986	if _, err := bot.Request(setCommands); err != nil {
 987		t.Error("Unable to set commands")
 988	}
 989
 990	commands, err = bot.GetMyCommandsWithConfig(NewGetMyCommandsWithScope(NewBotCommandScopeAllPrivateChats()))
 991	if err != nil {
 992		t.Error("Unable to get commands")
 993	}
 994
 995	if len(commands) != 1 {
 996		t.Error("Incorrect number of commands returned")
 997	}
 998
 999	if commands[0].Command != "private" || commands[0].Description != "a private command" {
1000		t.Error("Commands were incorrectly set")
1001	}
1002}
1003
1004// TODO: figure out why test is failing
1005//
1006// func TestEditMessageMedia(t *testing.T) {
1007// 	bot, _ := getBot(t)
1008
1009// 	msg := NewPhoto(ChatID, "tests/image.jpg")
1010// 	msg.Caption = "Test"
1011// 	m, err := bot.Send(msg)
1012
1013// 	if err != nil {
1014// 		t.Error(err)
1015// 	}
1016
1017// 	edit := EditMessageMediaConfig{
1018// 		BaseEdit: BaseEdit{
1019// 			ChatID:    ChatID,
1020// 			MessageID: m.MessageID,
1021// 		},
1022// 		Media: NewInputMediaVideo(FilePath("tests/video.mp4")),
1023// 	}
1024
1025// 	_, err = bot.Request(edit)
1026// 	if err != nil {
1027// 		t.Error(err)
1028// 	}
1029// }
1030
1031func TestPrepareInputMediaForParams(t *testing.T) {
1032	media := []interface{}{
1033		NewInputMediaPhoto(FilePath("tests/image.jpg")),
1034		NewInputMediaVideo(FileID("test")),
1035	}
1036
1037	prepared := prepareInputMediaForParams(media)
1038
1039	if media[0].(InputMediaPhoto).Media != FilePath("tests/image.jpg") {
1040		t.Error("Original media was changed")
1041	}
1042
1043	if prepared[0].(InputMediaPhoto).Media != fileAttach("attach://file-0") {
1044		t.Error("New media was not replaced")
1045	}
1046
1047	if prepared[1].(InputMediaVideo).Media != FileID("test") {
1048		t.Error("Passthrough value was not the same")
1049	}
1050}