all repos — telegram-bot-api @ ac5306ce0c6d68946d7d5a029c0338e758b5fc96

Golang bindings for the Telegram Bot API

configs.go (view raw)

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