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