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