helpers.go (view raw)
1package tgbotapi
2
3import (
4 "net/url"
5)
6
7// NewMessage creates a new Message.
8//
9// chatID is where to send it, text is the message text.
10func NewMessage(chatID int64, text string) MessageConfig {
11 return MessageConfig{
12 BaseChat: BaseChat{
13 ChatID: chatID,
14 ReplyToMessageID: 0,
15 },
16 Text: text,
17 DisableWebPagePreview: false,
18 }
19}
20
21// NewDeleteMessage creates a request to delete a message.
22func NewDeleteMessage(chatID int64, messageID int) DeleteMessageConfig {
23 return DeleteMessageConfig{
24 ChatID: chatID,
25 MessageID: messageID,
26 }
27}
28
29// NewMessageToChannel creates a new Message that is sent to a channel
30// by username.
31//
32// username is the username of the channel, text is the message text,
33// and the username should be in the form of `@username`.
34func NewMessageToChannel(username string, text string) MessageConfig {
35 return MessageConfig{
36 BaseChat: BaseChat{
37 ChannelUsername: username,
38 },
39 Text: text,
40 }
41}
42
43// NewForward creates a new forward.
44//
45// chatID is where to send it, fromChatID is the source chat,
46// and messageID is the ID of the original message.
47func NewForward(chatID int64, fromChatID int64, messageID int) ForwardConfig {
48 return ForwardConfig{
49 BaseChat: BaseChat{ChatID: chatID},
50 FromChatID: fromChatID,
51 MessageID: messageID,
52 }
53}
54
55// NewPhotoUpload creates a new photo uploader.
56//
57// chatID is where to send it, file is a string path to the file,
58// FileReader, or FileBytes.
59//
60// Note that you must send animated GIFs as a document.
61func NewPhotoUpload(chatID int64, file interface{}) PhotoConfig {
62 return PhotoConfig{
63 BaseFile: BaseFile{
64 BaseChat: BaseChat{ChatID: chatID},
65 File: file,
66 UseExisting: false,
67 },
68 }
69}
70
71// NewPhotoUploadToChannel creates a new photo uploader to send a photo to a channel.
72//
73// username is the username of the channel, file is a string path to the file,
74// FileReader, or FileBytes.
75//
76// Note that you must send animated GIFs as a document.
77func NewPhotoUploadToChannel(username string, file interface{}) PhotoConfig {
78 return PhotoConfig{
79 BaseFile: BaseFile{
80 BaseChat: BaseChat{
81 ChannelUsername: username,
82 },
83 File: file,
84 UseExisting: false,
85 },
86 }
87}
88
89// NewPhotoShare shares an existing photo.
90// You may use this to reshare an existing photo without reuploading it.
91//
92// chatID is where to send it, fileID is the ID of the file
93// already uploaded.
94func NewPhotoShare(chatID int64, fileID string) PhotoConfig {
95 return PhotoConfig{
96 BaseFile: BaseFile{
97 BaseChat: BaseChat{ChatID: chatID},
98 FileID: fileID,
99 UseExisting: true,
100 },
101 }
102}
103
104// NewAudioUpload creates a new audio uploader.
105//
106// chatID is where to send it, file is a string path to the file,
107// FileReader, or FileBytes.
108func NewAudioUpload(chatID int64, file interface{}) AudioConfig {
109 return AudioConfig{
110 BaseFile: BaseFile{
111 BaseChat: BaseChat{ChatID: chatID},
112 File: file,
113 UseExisting: false,
114 },
115 }
116}
117
118// NewAudioShare shares an existing audio file.
119// You may use this to reshare an existing audio file without
120// reuploading it.
121//
122// chatID is where to send it, fileID is the ID of the audio
123// already uploaded.
124func NewAudioShare(chatID int64, fileID string) AudioConfig {
125 return AudioConfig{
126 BaseFile: BaseFile{
127 BaseChat: BaseChat{ChatID: chatID},
128 FileID: fileID,
129 UseExisting: true,
130 },
131 }
132}
133
134// NewDocumentUpload creates a new document uploader.
135//
136// chatID is where to send it, file is a string path to the file,
137// FileReader, or FileBytes.
138func NewDocumentUpload(chatID int64, file interface{}) DocumentConfig {
139 return DocumentConfig{
140 BaseFile: BaseFile{
141 BaseChat: BaseChat{ChatID: chatID},
142 File: file,
143 UseExisting: false,
144 },
145 }
146}
147
148// NewDocumentShare shares an existing document.
149// You may use this to reshare an existing document without
150// reuploading it.
151//
152// chatID is where to send it, fileID is the ID of the document
153// already uploaded.
154func NewDocumentShare(chatID int64, fileID string) DocumentConfig {
155 return DocumentConfig{
156 BaseFile: BaseFile{
157 BaseChat: BaseChat{ChatID: chatID},
158 FileID: fileID,
159 UseExisting: true,
160 },
161 }
162}
163
164// NewStickerUpload creates a new sticker uploader.
165//
166// chatID is where to send it, file is a string path to the file,
167// FileReader, or FileBytes.
168func NewStickerUpload(chatID int64, file interface{}) StickerConfig {
169 return StickerConfig{
170 BaseFile: BaseFile{
171 BaseChat: BaseChat{ChatID: chatID},
172 File: file,
173 UseExisting: false,
174 },
175 }
176}
177
178// NewStickerShare shares an existing sticker.
179// You may use this to reshare an existing sticker without
180// reuploading it.
181//
182// chatID is where to send it, fileID is the ID of the sticker
183// already uploaded.
184func NewStickerShare(chatID int64, fileID string) StickerConfig {
185 return StickerConfig{
186 BaseFile: BaseFile{
187 BaseChat: BaseChat{ChatID: chatID},
188 FileID: fileID,
189 UseExisting: true,
190 },
191 }
192}
193
194// NewVideoUpload creates a new video uploader.
195//
196// chatID is where to send it, file is a string path to the file,
197// FileReader, or FileBytes.
198func NewVideoUpload(chatID int64, file interface{}) VideoConfig {
199 return VideoConfig{
200 BaseFile: BaseFile{
201 BaseChat: BaseChat{ChatID: chatID},
202 File: file,
203 UseExisting: false,
204 },
205 }
206}
207
208// NewVideoShare shares an existing video.
209// You may use this to reshare an existing video without reuploading it.
210//
211// chatID is where to send it, fileID is the ID of the video
212// already uploaded.
213func NewVideoShare(chatID int64, fileID string) VideoConfig {
214 return VideoConfig{
215 BaseFile: BaseFile{
216 BaseChat: BaseChat{ChatID: chatID},
217 FileID: fileID,
218 UseExisting: true,
219 },
220 }
221}
222
223// NewAnimationUpload creates a new animation uploader.
224//
225// chatID is where to send it, file is a string path to the file,
226// FileReader, or FileBytes.
227func NewAnimationUpload(chatID int64, file interface{}) AnimationConfig {
228 return AnimationConfig{
229 BaseFile: BaseFile{
230 BaseChat: BaseChat{ChatID: chatID},
231 File: file,
232 UseExisting: false,
233 },
234 }
235}
236
237// NewAnimationShare shares an existing animation.
238// You may use this to reshare an existing animation without reuploading it.
239//
240// chatID is where to send it, fileID is the ID of the animation
241// already uploaded.
242func NewAnimationShare(chatID int64, fileID string) AnimationConfig {
243 return AnimationConfig{
244 BaseFile: BaseFile{
245 BaseChat: BaseChat{ChatID: chatID},
246 FileID: fileID,
247 UseExisting: true,
248 },
249 }
250}
251
252// NewVideoNoteUpload creates a new video note uploader.
253//
254// chatID is where to send it, file is a string path to the file,
255// FileReader, or FileBytes.
256func NewVideoNoteUpload(chatID int64, length int, file interface{}) VideoNoteConfig {
257 return VideoNoteConfig{
258 BaseFile: BaseFile{
259 BaseChat: BaseChat{ChatID: chatID},
260 File: file,
261 UseExisting: false,
262 },
263 Length: length,
264 }
265}
266
267// NewVideoNoteShare shares an existing video.
268// You may use this to reshare an existing video without reuploading it.
269//
270// chatID is where to send it, fileID is the ID of the video
271// already uploaded.
272func NewVideoNoteShare(chatID int64, length int, fileID string) VideoNoteConfig {
273 return VideoNoteConfig{
274 BaseFile: BaseFile{
275 BaseChat: BaseChat{ChatID: chatID},
276 FileID: fileID,
277 UseExisting: true,
278 },
279 Length: length,
280 }
281}
282
283// NewVoiceUpload creates a new voice uploader.
284//
285// chatID is where to send it, file is a string path to the file,
286// FileReader, or FileBytes.
287func NewVoiceUpload(chatID int64, file interface{}) VoiceConfig {
288 return VoiceConfig{
289 BaseFile: BaseFile{
290 BaseChat: BaseChat{ChatID: chatID},
291 File: file,
292 UseExisting: false,
293 },
294 }
295}
296
297// NewVoiceShare shares an existing voice.
298// You may use this to reshare an existing voice without reuploading it.
299//
300// chatID is where to send it, fileID is the ID of the video
301// already uploaded.
302func NewVoiceShare(chatID int64, fileID string) VoiceConfig {
303 return VoiceConfig{
304 BaseFile: BaseFile{
305 BaseChat: BaseChat{ChatID: chatID},
306 FileID: fileID,
307 UseExisting: true,
308 },
309 }
310}
311
312// NewMediaGroup creates a new media group. Files should be an array of
313// two to ten InputMediaPhoto or InputMediaVideo.
314func NewMediaGroup(chatID int64, files []interface{}) MediaGroupConfig {
315 return MediaGroupConfig{
316 ChatID: chatID,
317 Media: files,
318 }
319}
320
321// NewInputMediaPhoto creates a new InputMediaPhoto.
322func NewInputMediaPhoto(media string) InputMediaPhoto {
323 return InputMediaPhoto{
324 BaseInputMedia{
325 Type: "photo",
326 Media: media,
327 },
328 }
329}
330
331// NewInputMediaVideo creates a new InputMediaVideo.
332func NewInputMediaVideo(media string) InputMediaVideo {
333 return InputMediaVideo{
334 BaseInputMedia: BaseInputMedia{
335 Type: "video",
336 Media: media,
337 },
338 }
339}
340
341// NewInputMediaAnimation creates a new InputMediaAnimation.
342func NewInputMediaAnimation(media string) InputMediaAnimation {
343 return InputMediaAnimation{
344 BaseInputMedia: BaseInputMedia{
345 Type: "animation",
346 Media: media,
347 },
348 }
349}
350
351// NewInputMediaAudio creates a new InputMediaAudio.
352func NewInputMediaAudio(media string) InputMediaAudio {
353 return InputMediaAudio{
354 BaseInputMedia: BaseInputMedia{
355 Type: "audio",
356 Media: media,
357 },
358 }
359}
360
361// NewInputMediaDocument creates a new InputMediaDocument.
362func NewInputMediaDocument(media string) InputMediaDocument {
363 return InputMediaDocument{
364 BaseInputMedia: BaseInputMedia{
365 Type: "document",
366 Media: media,
367 },
368 }
369}
370
371// NewContact allows you to send a shared contact.
372func NewContact(chatID int64, phoneNumber, firstName string) ContactConfig {
373 return ContactConfig{
374 BaseChat: BaseChat{
375 ChatID: chatID,
376 },
377 PhoneNumber: phoneNumber,
378 FirstName: firstName,
379 }
380}
381
382// NewLocation shares your location.
383//
384// chatID is where to send it, latitude and longitude are coordinates.
385func NewLocation(chatID int64, latitude float64, longitude float64) LocationConfig {
386 return LocationConfig{
387 BaseChat: BaseChat{
388 ChatID: chatID,
389 },
390 Latitude: latitude,
391 Longitude: longitude,
392 }
393}
394
395// NewVenue allows you to send a venue and its location.
396func NewVenue(chatID int64, title, address string, latitude, longitude float64) VenueConfig {
397 return VenueConfig{
398 BaseChat: BaseChat{
399 ChatID: chatID,
400 },
401 Title: title,
402 Address: address,
403 Latitude: latitude,
404 Longitude: longitude,
405 }
406}
407
408// NewChatAction sets a chat action.
409// Actions last for 5 seconds, or until your next action.
410//
411// chatID is where to send it, action should be set via Chat constants.
412func NewChatAction(chatID int64, action string) ChatActionConfig {
413 return ChatActionConfig{
414 BaseChat: BaseChat{ChatID: chatID},
415 Action: action,
416 }
417}
418
419// NewUserProfilePhotos gets user profile photos.
420//
421// userID is the ID of the user you wish to get profile photos from.
422func NewUserProfilePhotos(userID int) UserProfilePhotosConfig {
423 return UserProfilePhotosConfig{
424 UserID: userID,
425 Offset: 0,
426 Limit: 0,
427 }
428}
429
430// NewUpdate gets updates since the last Offset.
431//
432// offset is the last Update ID to include.
433// You likely want to set this to the last Update ID plus 1.
434func NewUpdate(offset int) UpdateConfig {
435 return UpdateConfig{
436 Offset: offset,
437 Limit: 0,
438 Timeout: 0,
439 }
440}
441
442// NewWebhook creates a new webhook.
443//
444// link is the url parsable link you wish to get the updates.
445func NewWebhook(link string) WebhookConfig {
446 u, _ := url.Parse(link)
447
448 return WebhookConfig{
449 URL: u,
450 }
451}
452
453// NewWebhookWithCert creates a new webhook with a certificate.
454//
455// link is the url you wish to get webhooks,
456// file contains a string to a file, FileReader, or FileBytes.
457func NewWebhookWithCert(link string, file interface{}) WebhookConfig {
458 u, _ := url.Parse(link)
459
460 return WebhookConfig{
461 URL: u,
462 Certificate: file,
463 }
464}
465
466// NewInlineQueryResultArticle creates a new inline query article.
467func NewInlineQueryResultArticle(id, title, messageText string) InlineQueryResultArticle {
468 return InlineQueryResultArticle{
469 Type: "article",
470 ID: id,
471 Title: title,
472 InputMessageContent: InputTextMessageContent{
473 Text: messageText,
474 },
475 }
476}
477
478// NewInlineQueryResultArticleMarkdown creates a new inline query article with Markdown parsing.
479func NewInlineQueryResultArticleMarkdown(id, title, messageText string) InlineQueryResultArticle {
480 return InlineQueryResultArticle{
481 Type: "article",
482 ID: id,
483 Title: title,
484 InputMessageContent: InputTextMessageContent{
485 Text: messageText,
486 ParseMode: "Markdown",
487 },
488 }
489}
490
491// NewInlineQueryResultArticleMarkdownV2 creates a new inline query article with MarkdownV2 parsing.
492func NewInlineQueryResultArticleMarkdownV2(id, title, messageText string) InlineQueryResultArticle {
493 return InlineQueryResultArticle{
494 Type: "article",
495 ID: id,
496 Title: title,
497 InputMessageContent: InputTextMessageContent{
498 Text: messageText,
499 ParseMode: "MarkdownV2",
500 },
501 }
502}
503
504// NewInlineQueryResultArticleHTML creates a new inline query article with HTML parsing.
505func NewInlineQueryResultArticleHTML(id, title, messageText string) InlineQueryResultArticle {
506 return InlineQueryResultArticle{
507 Type: "article",
508 ID: id,
509 Title: title,
510 InputMessageContent: InputTextMessageContent{
511 Text: messageText,
512 ParseMode: "HTML",
513 },
514 }
515}
516
517// NewInlineQueryResultGIF creates a new inline query GIF.
518func NewInlineQueryResultGIF(id, url string) InlineQueryResultGIF {
519 return InlineQueryResultGIF{
520 Type: "gif",
521 ID: id,
522 URL: url,
523 }
524}
525
526// NewInlineQueryResultCachedGIF create a new inline query with cached photo.
527func NewInlineQueryResultCachedGIF(id, gifID string) InlineQueryResultCachedGIF {
528 return InlineQueryResultCachedGIF{
529 Type: "gif",
530 ID: id,
531 GIFID: gifID,
532 }
533}
534
535// NewInlineQueryResultMPEG4GIF creates a new inline query MPEG4 GIF.
536func NewInlineQueryResultMPEG4GIF(id, url string) InlineQueryResultMPEG4GIF {
537 return InlineQueryResultMPEG4GIF{
538 Type: "mpeg4_gif",
539 ID: id,
540 URL: url,
541 }
542}
543
544// NewInlineQueryResultCachedMPEG4GIF create a new inline query with cached MPEG4 GIF.
545func NewInlineQueryResultCachedMPEG4GIF(id, MPEG4GIFID string) InlineQueryResultCachedMPEG4GIF {
546 return InlineQueryResultCachedMPEG4GIF{
547 Type: "mpeg4_gif",
548 ID: id,
549 MPEG4FileID: MPEG4GIFID,
550 }
551}
552
553// NewInlineQueryResultPhoto creates a new inline query photo.
554func NewInlineQueryResultPhoto(id, url string) InlineQueryResultPhoto {
555 return InlineQueryResultPhoto{
556 Type: "photo",
557 ID: id,
558 URL: url,
559 }
560}
561
562// NewInlineQueryResultPhotoWithThumb creates a new inline query photo.
563func NewInlineQueryResultPhotoWithThumb(id, url, thumb string) InlineQueryResultPhoto {
564 return InlineQueryResultPhoto{
565 Type: "photo",
566 ID: id,
567 URL: url,
568 ThumbURL: thumb,
569 }
570}
571
572// NewInlineQueryResultCachedPhoto create a new inline query with cached photo.
573func NewInlineQueryResultCachedPhoto(id, photoID string) InlineQueryResultCachedPhoto {
574 return InlineQueryResultCachedPhoto{
575 Type: "photo",
576 ID: id,
577 PhotoID: photoID,
578 }
579}
580
581// NewInlineQueryResultVideo creates a new inline query video.
582func NewInlineQueryResultVideo(id, url string) InlineQueryResultVideo {
583 return InlineQueryResultVideo{
584 Type: "video",
585 ID: id,
586 URL: url,
587 }
588}
589
590// NewInlineQueryResultCachedVideo create a new inline query with cached video.
591func NewInlineQueryResultCachedVideo(id, videoID, title string) InlineQueryResultCachedVideo {
592 return InlineQueryResultCachedVideo{
593 Type: "video",
594 ID: id,
595 VideoID: videoID,
596 Title: title,
597 }
598}
599
600// NewInlineQueryResultCachedSticker create a new inline query with cached sticker.
601func NewInlineQueryResultCachedSticker(id, stickerID, title string) InlineQueryResultCachedSticker {
602 return InlineQueryResultCachedSticker{
603 Type: "sticker",
604 ID: id,
605 StickerID: stickerID,
606 Title: title,
607 }
608}
609
610// NewInlineQueryResultAudio creates a new inline query audio.
611func NewInlineQueryResultAudio(id, url, title string) InlineQueryResultAudio {
612 return InlineQueryResultAudio{
613 Type: "audio",
614 ID: id,
615 URL: url,
616 Title: title,
617 }
618}
619
620// NewInlineQueryResultCachedAudio create a new inline query with cached photo.
621func NewInlineQueryResultCachedAudio(id, audioID string) InlineQueryResultCachedAudio {
622 return InlineQueryResultCachedAudio{
623 Type: "audio",
624 ID: id,
625 AudioID: audioID,
626 }
627}
628
629// NewInlineQueryResultVoice creates a new inline query voice.
630func NewInlineQueryResultVoice(id, url, title string) InlineQueryResultVoice {
631 return InlineQueryResultVoice{
632 Type: "voice",
633 ID: id,
634 URL: url,
635 Title: title,
636 }
637}
638
639// NewInlineQueryResultCachedVoice create a new inline query with cached photo.
640func NewInlineQueryResultCachedVoice(id, voiceID, title string) InlineQueryResultCachedVoice {
641 return InlineQueryResultCachedVoice{
642 Type: "voice",
643 ID: id,
644 VoiceID: voiceID,
645 Title: title,
646 }
647}
648
649// NewInlineQueryResultDocument creates a new inline query document.
650func NewInlineQueryResultDocument(id, url, title, mimeType string) InlineQueryResultDocument {
651 return InlineQueryResultDocument{
652 Type: "document",
653 ID: id,
654 URL: url,
655 Title: title,
656 MimeType: mimeType,
657 }
658}
659
660// NewInlineQueryResultCachedDocument create a new inline query with cached photo.
661func NewInlineQueryResultCachedDocument(id, documentID, title string) InlineQueryResultCachedDocument {
662 return InlineQueryResultCachedDocument{
663 Type: "document",
664 ID: id,
665 DocumentID: documentID,
666 Title: title,
667 }
668}
669
670// NewInlineQueryResultLocation creates a new inline query location.
671func NewInlineQueryResultLocation(id, title string, latitude, longitude float64) InlineQueryResultLocation {
672 return InlineQueryResultLocation{
673 Type: "location",
674 ID: id,
675 Title: title,
676 Latitude: latitude,
677 Longitude: longitude,
678 }
679}
680
681// NewInlineQueryResultVenue creates a new inline query venue.
682func NewInlineQueryResultVenue(id, title, address string, latitude, longitude float64) InlineQueryResultVenue {
683 return InlineQueryResultVenue{
684 Type: "venue",
685 ID: id,
686 Title: title,
687 Address: address,
688 Latitude: latitude,
689 Longitude: longitude,
690 }
691}
692
693// NewEditMessageText allows you to edit the text of a message.
694func NewEditMessageText(chatID int64, messageID int, text string) EditMessageTextConfig {
695 return EditMessageTextConfig{
696 BaseEdit: BaseEdit{
697 ChatID: chatID,
698 MessageID: messageID,
699 },
700 Text: text,
701 }
702}
703
704// NewEditMessageTextAndMarkup allows you to edit the text and replymarkup of a message.
705func NewEditMessageTextAndMarkup(chatID int64, messageID int, text string, replyMarkup InlineKeyboardMarkup) EditMessageTextConfig {
706 return EditMessageTextConfig{
707 BaseEdit: BaseEdit{
708 ChatID: chatID,
709 MessageID: messageID,
710 ReplyMarkup: &replyMarkup,
711 },
712 Text: text,
713 }
714}
715
716// NewEditMessageCaption allows you to edit the caption of a message.
717func NewEditMessageCaption(chatID int64, messageID int, caption string) EditMessageCaptionConfig {
718 return EditMessageCaptionConfig{
719 BaseEdit: BaseEdit{
720 ChatID: chatID,
721 MessageID: messageID,
722 },
723 Caption: caption,
724 }
725}
726
727// NewEditMessageReplyMarkup allows you to edit the inline
728// keyboard markup.
729func NewEditMessageReplyMarkup(chatID int64, messageID int, replyMarkup InlineKeyboardMarkup) EditMessageReplyMarkupConfig {
730 return EditMessageReplyMarkupConfig{
731 BaseEdit: BaseEdit{
732 ChatID: chatID,
733 MessageID: messageID,
734 ReplyMarkup: &replyMarkup,
735 },
736 }
737}
738
739// NewRemoveKeyboard hides the keyboard, with the option for being selective
740// or hiding for everyone.
741func NewRemoveKeyboard(selective bool) ReplyKeyboardRemove {
742 return ReplyKeyboardRemove{
743 RemoveKeyboard: true,
744 Selective: selective,
745 }
746}
747
748// NewKeyboardButton creates a regular keyboard button.
749func NewKeyboardButton(text string) KeyboardButton {
750 return KeyboardButton{
751 Text: text,
752 }
753}
754
755// NewKeyboardButtonContact creates a keyboard button that requests
756// user contact information upon click.
757func NewKeyboardButtonContact(text string) KeyboardButton {
758 return KeyboardButton{
759 Text: text,
760 RequestContact: true,
761 }
762}
763
764// NewKeyboardButtonLocation creates a keyboard button that requests
765// user location information upon click.
766func NewKeyboardButtonLocation(text string) KeyboardButton {
767 return KeyboardButton{
768 Text: text,
769 RequestLocation: true,
770 }
771}
772
773// NewKeyboardButtonRow creates a row of keyboard buttons.
774func NewKeyboardButtonRow(buttons ...KeyboardButton) []KeyboardButton {
775 var row []KeyboardButton
776
777 row = append(row, buttons...)
778
779 return row
780}
781
782// NewReplyKeyboard creates a new regular keyboard with sane defaults.
783func NewReplyKeyboard(rows ...[]KeyboardButton) ReplyKeyboardMarkup {
784 var keyboard [][]KeyboardButton
785
786 keyboard = append(keyboard, rows...)
787
788 return ReplyKeyboardMarkup{
789 ResizeKeyboard: true,
790 Keyboard: keyboard,
791 }
792}
793
794// NewOneTimeReplyKeyboard creates a new one time keyboard.
795func NewOneTimeReplyKeyboard(rows ...[]KeyboardButton) ReplyKeyboardMarkup {
796 markup := NewReplyKeyboard(rows...)
797 markup.OneTimeKeyboard = true
798 return markup
799}
800
801// NewInlineKeyboardButtonData creates an inline keyboard button with text
802// and data for a callback.
803func NewInlineKeyboardButtonData(text, data string) InlineKeyboardButton {
804 return InlineKeyboardButton{
805 Text: text,
806 CallbackData: &data,
807 }
808}
809
810// NewInlineKeyboardButtonURL creates an inline keyboard button with text
811// which goes to a URL.
812func NewInlineKeyboardButtonURL(text, url string) InlineKeyboardButton {
813 return InlineKeyboardButton{
814 Text: text,
815 URL: &url,
816 }
817}
818
819// NewInlineKeyboardButtonSwitch creates an inline keyboard button with
820// text which allows the user to switch to a chat or return to a chat.
821func NewInlineKeyboardButtonSwitch(text, sw string) InlineKeyboardButton {
822 return InlineKeyboardButton{
823 Text: text,
824 SwitchInlineQuery: &sw,
825 }
826}
827
828// NewInlineKeyboardRow creates an inline keyboard row with buttons.
829func NewInlineKeyboardRow(buttons ...InlineKeyboardButton) []InlineKeyboardButton {
830 var row []InlineKeyboardButton
831
832 row = append(row, buttons...)
833
834 return row
835}
836
837// NewInlineKeyboardMarkup creates a new inline keyboard.
838func NewInlineKeyboardMarkup(rows ...[]InlineKeyboardButton) InlineKeyboardMarkup {
839 var keyboard [][]InlineKeyboardButton
840
841 keyboard = append(keyboard, rows...)
842
843 return InlineKeyboardMarkup{
844 InlineKeyboard: keyboard,
845 }
846}
847
848// NewCallback creates a new callback message.
849func NewCallback(id, text string) CallbackConfig {
850 return CallbackConfig{
851 CallbackQueryID: id,
852 Text: text,
853 ShowAlert: false,
854 }
855}
856
857// NewCallbackWithAlert creates a new callback message that alerts
858// the user.
859func NewCallbackWithAlert(id, text string) CallbackConfig {
860 return CallbackConfig{
861 CallbackQueryID: id,
862 Text: text,
863 ShowAlert: true,
864 }
865}
866
867// NewInvoice creates a new Invoice request to the user.
868func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices []LabeledPrice) InvoiceConfig {
869 return InvoiceConfig{
870 BaseChat: BaseChat{ChatID: chatID},
871 Title: title,
872 Description: description,
873 Payload: payload,
874 ProviderToken: providerToken,
875 StartParameter: startParameter,
876 Currency: currency,
877 Prices: prices}
878}
879
880// NewSetChatPhotoUpload creates a new chat photo uploader.
881//
882// chatID is where to send it, file is a string path to the file,
883// FileReader, or FileBytes.
884//
885// Note that you must send animated GIFs as a document.
886func NewSetChatPhotoUpload(chatID int64, file interface{}) SetChatPhotoConfig {
887 return SetChatPhotoConfig{
888 BaseFile: BaseFile{
889 BaseChat: BaseChat{ChatID: chatID},
890 File: file,
891 UseExisting: false,
892 },
893 }
894}
895
896// NewSetChatPhotoShare shares an existing photo.
897// You may use this to reshare an existing photo without reuploading it.
898//
899// chatID is where to send it, fileID is the ID of the file
900// already uploaded.
901func NewSetChatPhotoShare(chatID int64, fileID string) SetChatPhotoConfig {
902 return SetChatPhotoConfig{
903 BaseFile: BaseFile{
904 BaseChat: BaseChat{ChatID: chatID},
905 FileID: fileID,
906 UseExisting: true,
907 },
908 }
909}
910
911// NewChatTitle allows you to update the title of a chat.
912func NewChatTitle(chatID int64, title string) SetChatTitleConfig {
913 return SetChatTitleConfig{
914 ChatID: chatID,
915 Title: title,
916 }
917}
918
919// NewChatDescription allows you to update the description of a chat.
920func NewChatDescription(chatID int64, description string) SetChatDescriptionConfig {
921 return SetChatDescriptionConfig{
922 ChatID: chatID,
923 Description: description,
924 }
925}
926
927// NewChatPhoto allows you to update the photo for a chat.
928func NewChatPhoto(chatID int64, photo interface{}) SetChatPhotoConfig {
929 return SetChatPhotoConfig{
930 BaseFile: BaseFile{
931 BaseChat: BaseChat{
932 ChatID: chatID,
933 },
934 File: photo,
935 },
936 }
937}
938
939// NewDeleteChatPhoto allows you to delete the photo for a chat.
940func NewDeleteChatPhoto(chatID int64, photo interface{}) DeleteChatPhotoConfig {
941 return DeleteChatPhotoConfig{
942 ChatID: chatID,
943 }
944}
945
946// NewPoll allows you to create a new poll.
947func NewPoll(chatID int64, question string, options ...string) SendPollConfig {
948 return SendPollConfig{
949 BaseChat: BaseChat{
950 ChatID: chatID,
951 },
952 Question: question,
953 Options: options,
954 IsAnonymous: true, // This is Telegram's default.
955 }
956}
957
958// NewStopPoll allows you to stop a poll.
959func NewStopPoll(chatID int64, messageID int) StopPollConfig {
960 return StopPollConfig{
961 BaseEdit{
962 ChatID: chatID,
963 MessageID: messageID,
964 },
965 }
966}
967
968// NewSendDice allows you to send a random dice roll.
969//
970// Deprecated: Use NewDice instead.
971func NewSendDice(chatID int64) DiceConfig {
972 return NewDice(chatID)
973}
974
975// NewDice allows you to send a random dice roll.
976func NewDice(chatID int64) DiceConfig {
977 return DiceConfig{
978 BaseChat: BaseChat{
979 ChatID: chatID,
980 },
981 }
982}
983
984// NewDiceWithEmoji allows you to send a random roll of one of many types.
985//
986// Emoji may be 🎲 (1-6), 🎯 (1-6), or 🏀 (1-5).
987func NewDiceWithEmoji(chatID int64, emoji string) DiceConfig {
988 return DiceConfig{
989 BaseChat: BaseChat{
990 ChatID: chatID,
991 },
992 Emoji: emoji,
993 }
994}
995
996// NewSetMyCommands allows you to set the registered commands.
997func NewSetMyCommands(commands ...BotCommand) SetMyCommandsConfig {
998 return SetMyCommandsConfig{commands: commands}
999}