all repos — telegram-bot-api @ 4064ced03f921894c1c8ee0b40476903f7d10b40

Golang bindings for the Telegram Bot API

bot_test.go (view raw)

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