all repos — telegram-bot-api @ 4f6c0f14db51526d7cb0e368c2e1ffe05ab19a45

Golang bindings for the Telegram Bot API

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