all repos — telegram-bot-api @ 5ce2767dadc468aaf629a3119d806f33d68e10ef

Golang bindings for the Telegram Bot API

configs.go (view raw)

   1package tgbotapi
   2
   3import (
   4	"io"
   5	"net/url"
   6)
   7
   8// Telegram constants
   9const (
  10	// APIEndpoint is the endpoint for all API methods,
  11	// with formatting for Sprintf.
  12	APIEndpoint = "https://api.telegram.org/bot%s/%s"
  13	// FileEndpoint is the endpoint for downloading a file from Telegram.
  14	FileEndpoint = "https://api.telegram.org/file/bot%s/%s"
  15)
  16
  17// Constant values for ChatActions
  18const (
  19	ChatTyping         = "typing"
  20	ChatUploadPhoto    = "upload_photo"
  21	ChatRecordVideo    = "record_video"
  22	ChatUploadVideo    = "upload_video"
  23	ChatRecordAudio    = "record_audio"
  24	ChatUploadAudio    = "upload_audio"
  25	ChatUploadDocument = "upload_document"
  26	ChatFindLocation   = "find_location"
  27)
  28
  29// API errors
  30const (
  31	// ErrAPIForbidden happens when a token is bad
  32	ErrAPIForbidden = "forbidden"
  33)
  34
  35// Constant values for ParseMode in MessageConfig
  36const (
  37	ModeMarkdown   = "Markdown"
  38	ModeMarkdownV2 = "MarkdownV2"
  39	ModeHTML       = "HTML"
  40)
  41
  42// Library errors
  43const (
  44	// ErrBadFileType happens when you pass an unknown type
  45	ErrBadFileType = "bad file type"
  46	ErrBadURL      = "bad or empty url"
  47)
  48
  49// Chattable is any config type that can be sent.
  50type Chattable interface {
  51	params() (Params, error)
  52	method() string
  53}
  54
  55// Fileable is any config type that can be sent that includes a file.
  56type Fileable interface {
  57	Chattable
  58	name() string
  59	getFile() interface{}
  60	useExistingFile() bool
  61}
  62
  63// BaseChat is base type for all chat config types.
  64type BaseChat struct {
  65	ChatID              int64 // required
  66	ChannelUsername     string
  67	ReplyToMessageID    int
  68	ReplyMarkup         interface{}
  69	DisableNotification bool
  70}
  71
  72func (chat *BaseChat) params() (Params, error) {
  73	params := make(Params)
  74
  75	params.AddFirstValid("chat_id", chat.ChatID, chat.ChannelUsername)
  76	params.AddNonZero("reply_to_message_id", chat.ReplyToMessageID)
  77	params.AddBool("disable_notification", chat.DisableNotification)
  78
  79	err := params.AddInterface("reply_markup", chat.ReplyMarkup)
  80
  81	return params, err
  82}
  83
  84// BaseFile is a base type for all file config types.
  85type BaseFile struct {
  86	BaseChat
  87	File        interface{}
  88	FileID      string
  89	UseExisting bool
  90	MimeType    string
  91	FileSize    int
  92}
  93
  94func (file BaseFile) params() (Params, error) {
  95	params, err := file.BaseChat.params()
  96
  97	params.AddNonEmpty("mime_type", file.MimeType)
  98	params.AddNonZero("file_size", file.FileSize)
  99
 100	return params, err
 101}
 102
 103func (file BaseFile) getFile() interface{} {
 104	return file.File
 105}
 106
 107func (file BaseFile) useExistingFile() bool {
 108	return file.UseExisting
 109}
 110
 111// BaseEdit is base type of all chat edits.
 112type BaseEdit struct {
 113	ChatID          int64
 114	ChannelUsername string
 115	MessageID       int
 116	InlineMessageID string
 117	ReplyMarkup     *InlineKeyboardMarkup
 118}
 119
 120func (edit BaseEdit) params() (Params, error) {
 121	params := make(Params)
 122
 123	if edit.InlineMessageID != "" {
 124		params["inline_message_id"] = edit.InlineMessageID
 125	} else {
 126		params.AddFirstValid("chat_id", edit.ChatID, edit.ChannelUsername)
 127		params.AddNonZero("message_id", edit.MessageID)
 128	}
 129
 130	err := params.AddInterface("reply_markup", edit.ReplyMarkup)
 131
 132	return params, err
 133}
 134
 135// MessageConfig contains information about a SendMessage request.
 136type MessageConfig struct {
 137	BaseChat
 138	Text                  string
 139	ParseMode             string
 140	DisableWebPagePreview bool
 141}
 142
 143func (config MessageConfig) params() (Params, error) {
 144	params, err := config.BaseChat.params()
 145	if err != nil {
 146		return params, err
 147	}
 148
 149	params.AddNonEmpty("text", config.Text)
 150	params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
 151	params.AddNonEmpty("parse_mode", config.ParseMode)
 152
 153	return params, nil
 154}
 155
 156func (config MessageConfig) method() string {
 157	return "sendMessage"
 158}
 159
 160// ForwardConfig contains information about a ForwardMessage request.
 161type ForwardConfig struct {
 162	BaseChat
 163	FromChatID          int64 // required
 164	FromChannelUsername string
 165	MessageID           int // required
 166}
 167
 168func (config ForwardConfig) params() (Params, error) {
 169	params, err := config.BaseChat.params()
 170	if err != nil {
 171		return params, err
 172	}
 173
 174	params.AddNonZero64("from_chat_id", config.FromChatID)
 175	params.AddNonZero("message_id", config.MessageID)
 176
 177	return params, nil
 178}
 179
 180func (config ForwardConfig) method() string {
 181	return "forwardMessage"
 182}
 183
 184// PhotoConfig contains information about a SendPhoto request.
 185type PhotoConfig struct {
 186	BaseFile
 187	Caption   string
 188	ParseMode string
 189}
 190
 191func (config PhotoConfig) params() (Params, error) {
 192	params, err := config.BaseFile.params()
 193
 194	params.AddNonEmpty(config.name(), config.FileID)
 195	params.AddNonEmpty("caption", config.Caption)
 196	params.AddNonEmpty("parse_mode", config.ParseMode)
 197
 198	return params, err
 199}
 200
 201func (config PhotoConfig) name() string {
 202	return "photo"
 203}
 204
 205func (config PhotoConfig) method() string {
 206	return "sendPhoto"
 207}
 208
 209// AudioConfig contains information about a SendAudio request.
 210type AudioConfig struct {
 211	BaseFile
 212	Caption   string
 213	ParseMode string
 214	Duration  int
 215	Performer string
 216	Title     string
 217}
 218
 219func (config AudioConfig) params() (Params, error) {
 220	params, err := config.BaseChat.params()
 221	if err != nil {
 222		return params, err
 223	}
 224
 225	params.AddNonEmpty(config.name(), config.FileID)
 226	params.AddNonZero("duration", config.Duration)
 227	params.AddNonEmpty("performer", config.Performer)
 228	params.AddNonEmpty("title", config.Title)
 229	params.AddNonEmpty("caption", config.Caption)
 230	params.AddNonEmpty("parse_mode", config.ParseMode)
 231
 232	return params, nil
 233}
 234
 235func (config AudioConfig) name() string {
 236	return "audio"
 237}
 238
 239func (config AudioConfig) method() string {
 240	return "sendAudio"
 241}
 242
 243// DocumentConfig contains information about a SendDocument request.
 244type DocumentConfig struct {
 245	BaseFile
 246	Caption   string
 247	ParseMode string
 248}
 249
 250func (config DocumentConfig) params() (Params, error) {
 251	params, err := config.BaseFile.params()
 252
 253	params.AddNonEmpty(config.name(), config.FileID)
 254	params.AddNonEmpty("caption", config.Caption)
 255	params.AddNonEmpty("parse_mode", config.ParseMode)
 256
 257	return params, err
 258}
 259
 260func (config DocumentConfig) name() string {
 261	return "document"
 262}
 263
 264func (config DocumentConfig) method() string {
 265	return "sendDocument"
 266}
 267
 268// StickerConfig contains information about a SendSticker request.
 269type StickerConfig struct {
 270	BaseFile
 271}
 272
 273func (config StickerConfig) params() (Params, error) {
 274	params, err := config.BaseChat.params()
 275
 276	params.AddNonEmpty(config.name(), config.FileID)
 277
 278	return params, err
 279}
 280
 281func (config StickerConfig) name() string {
 282	return "sticker"
 283}
 284
 285func (config StickerConfig) method() string {
 286	return "sendSticker"
 287}
 288
 289// VideoConfig contains information about a SendVideo request.
 290type VideoConfig struct {
 291	BaseFile
 292	Duration          int
 293	Caption           string
 294	ParseMode         string
 295	SupportsStreaming bool
 296}
 297
 298func (config VideoConfig) params() (Params, error) {
 299	params, err := config.BaseChat.params()
 300
 301	params.AddNonEmpty(config.name(), config.FileID)
 302	params.AddNonZero("duration", config.Duration)
 303	params.AddNonEmpty("caption", config.Caption)
 304	params.AddNonEmpty("parse_mode", config.ParseMode)
 305	params.AddBool("supports_streaming", config.SupportsStreaming)
 306
 307	return params, err
 308}
 309
 310func (config VideoConfig) name() string {
 311	return "video"
 312}
 313
 314func (config VideoConfig) method() string {
 315	return "sendVideo"
 316}
 317
 318// AnimationConfig contains information about a SendAnimation request.
 319type AnimationConfig struct {
 320	BaseFile
 321	Duration  int
 322	Caption   string
 323	ParseMode string
 324}
 325
 326func (config AnimationConfig) params() (Params, error) {
 327	params, err := config.BaseChat.params()
 328
 329	params.AddNonEmpty(config.name(), config.FileID)
 330	params.AddNonZero("duration", config.Duration)
 331	params.AddNonEmpty("caption", config.Caption)
 332	params.AddNonEmpty("parse_mode", config.ParseMode)
 333
 334	return params, err
 335}
 336
 337func (config AnimationConfig) name() string {
 338	return "animation"
 339}
 340
 341func (config AnimationConfig) method() string {
 342	return "sendAnimation"
 343}
 344
 345// VideoNoteConfig contains information about a SendVideoNote request.
 346type VideoNoteConfig struct {
 347	BaseFile
 348	Duration int
 349	Length   int
 350}
 351
 352func (config VideoNoteConfig) params() (Params, error) {
 353	params, err := config.BaseChat.params()
 354
 355	params.AddNonEmpty(config.name(), config.FileID)
 356	params.AddNonZero("duration", config.Duration)
 357	params.AddNonZero("length", config.Length)
 358
 359	return params, err
 360}
 361
 362func (config VideoNoteConfig) name() string {
 363	return "video_note"
 364}
 365
 366func (config VideoNoteConfig) method() string {
 367	return "sendVideoNote"
 368}
 369
 370// VoiceConfig contains information about a SendVoice request.
 371type VoiceConfig struct {
 372	BaseFile
 373	Caption   string
 374	ParseMode string
 375	Duration  int
 376}
 377
 378func (config VoiceConfig) params() (Params, error) {
 379	params, err := config.BaseChat.params()
 380
 381	params.AddNonEmpty(config.name(), config.FileID)
 382	params.AddNonZero("duration", config.Duration)
 383	params.AddNonEmpty("caption", config.Caption)
 384	params.AddNonEmpty("parse_mode", config.ParseMode)
 385
 386	return params, err
 387}
 388
 389func (config VoiceConfig) name() string {
 390	return "voice"
 391}
 392
 393func (config VoiceConfig) method() string {
 394	return "sendVoice"
 395}
 396
 397// LocationConfig contains information about a SendLocation request.
 398type LocationConfig struct {
 399	BaseChat
 400	Latitude   float64 // required
 401	Longitude  float64 // required
 402	LivePeriod int     // optional
 403}
 404
 405func (config LocationConfig) params() (Params, error) {
 406	params, err := config.BaseChat.params()
 407
 408	params.AddNonZeroFloat("latitude", config.Latitude)
 409	params.AddNonZeroFloat("longitude", config.Longitude)
 410	params.AddNonZero("live_period", config.LivePeriod)
 411
 412	return params, err
 413}
 414
 415func (config LocationConfig) method() string {
 416	return "sendLocation"
 417}
 418
 419// EditMessageLiveLocationConfig allows you to update a live location.
 420type EditMessageLiveLocationConfig struct {
 421	BaseEdit
 422	Latitude  float64 // required
 423	Longitude float64 // required
 424}
 425
 426func (config EditMessageLiveLocationConfig) params() (Params, error) {
 427	params, err := config.BaseEdit.params()
 428
 429	params.AddNonZeroFloat("latitude", config.Latitude)
 430	params.AddNonZeroFloat("longitude", config.Longitude)
 431
 432	return params, err
 433}
 434
 435func (config EditMessageLiveLocationConfig) method() string {
 436	return "editMessageLiveLocation"
 437}
 438
 439// StopMessageLiveLocationConfig stops updating a live location.
 440type StopMessageLiveLocationConfig struct {
 441	BaseEdit
 442}
 443
 444func (config StopMessageLiveLocationConfig) params() (Params, error) {
 445	return config.BaseEdit.params()
 446}
 447
 448func (config StopMessageLiveLocationConfig) method() string {
 449	return "stopMessageLiveLocation"
 450}
 451
 452// VenueConfig contains information about a SendVenue request.
 453type VenueConfig struct {
 454	BaseChat
 455	Latitude     float64 // required
 456	Longitude    float64 // required
 457	Title        string  // required
 458	Address      string  // required
 459	FoursquareID string
 460}
 461
 462func (config VenueConfig) params() (Params, error) {
 463	params, err := config.BaseChat.params()
 464
 465	params.AddNonZeroFloat("latitude", config.Latitude)
 466	params.AddNonZeroFloat("longitude", config.Longitude)
 467	params["title"] = config.Title
 468	params["address"] = config.Address
 469	params.AddNonEmpty("foursquare_id", config.FoursquareID)
 470
 471	return params, err
 472}
 473
 474func (config VenueConfig) method() string {
 475	return "sendVenue"
 476}
 477
 478// ContactConfig allows you to send a contact.
 479type ContactConfig struct {
 480	BaseChat
 481	PhoneNumber string
 482	FirstName   string
 483	LastName    string
 484	VCard       string
 485}
 486
 487func (config ContactConfig) params() (Params, error) {
 488	params, err := config.BaseChat.params()
 489
 490	params["phone_number"] = config.PhoneNumber
 491	params["first_name"] = config.FirstName
 492
 493	params.AddNonEmpty("last_name", config.LastName)
 494	params.AddNonEmpty("vcard", config.VCard)
 495
 496	return params, err
 497}
 498
 499func (config ContactConfig) method() string {
 500	return "sendContact"
 501}
 502
 503// SendPollConfig allows you to send a poll.
 504type SendPollConfig struct {
 505	BaseChat
 506	Question string
 507	Options  []string
 508}
 509
 510func (config SendPollConfig) params() (Params, error) {
 511	params, err := config.BaseChat.params()
 512	if err != nil {
 513		return params, err
 514	}
 515
 516	params["question"] = config.Question
 517	err = params.AddInterface("options", config.Options)
 518
 519	return params, err
 520}
 521
 522func (SendPollConfig) method() string {
 523	return "sendPoll"
 524}
 525
 526// GameConfig allows you to send a game.
 527type GameConfig struct {
 528	BaseChat
 529	GameShortName string
 530}
 531
 532func (config GameConfig) params() (Params, error) {
 533	params, err := config.BaseChat.params()
 534
 535	params["game_short_name"] = config.GameShortName
 536
 537	return params, err
 538}
 539
 540func (config GameConfig) method() string {
 541	return "sendGame"
 542}
 543
 544// SetGameScoreConfig allows you to update the game score in a chat.
 545type SetGameScoreConfig struct {
 546	UserID             int
 547	Score              int
 548	Force              bool
 549	DisableEditMessage bool
 550	ChatID             int64
 551	ChannelUsername    string
 552	MessageID          int
 553	InlineMessageID    string
 554}
 555
 556func (config SetGameScoreConfig) params() (Params, error) {
 557	params := make(Params)
 558
 559	params.AddNonZero("user_id", config.UserID)
 560	params.AddNonZero("scrore", config.Score)
 561	params.AddBool("disable_edit_message", config.DisableEditMessage)
 562
 563	if config.InlineMessageID != "" {
 564		params["inline_message_id"] = config.InlineMessageID
 565	} else {
 566		params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
 567		params.AddNonZero("message_id", config.MessageID)
 568	}
 569
 570	return params, nil
 571}
 572
 573func (config SetGameScoreConfig) method() string {
 574	return "setGameScore"
 575}
 576
 577// GetGameHighScoresConfig allows you to fetch the high scores for a game.
 578type GetGameHighScoresConfig struct {
 579	UserID          int
 580	ChatID          int
 581	ChannelUsername string
 582	MessageID       int
 583	InlineMessageID string
 584}
 585
 586func (config GetGameHighScoresConfig) params() (Params, error) {
 587	params := make(Params)
 588
 589	params.AddNonZero("user_id", config.UserID)
 590
 591	if config.InlineMessageID != "" {
 592		params["inline_message_id"] = config.InlineMessageID
 593	} else {
 594		params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
 595		params.AddNonZero("message_id", config.MessageID)
 596	}
 597
 598	return params, nil
 599}
 600
 601func (config GetGameHighScoresConfig) method() string {
 602	return "getGameHighScores"
 603}
 604
 605// ChatActionConfig contains information about a SendChatAction request.
 606type ChatActionConfig struct {
 607	BaseChat
 608	Action string // required
 609}
 610
 611func (config ChatActionConfig) params() (Params, error) {
 612	params, err := config.BaseChat.params()
 613
 614	params["action"] = config.Action
 615
 616	return params, err
 617}
 618
 619func (config ChatActionConfig) method() string {
 620	return "sendChatAction"
 621}
 622
 623// EditMessageTextConfig allows you to modify the text in a message.
 624type EditMessageTextConfig struct {
 625	BaseEdit
 626	Text                  string
 627	ParseMode             string
 628	DisableWebPagePreview bool
 629}
 630
 631func (config EditMessageTextConfig) params() (Params, error) {
 632	params, err := config.BaseEdit.params()
 633
 634	params["text"] = config.Text
 635	params.AddNonEmpty("parse_mode", config.ParseMode)
 636	params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
 637
 638	return params, err
 639}
 640
 641func (config EditMessageTextConfig) method() string {
 642	return "editMessageText"
 643}
 644
 645// EditMessageCaptionConfig allows you to modify the caption of a message.
 646type EditMessageCaptionConfig struct {
 647	BaseEdit
 648	Caption   string
 649	ParseMode string
 650}
 651
 652func (config EditMessageCaptionConfig) params() (Params, error) {
 653	params, err := config.BaseEdit.params()
 654
 655	params["caption"] = config.Caption
 656	params.AddNonEmpty("parse_mode", config.ParseMode)
 657
 658	return params, err
 659}
 660
 661func (config EditMessageCaptionConfig) method() string {
 662	return "editMessageCaption"
 663}
 664
 665// EditMessageMediaConfig contains information about editing a message's media.
 666type EditMessageMediaConfig struct {
 667	BaseEdit
 668
 669	Media interface{}
 670}
 671
 672func (EditMessageMediaConfig) method() string {
 673	return "editMessageMedia"
 674}
 675
 676func (config EditMessageMediaConfig) params() (Params, error) {
 677	params, err := config.BaseEdit.params()
 678
 679	params.AddInterface("media", config.Media)
 680
 681	return params, err
 682}
 683
 684// EditMessageReplyMarkupConfig allows you to modify the reply markup
 685// of a message.
 686type EditMessageReplyMarkupConfig struct {
 687	BaseEdit
 688}
 689
 690func (config EditMessageReplyMarkupConfig) params() (Params, error) {
 691	return config.BaseEdit.params()
 692}
 693
 694func (config EditMessageReplyMarkupConfig) method() string {
 695	return "editMessageReplyMarkup"
 696}
 697
 698// StopPollConfig allows you to stop a poll sent by the bot.
 699type StopPollConfig struct {
 700	BaseEdit
 701}
 702
 703func (config StopPollConfig) params() (Params, error) {
 704	return config.BaseEdit.params()
 705}
 706
 707func (StopPollConfig) method() string {
 708	return "stopPoll"
 709}
 710
 711// UserProfilePhotosConfig contains information about a
 712// GetUserProfilePhotos request.
 713type UserProfilePhotosConfig struct {
 714	UserID int
 715	Offset int
 716	Limit  int
 717}
 718
 719func (UserProfilePhotosConfig) method() string {
 720	return "getUserProfilePhotos"
 721}
 722
 723func (config UserProfilePhotosConfig) params() (Params, error) {
 724	params := make(Params)
 725
 726	params.AddNonZero("user_id", config.UserID)
 727	params.AddNonZero("offset", config.Offset)
 728	params.AddNonZero("limit", config.Limit)
 729
 730	return params, nil
 731}
 732
 733// FileConfig has information about a file hosted on Telegram.
 734type FileConfig struct {
 735	FileID string
 736}
 737
 738func (FileConfig) method() string {
 739	return "getFile"
 740}
 741
 742func (config FileConfig) params() (Params, error) {
 743	params := make(Params)
 744
 745	params["file_id"] = config.FileID
 746
 747	return params, nil
 748}
 749
 750// UpdateConfig contains information about a GetUpdates request.
 751type UpdateConfig struct {
 752	Offset  int
 753	Limit   int
 754	Timeout int
 755}
 756
 757func (UpdateConfig) method() string {
 758	return "getUpdates"
 759}
 760
 761func (config UpdateConfig) params() (Params, error) {
 762	params := make(Params)
 763
 764	params.AddNonZero("offset", config.Offset)
 765	params.AddNonZero("limit", config.Limit)
 766	params.AddNonZero("timeout", config.Timeout)
 767
 768	return params, nil
 769}
 770
 771// WebhookConfig contains information about a SetWebhook request.
 772type WebhookConfig struct {
 773	URL            *url.URL
 774	Certificate    interface{}
 775	MaxConnections int
 776	AllowedUpdates []string
 777}
 778
 779func (config WebhookConfig) method() string {
 780	return "setWebhook"
 781}
 782
 783func (config WebhookConfig) params() (Params, error) {
 784	params := make(Params)
 785
 786	if config.URL != nil {
 787		params["url"] = config.URL.String()
 788	}
 789
 790	params.AddNonZero("max_connections", config.MaxConnections)
 791	params.AddInterface("allowed_updates", config.AllowedUpdates)
 792
 793	return params, nil
 794}
 795
 796func (config WebhookConfig) name() string {
 797	return "certificate"
 798}
 799
 800func (config WebhookConfig) getFile() interface{} {
 801	return config.Certificate
 802}
 803
 804func (config WebhookConfig) useExistingFile() bool {
 805	return config.URL != nil
 806}
 807
 808// RemoveWebhookConfig is a helper to remove a webhook.
 809type RemoveWebhookConfig struct {
 810}
 811
 812func (config RemoveWebhookConfig) method() string {
 813	return "setWebhook"
 814}
 815
 816func (config RemoveWebhookConfig) params() (Params, error) {
 817	return nil, nil
 818}
 819
 820// FileBytes contains information about a set of bytes to upload
 821// as a File.
 822type FileBytes struct {
 823	Name  string
 824	Bytes []byte
 825}
 826
 827// FileReader contains information about a reader to upload as a File.
 828// If Size is -1, it will read the entire Reader into memory to
 829// calculate a Size.
 830type FileReader struct {
 831	Name   string
 832	Reader io.Reader
 833	Size   int64
 834}
 835
 836// InlineConfig contains information on making an InlineQuery response.
 837type InlineConfig struct {
 838	InlineQueryID     string        `json:"inline_query_id"`
 839	Results           []interface{} `json:"results"`
 840	CacheTime         int           `json:"cache_time"`
 841	IsPersonal        bool          `json:"is_personal"`
 842	NextOffset        string        `json:"next_offset"`
 843	SwitchPMText      string        `json:"switch_pm_text"`
 844	SwitchPMParameter string        `json:"switch_pm_parameter"`
 845}
 846
 847func (config InlineConfig) method() string {
 848	return "answerInlineQuery"
 849}
 850
 851func (config InlineConfig) params() (Params, error) {
 852	params := make(Params)
 853
 854	params["inline_query_id"] = config.InlineQueryID
 855	params.AddNonZero("cache_time", config.CacheTime)
 856	params.AddBool("is_personal", config.IsPersonal)
 857	params.AddNonEmpty("next_offset", config.NextOffset)
 858	params.AddNonEmpty("switch_pm_text", config.SwitchPMText)
 859	params.AddNonEmpty("switch_pm_parameter", config.SwitchPMParameter)
 860
 861	if err := params.AddInterface("results", config.Results); err != nil {
 862		return params, err
 863	}
 864
 865	return params, nil
 866}
 867
 868// CallbackConfig contains information on making a CallbackQuery response.
 869type CallbackConfig struct {
 870	CallbackQueryID string `json:"callback_query_id"`
 871	Text            string `json:"text"`
 872	ShowAlert       bool   `json:"show_alert"`
 873	URL             string `json:"url"`
 874	CacheTime       int    `json:"cache_time"`
 875}
 876
 877func (config CallbackConfig) method() string {
 878	return "answerCallbackQuery"
 879}
 880
 881func (config CallbackConfig) params() (Params, error) {
 882	params := make(Params)
 883
 884	params["callback_query_id"] = config.CallbackQueryID
 885	params.AddNonEmpty("text", config.Text)
 886	params.AddBool("show_alert", config.ShowAlert)
 887	params.AddNonEmpty("url", config.URL)
 888	params.AddNonZero("cache_time", config.CacheTime)
 889
 890	return params, nil
 891}
 892
 893// ChatMemberConfig contains information about a user in a chat for use
 894// with administrative functions such as kicking or unbanning a user.
 895type ChatMemberConfig struct {
 896	ChatID             int64
 897	SuperGroupUsername string
 898	ChannelUsername    string
 899	UserID             int
 900}
 901
 902// UnbanChatMemberConfig allows you to unban a user.
 903type UnbanChatMemberConfig struct {
 904	ChatMemberConfig
 905}
 906
 907func (config UnbanChatMemberConfig) method() string {
 908	return "unbanChatMember"
 909}
 910
 911func (config UnbanChatMemberConfig) params() (Params, error) {
 912	params := make(Params)
 913
 914	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
 915	params.AddNonZero("user_id", config.UserID)
 916
 917	return params, nil
 918}
 919
 920// KickChatMemberConfig contains extra fields to kick user
 921type KickChatMemberConfig struct {
 922	ChatMemberConfig
 923	UntilDate int64
 924}
 925
 926func (config KickChatMemberConfig) method() string {
 927	return "kickChatMember"
 928}
 929
 930func (config KickChatMemberConfig) params() (Params, error) {
 931	params := make(Params)
 932
 933	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
 934	params.AddNonZero("user_id", config.UserID)
 935	params.AddNonZero64("until_date", config.UntilDate)
 936
 937	return params, nil
 938}
 939
 940// RestrictChatMemberConfig contains fields to restrict members of chat
 941type RestrictChatMemberConfig struct {
 942	ChatMemberConfig
 943	UntilDate   int64
 944	Permissions *ChatPermissions
 945}
 946
 947func (config RestrictChatMemberConfig) method() string {
 948	return "restrictChatMember"
 949}
 950
 951func (config RestrictChatMemberConfig) params() (Params, error) {
 952	params := make(Params)
 953
 954	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
 955	params.AddNonZero("user_id", config.UserID)
 956
 957	if err := params.AddInterface("permissions", config.Permissions); err != nil {
 958		return params, err
 959	}
 960	params.AddNonZero64("until_date", config.UntilDate)
 961
 962	return params, nil
 963}
 964
 965// PromoteChatMemberConfig contains fields to promote members of chat
 966type PromoteChatMemberConfig struct {
 967	ChatMemberConfig
 968	CanChangeInfo      bool
 969	CanPostMessages    bool
 970	CanEditMessages    bool
 971	CanDeleteMessages  bool
 972	CanInviteUsers     bool
 973	CanRestrictMembers bool
 974	CanPinMessages     bool
 975	CanPromoteMembers  bool
 976}
 977
 978func (config PromoteChatMemberConfig) method() string {
 979	return "promoteChatMember"
 980}
 981
 982func (config PromoteChatMemberConfig) params() (Params, error) {
 983	params := make(Params)
 984
 985	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
 986	params.AddNonZero("user_id", config.UserID)
 987
 988	params.AddBool("can_change_info", config.CanChangeInfo)
 989	params.AddBool("can_post_messages", config.CanPostMessages)
 990	params.AddBool("can_edit_messages", config.CanEditMessages)
 991	params.AddBool("can_delete_messages", config.CanDeleteMessages)
 992	params.AddBool("can_invite_users", config.CanInviteUsers)
 993	params.AddBool("can_restrict_members", config.CanRestrictMembers)
 994	params.AddBool("can_pin_messages", config.CanPinMessages)
 995	params.AddBool("can_promote_members", config.CanPromoteMembers)
 996
 997	return params, nil
 998}
 999
1000// SetChatAdministratorCustomTitle sets the title of an administrative user
1001// promoted by the bot for a chat.
1002type SetChatAdministratorCustomTitle struct {
1003	ChatMemberConfig
1004	CustomTitle string
1005}
1006
1007func (SetChatAdministratorCustomTitle) method() string {
1008	return "setChatAdministratorCustomTitle"
1009}
1010
1011func (config SetChatAdministratorCustomTitle) params() (Params, error) {
1012	params := make(Params)
1013
1014	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1015	params.AddNonZero("user_id", config.UserID)
1016	params.AddNonEmpty("custom_title", config.CustomTitle)
1017
1018	return params, nil
1019}
1020
1021// ChatConfig contains information about getting information on a chat.
1022type ChatConfig struct {
1023	ChatID             int64
1024	SuperGroupUsername string
1025}
1026
1027func (config ChatConfig) params() (Params, error) {
1028	params := make(Params)
1029
1030	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1031
1032	return params, nil
1033}
1034
1035// ChatInfoConfig contains information about getting chat information.
1036type ChatInfoConfig struct {
1037	ChatConfig
1038}
1039
1040func (ChatInfoConfig) method() string {
1041	return "getChat"
1042}
1043
1044// ChatMemberCountConfig contains information about getting the number of users in a chat.
1045type ChatMemberCountConfig struct {
1046	ChatConfig
1047}
1048
1049func (ChatMemberCountConfig) method() string {
1050	return "getChatMembersCount"
1051}
1052
1053// ChatAdministratorsConfig contains information about getting chat administrators.
1054type ChatAdministratorsConfig struct {
1055	ChatConfig
1056}
1057
1058func (ChatAdministratorsConfig) method() string {
1059	return "getChatAdministrators"
1060}
1061
1062// SetChatPermissionsConfig allows you to set default permissions for the
1063// members in a group. The bot must be an administrator and have rights to
1064// restrict members.
1065type SetChatPermissionsConfig struct {
1066	ChatConfig
1067	Permissions *ChatPermissions
1068}
1069
1070func (SetChatPermissionsConfig) method() string {
1071	return "setChatPermissions"
1072}
1073
1074func (config SetChatPermissionsConfig) params() (Params, error) {
1075	params := make(Params)
1076
1077	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1078	params.AddInterface("permissions", config.Permissions)
1079
1080	return params, nil
1081}
1082
1083// ChatInviteLinkConfig contains information about getting a chat link.
1084//
1085// Note that generating a new link will revoke any previous links.
1086type ChatInviteLinkConfig struct {
1087	ChatConfig
1088}
1089
1090func (ChatInviteLinkConfig) method() string {
1091	return "exportChatInviteLink"
1092}
1093
1094func (config ChatInviteLinkConfig) params() (Params, error) {
1095	params := make(Params)
1096
1097	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1098
1099	return params, nil
1100}
1101
1102// LeaveChatConfig allows you to leave a chat.
1103type LeaveChatConfig struct {
1104	ChatID          int64
1105	ChannelUsername string
1106}
1107
1108func (config LeaveChatConfig) method() string {
1109	return "leaveChat"
1110}
1111
1112func (config LeaveChatConfig) params() (Params, error) {
1113	params := make(Params)
1114
1115	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1116
1117	return params, nil
1118}
1119
1120// ChatConfigWithUser contains information about a chat and a user.
1121type ChatConfigWithUser struct {
1122	ChatID             int64
1123	SuperGroupUsername string
1124	UserID             int
1125}
1126
1127func (config ChatConfigWithUser) params() (Params, error) {
1128	params := make(Params)
1129
1130	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1131	params.AddNonZero("user_id", config.UserID)
1132
1133	return params, nil
1134}
1135
1136// GetChatMemberConfig is information about getting a specific member in a chat.
1137type GetChatMemberConfig struct {
1138	ChatConfigWithUser
1139}
1140
1141func (GetChatMemberConfig) method() string {
1142	return "getChatMember"
1143}
1144
1145// InvoiceConfig contains information for sendInvoice request.
1146type InvoiceConfig struct {
1147	BaseChat
1148	Title                     string         // required
1149	Description               string         // required
1150	Payload                   string         // required
1151	ProviderToken             string         // required
1152	StartParameter            string         // required
1153	Currency                  string         // required
1154	Prices                    []LabeledPrice // required
1155	ProviderData              string
1156	PhotoURL                  string
1157	PhotoSize                 int
1158	PhotoWidth                int
1159	PhotoHeight               int
1160	NeedName                  bool
1161	NeedPhoneNumber           bool
1162	NeedEmail                 bool
1163	NeedShippingAddress       bool
1164	SendPhoneNumberToProvider bool
1165	SendEmailToProvider       bool
1166	IsFlexible                bool
1167}
1168
1169func (config InvoiceConfig) params() (Params, error) {
1170	params, err := config.BaseChat.params()
1171	if err != nil {
1172		return params, err
1173	}
1174
1175	params["title"] = config.Title
1176	params["description"] = config.Description
1177	params["payload"] = config.Payload
1178	params["provider_token"] = config.ProviderToken
1179	params["start_parameter"] = config.StartParameter
1180	params["currency"] = config.Currency
1181
1182	if err = params.AddInterface("prices", config.Prices); err != nil {
1183		return params, err
1184	}
1185
1186	params.AddNonEmpty("provider_data", config.ProviderData)
1187	params.AddNonEmpty("photo_url", config.PhotoURL)
1188	params.AddNonZero("photo_size", config.PhotoSize)
1189	params.AddNonZero("photo_width", config.PhotoWidth)
1190	params.AddNonZero("photo_height", config.PhotoHeight)
1191	params.AddBool("need_name", config.NeedName)
1192	params.AddBool("need_phone_number", config.NeedPhoneNumber)
1193	params.AddBool("need_email", config.NeedEmail)
1194	params.AddBool("need_shipping_address", config.NeedShippingAddress)
1195	params.AddBool("is_flexible", config.IsFlexible)
1196	params.AddBool("send_phone_number_to_provider", config.SendPhoneNumberToProvider)
1197	params.AddBool("send_email_to_provider", config.SendEmailToProvider)
1198
1199	return params, nil
1200}
1201
1202func (config InvoiceConfig) method() string {
1203	return "sendInvoice"
1204}
1205
1206// ShippingConfig contains information for answerShippingQuery request.
1207type ShippingConfig struct {
1208	ShippingQueryID string // required
1209	OK              bool   // required
1210	ShippingOptions []ShippingOption
1211	ErrorMessage    string
1212}
1213
1214// PreCheckoutConfig conatins information for answerPreCheckoutQuery request.
1215type PreCheckoutConfig struct {
1216	PreCheckoutQueryID string // required
1217	OK                 bool   // required
1218	ErrorMessage       string
1219}
1220
1221// DeleteMessageConfig contains information of a message in a chat to delete.
1222type DeleteMessageConfig struct {
1223	ChatID    int64
1224	MessageID int
1225}
1226
1227func (config DeleteMessageConfig) method() string {
1228	return "deleteMessage"
1229}
1230
1231func (config DeleteMessageConfig) params() (Params, error) {
1232	params := make(Params)
1233
1234	params.AddNonZero64("chat_id", config.ChatID)
1235	params.AddNonZero("message_id", config.MessageID)
1236
1237	return params, nil
1238}
1239
1240// PinChatMessageConfig contains information of a message in a chat to pin.
1241type PinChatMessageConfig struct {
1242	ChatID              int64
1243	ChannelUsername     string
1244	MessageID           int
1245	DisableNotification bool
1246}
1247
1248func (config PinChatMessageConfig) method() string {
1249	return "pinChatMessage"
1250}
1251
1252func (config PinChatMessageConfig) params() (Params, error) {
1253	params := make(Params)
1254
1255	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1256	params.AddNonZero("message_id", config.MessageID)
1257	params.AddBool("disable_notification", config.DisableNotification)
1258
1259	return params, nil
1260}
1261
1262// UnpinChatMessageConfig contains information of chat to unpin.
1263type UnpinChatMessageConfig struct {
1264	ChatID          int64
1265	ChannelUsername string
1266}
1267
1268func (config UnpinChatMessageConfig) method() string {
1269	return "unpinChatMessage"
1270}
1271
1272func (config UnpinChatMessageConfig) params() (Params, error) {
1273	params := make(Params)
1274
1275	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1276
1277	return params, nil
1278}
1279
1280// SetChatPhotoConfig allows you to set a group, supergroup, or channel's photo.
1281type SetChatPhotoConfig struct {
1282	BaseFile
1283}
1284
1285func (config SetChatPhotoConfig) method() string {
1286	return "setChatPhoto"
1287}
1288
1289func (config SetChatPhotoConfig) name() string {
1290	return "photo"
1291}
1292
1293func (config SetChatPhotoConfig) getFile() interface{} {
1294	return config.File
1295}
1296
1297func (config SetChatPhotoConfig) useExistingFile() bool {
1298	return config.UseExisting
1299}
1300
1301// DeleteChatPhotoConfig allows you to delete a group, supergroup, or channel's photo.
1302type DeleteChatPhotoConfig struct {
1303	ChatID          int64
1304	ChannelUsername string
1305}
1306
1307func (config DeleteChatPhotoConfig) method() string {
1308	return "deleteChatPhoto"
1309}
1310
1311func (config DeleteChatPhotoConfig) params() (Params, error) {
1312	params := make(Params)
1313
1314	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1315
1316	return params, nil
1317}
1318
1319// SetChatTitleConfig allows you to set the title of something other than a private chat.
1320type SetChatTitleConfig struct {
1321	ChatID          int64
1322	ChannelUsername string
1323
1324	Title string
1325}
1326
1327func (config SetChatTitleConfig) method() string {
1328	return "setChatTitle"
1329}
1330
1331func (config SetChatTitleConfig) params() (Params, error) {
1332	params := make(Params)
1333
1334	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1335	params["title"] = config.Title
1336
1337	return params, nil
1338}
1339
1340// SetChatDescriptionConfig allows you to set the description of a supergroup or channel.
1341type SetChatDescriptionConfig struct {
1342	ChatID          int64
1343	ChannelUsername string
1344
1345	Description string
1346}
1347
1348func (config SetChatDescriptionConfig) method() string {
1349	return "setChatDescription"
1350}
1351
1352func (config SetChatDescriptionConfig) params() (Params, error) {
1353	params := make(Params)
1354
1355	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1356	params["description"] = config.Description
1357
1358	return params, nil
1359}
1360
1361// GetStickerSetConfig allows you to get the stickers in a set.
1362type GetStickerSetConfig struct {
1363	Name string
1364}
1365
1366func (config GetStickerSetConfig) method() string {
1367	return "getStickerSet"
1368}
1369
1370func (config GetStickerSetConfig) params() (Params, error) {
1371	params := make(Params)
1372
1373	params["name"] = config.Name
1374
1375	return params, nil
1376}
1377
1378// UploadStickerConfig allows you to upload a sticker for use in a set later.
1379type UploadStickerConfig struct {
1380	UserID     int64
1381	PNGSticker interface{}
1382}
1383
1384func (config UploadStickerConfig) method() string {
1385	return "uploadStickerFile"
1386}
1387
1388func (config UploadStickerConfig) params() (Params, error) {
1389	params := make(Params)
1390
1391	params.AddNonZero64("user_id", config.UserID)
1392
1393	return params, nil
1394}
1395
1396func (config UploadStickerConfig) name() string {
1397	return "png_sticker"
1398}
1399
1400func (config UploadStickerConfig) getFile() interface{} {
1401	return config.PNGSticker
1402}
1403
1404func (config UploadStickerConfig) useExistingFile() bool {
1405	return false
1406}
1407
1408// NewStickerSetConfig allows creating a new sticker set.
1409type NewStickerSetConfig struct {
1410	UserID        int64
1411	Name          string
1412	Title         string
1413	PNGSticker    interface{}
1414	Emojis        string
1415	ContainsMasks bool
1416	MaskPosition  *MaskPosition
1417}
1418
1419func (config NewStickerSetConfig) method() string {
1420	return "createNewStickerSet"
1421}
1422
1423func (config NewStickerSetConfig) params() (Params, error) {
1424	params := make(Params)
1425
1426	params.AddNonZero64("user_id", config.UserID)
1427	params["name"] = config.Name
1428	params["title"] = config.Title
1429
1430	if sticker, ok := config.PNGSticker.(string); ok {
1431		params[config.name()] = sticker
1432	}
1433
1434	params["emojis"] = config.Emojis
1435
1436	params.AddBool("contains_masks", config.ContainsMasks)
1437
1438	err := params.AddInterface("mask_position", config.MaskPosition)
1439
1440	return params, err
1441}
1442
1443func (config NewStickerSetConfig) getFile() interface{} {
1444	return config.PNGSticker
1445}
1446
1447func (config NewStickerSetConfig) name() string {
1448	return "png_sticker"
1449}
1450
1451func (config NewStickerSetConfig) useExistingFile() bool {
1452	_, ok := config.PNGSticker.(string)
1453
1454	return ok
1455}
1456
1457// AddStickerConfig allows you to add a sticker to a set.
1458type AddStickerConfig struct {
1459	UserID       int64
1460	Name         string
1461	PNGSticker   interface{}
1462	Emojis       string
1463	MaskPosition *MaskPosition
1464}
1465
1466func (config AddStickerConfig) method() string {
1467	return "addStickerToSet"
1468}
1469
1470func (config AddStickerConfig) params() (Params, error) {
1471	params := make(Params)
1472
1473	params.AddNonZero64("user_id", config.UserID)
1474	params["name"] = config.Name
1475	params["emojis"] = config.Emojis
1476
1477	if sticker, ok := config.PNGSticker.(string); ok {
1478		params[config.name()] = sticker
1479	}
1480
1481	err := params.AddInterface("mask_position", config.MaskPosition)
1482
1483	return params, err
1484}
1485
1486func (config AddStickerConfig) name() string {
1487	return "png_sticker"
1488}
1489
1490func (config AddStickerConfig) getFile() interface{} {
1491	return config.PNGSticker
1492}
1493
1494func (config AddStickerConfig) useExistingFile() bool {
1495	return false
1496}
1497
1498// SetStickerPositionConfig allows you to change the position of a sticker in a set.
1499type SetStickerPositionConfig struct {
1500	Sticker  string
1501	Position int
1502}
1503
1504func (config SetStickerPositionConfig) method() string {
1505	return "setStickerPositionInSet"
1506}
1507
1508func (config SetStickerPositionConfig) params() (Params, error) {
1509	params := make(Params)
1510
1511	params["sticker"] = config.Sticker
1512	params.AddNonZero("position", config.Position)
1513
1514	return params, nil
1515}
1516
1517// DeleteStickerConfig allows you to delete a sticker from a set.
1518type DeleteStickerConfig struct {
1519	Sticker string
1520}
1521
1522func (config DeleteStickerConfig) method() string {
1523	return "deleteStickerFromSet"
1524}
1525
1526func (config DeleteStickerConfig) params() (Params, error) {
1527	params := make(Params)
1528
1529	params["sticker"] = config.Sticker
1530
1531	return params, nil
1532}
1533
1534// SetChatStickerSetConfig allows you to set the sticker set for a supergroup.
1535type SetChatStickerSetConfig struct {
1536	ChatID             int64
1537	SuperGroupUsername string
1538
1539	StickerSetName string
1540}
1541
1542func (config SetChatStickerSetConfig) method() string {
1543	return "setChatStickerSet"
1544}
1545
1546func (config SetChatStickerSetConfig) params() (Params, error) {
1547	params := make(Params)
1548
1549	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1550	params["sticker_set_name"] = config.StickerSetName
1551
1552	return params, nil
1553}
1554
1555// DeleteChatStickerSetConfig allows you to remove a supergroup's sticker set.
1556type DeleteChatStickerSetConfig struct {
1557	ChatID             int64
1558	SuperGroupUsername string
1559}
1560
1561func (config DeleteChatStickerSetConfig) method() string {
1562	return "deleteChatStickerSet"
1563}
1564
1565func (config DeleteChatStickerSetConfig) params() (Params, error) {
1566	params := make(Params)
1567
1568	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1569
1570	return params, nil
1571}
1572
1573// MediaGroupConfig allows you to send a group of media.
1574//
1575// Media consist of InputMedia items (InputMediaPhoto, InputMediaVideo).
1576type MediaGroupConfig struct {
1577	ChatID          int64
1578	ChannelUsername string
1579
1580	Media               []interface{}
1581	DisableNotification bool
1582	ReplyToMessageID    int
1583}
1584
1585func (config MediaGroupConfig) method() string {
1586	return "sendMediaGroup"
1587}
1588
1589func (config MediaGroupConfig) params() (Params, error) {
1590	params := make(Params)
1591
1592	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1593	if err := params.AddInterface("media", config.Media); err != nil {
1594		return params, nil
1595	}
1596	params.AddBool("disable_notification", config.DisableNotification)
1597	params.AddNonZero("reply_to_message_id", config.ReplyToMessageID)
1598
1599	return params, nil
1600}