all repos — telegram-bot-api @ 24e02f7ba6aa2e045e23e8afbebaf7f249f0e368

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	err := params.AddInterface("results", config.Results)
1005
1006	return params, err
1007}
1008
1009// CallbackConfig contains information on making a CallbackQuery response.
1010type CallbackConfig struct {
1011	CallbackQueryID string `json:"callback_query_id"`
1012	Text            string `json:"text"`
1013	ShowAlert       bool   `json:"show_alert"`
1014	URL             string `json:"url"`
1015	CacheTime       int    `json:"cache_time"`
1016}
1017
1018func (config CallbackConfig) method() string {
1019	return "answerCallbackQuery"
1020}
1021
1022func (config CallbackConfig) params() (Params, error) {
1023	params := make(Params)
1024
1025	params["callback_query_id"] = config.CallbackQueryID
1026	params.AddNonEmpty("text", config.Text)
1027	params.AddBool("show_alert", config.ShowAlert)
1028	params.AddNonEmpty("url", config.URL)
1029	params.AddNonZero("cache_time", config.CacheTime)
1030
1031	return params, nil
1032}
1033
1034// ChatMemberConfig contains information about a user in a chat for use
1035// with administrative functions such as kicking or unbanning a user.
1036type ChatMemberConfig struct {
1037	ChatID             int64
1038	SuperGroupUsername string
1039	ChannelUsername    string
1040	UserID             int
1041}
1042
1043// UnbanChatMemberConfig allows you to unban a user.
1044type UnbanChatMemberConfig struct {
1045	ChatMemberConfig
1046	OnlyIfBanned bool
1047}
1048
1049func (config UnbanChatMemberConfig) method() string {
1050	return "unbanChatMember"
1051}
1052
1053func (config UnbanChatMemberConfig) params() (Params, error) {
1054	params := make(Params)
1055
1056	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1057	params.AddNonZero("user_id", config.UserID)
1058	params.AddBool("only_if_banned", config.OnlyIfBanned)
1059
1060	return params, nil
1061}
1062
1063// KickChatMemberConfig contains extra fields to kick user
1064type KickChatMemberConfig struct {
1065	ChatMemberConfig
1066	UntilDate int64
1067}
1068
1069func (config KickChatMemberConfig) method() string {
1070	return "kickChatMember"
1071}
1072
1073func (config KickChatMemberConfig) params() (Params, error) {
1074	params := make(Params)
1075
1076	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1077	params.AddNonZero("user_id", config.UserID)
1078	params.AddNonZero64("until_date", config.UntilDate)
1079
1080	return params, nil
1081}
1082
1083// RestrictChatMemberConfig contains fields to restrict members of chat
1084type RestrictChatMemberConfig struct {
1085	ChatMemberConfig
1086	UntilDate   int64
1087	Permissions *ChatPermissions
1088}
1089
1090func (config RestrictChatMemberConfig) method() string {
1091	return "restrictChatMember"
1092}
1093
1094func (config RestrictChatMemberConfig) params() (Params, error) {
1095	params := make(Params)
1096
1097	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1098	params.AddNonZero("user_id", config.UserID)
1099
1100	err := params.AddInterface("permissions", config.Permissions)
1101	params.AddNonZero64("until_date", config.UntilDate)
1102
1103	return params, err
1104}
1105
1106// PromoteChatMemberConfig contains fields to promote members of chat
1107type PromoteChatMemberConfig struct {
1108	ChatMemberConfig
1109	IsAnonymous        bool
1110	CanChangeInfo      bool
1111	CanPostMessages    bool
1112	CanEditMessages    bool
1113	CanDeleteMessages  bool
1114	CanInviteUsers     bool
1115	CanRestrictMembers bool
1116	CanPinMessages     bool
1117	CanPromoteMembers  bool
1118}
1119
1120func (config PromoteChatMemberConfig) method() string {
1121	return "promoteChatMember"
1122}
1123
1124func (config PromoteChatMemberConfig) params() (Params, error) {
1125	params := make(Params)
1126
1127	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1128	params.AddNonZero("user_id", config.UserID)
1129
1130	params.AddBool("is_anonymous", config.IsAnonymous)
1131	params.AddBool("can_change_info", config.CanChangeInfo)
1132	params.AddBool("can_post_messages", config.CanPostMessages)
1133	params.AddBool("can_edit_messages", config.CanEditMessages)
1134	params.AddBool("can_delete_messages", config.CanDeleteMessages)
1135	params.AddBool("can_invite_users", config.CanInviteUsers)
1136	params.AddBool("can_restrict_members", config.CanRestrictMembers)
1137	params.AddBool("can_pin_messages", config.CanPinMessages)
1138	params.AddBool("can_promote_members", config.CanPromoteMembers)
1139
1140	return params, nil
1141}
1142
1143// SetChatAdministratorCustomTitle sets the title of an administrative user
1144// promoted by the bot for a chat.
1145type SetChatAdministratorCustomTitle struct {
1146	ChatMemberConfig
1147	CustomTitle string
1148}
1149
1150func (SetChatAdministratorCustomTitle) method() string {
1151	return "setChatAdministratorCustomTitle"
1152}
1153
1154func (config SetChatAdministratorCustomTitle) params() (Params, error) {
1155	params := make(Params)
1156
1157	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1158	params.AddNonZero("user_id", config.UserID)
1159	params.AddNonEmpty("custom_title", config.CustomTitle)
1160
1161	return params, nil
1162}
1163
1164// ChatConfig contains information about getting information on a chat.
1165type ChatConfig struct {
1166	ChatID             int64
1167	SuperGroupUsername string
1168}
1169
1170func (config ChatConfig) params() (Params, error) {
1171	params := make(Params)
1172
1173	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1174
1175	return params, nil
1176}
1177
1178// ChatInfoConfig contains information about getting chat information.
1179type ChatInfoConfig struct {
1180	ChatConfig
1181}
1182
1183func (ChatInfoConfig) method() string {
1184	return "getChat"
1185}
1186
1187// ChatMemberCountConfig contains information about getting the number of users in a chat.
1188type ChatMemberCountConfig struct {
1189	ChatConfig
1190}
1191
1192func (ChatMemberCountConfig) method() string {
1193	return "getChatMembersCount"
1194}
1195
1196// ChatAdministratorsConfig contains information about getting chat administrators.
1197type ChatAdministratorsConfig struct {
1198	ChatConfig
1199}
1200
1201func (ChatAdministratorsConfig) method() string {
1202	return "getChatAdministrators"
1203}
1204
1205// SetChatPermissionsConfig allows you to set default permissions for the
1206// members in a group. The bot must be an administrator and have rights to
1207// restrict members.
1208type SetChatPermissionsConfig struct {
1209	ChatConfig
1210	Permissions *ChatPermissions
1211}
1212
1213func (SetChatPermissionsConfig) method() string {
1214	return "setChatPermissions"
1215}
1216
1217func (config SetChatPermissionsConfig) params() (Params, error) {
1218	params := make(Params)
1219
1220	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1221	params.AddInterface("permissions", config.Permissions)
1222
1223	return params, nil
1224}
1225
1226// ChatInviteLinkConfig contains information about getting a chat link.
1227//
1228// Note that generating a new link will revoke any previous links.
1229type ChatInviteLinkConfig struct {
1230	ChatConfig
1231}
1232
1233func (ChatInviteLinkConfig) method() string {
1234	return "exportChatInviteLink"
1235}
1236
1237func (config ChatInviteLinkConfig) params() (Params, error) {
1238	params := make(Params)
1239
1240	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1241
1242	return params, nil
1243}
1244
1245// LeaveChatConfig allows you to leave a chat.
1246type LeaveChatConfig struct {
1247	ChatID          int64
1248	ChannelUsername string
1249}
1250
1251func (config LeaveChatConfig) method() string {
1252	return "leaveChat"
1253}
1254
1255func (config LeaveChatConfig) params() (Params, error) {
1256	params := make(Params)
1257
1258	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1259
1260	return params, nil
1261}
1262
1263// ChatConfigWithUser contains information about a chat and a user.
1264type ChatConfigWithUser struct {
1265	ChatID             int64
1266	SuperGroupUsername string
1267	UserID             int
1268}
1269
1270func (config ChatConfigWithUser) params() (Params, error) {
1271	params := make(Params)
1272
1273	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1274	params.AddNonZero("user_id", config.UserID)
1275
1276	return params, nil
1277}
1278
1279// GetChatMemberConfig is information about getting a specific member in a chat.
1280type GetChatMemberConfig struct {
1281	ChatConfigWithUser
1282}
1283
1284func (GetChatMemberConfig) method() string {
1285	return "getChatMember"
1286}
1287
1288// InvoiceConfig contains information for sendInvoice request.
1289type InvoiceConfig struct {
1290	BaseChat
1291	Title                     string         // required
1292	Description               string         // required
1293	Payload                   string         // required
1294	ProviderToken             string         // required
1295	StartParameter            string         // required
1296	Currency                  string         // required
1297	Prices                    []LabeledPrice // required
1298	ProviderData              string
1299	PhotoURL                  string
1300	PhotoSize                 int
1301	PhotoWidth                int
1302	PhotoHeight               int
1303	NeedName                  bool
1304	NeedPhoneNumber           bool
1305	NeedEmail                 bool
1306	NeedShippingAddress       bool
1307	SendPhoneNumberToProvider bool
1308	SendEmailToProvider       bool
1309	IsFlexible                bool
1310}
1311
1312func (config InvoiceConfig) params() (Params, error) {
1313	params, err := config.BaseChat.params()
1314	if err != nil {
1315		return params, err
1316	}
1317
1318	params["title"] = config.Title
1319	params["description"] = config.Description
1320	params["payload"] = config.Payload
1321	params["provider_token"] = config.ProviderToken
1322	params["start_parameter"] = config.StartParameter
1323	params["currency"] = config.Currency
1324
1325	err = params.AddInterface("prices", config.Prices)
1326	params.AddNonEmpty("provider_data", config.ProviderData)
1327	params.AddNonEmpty("photo_url", config.PhotoURL)
1328	params.AddNonZero("photo_size", config.PhotoSize)
1329	params.AddNonZero("photo_width", config.PhotoWidth)
1330	params.AddNonZero("photo_height", config.PhotoHeight)
1331	params.AddBool("need_name", config.NeedName)
1332	params.AddBool("need_phone_number", config.NeedPhoneNumber)
1333	params.AddBool("need_email", config.NeedEmail)
1334	params.AddBool("need_shipping_address", config.NeedShippingAddress)
1335	params.AddBool("is_flexible", config.IsFlexible)
1336	params.AddBool("send_phone_number_to_provider", config.SendPhoneNumberToProvider)
1337	params.AddBool("send_email_to_provider", config.SendEmailToProvider)
1338
1339	return params, err
1340}
1341
1342func (config InvoiceConfig) method() string {
1343	return "sendInvoice"
1344}
1345
1346// ShippingConfig contains information for answerShippingQuery request.
1347type ShippingConfig struct {
1348	ShippingQueryID string // required
1349	OK              bool   // required
1350	ShippingOptions []ShippingOption
1351	ErrorMessage    string
1352}
1353
1354func (config ShippingConfig) method() string {
1355	return "answerShippingQuery"
1356}
1357
1358func (config ShippingConfig) params() (Params, error) {
1359	params := make(Params)
1360
1361	params["shipping_query_id"] = config.ShippingQueryID
1362	params.AddBool("ok", config.OK)
1363	err := params.AddInterface("shipping_options", config.ShippingOptions)
1364	params.AddNonEmpty("error_message", config.ErrorMessage)
1365
1366	return params, err
1367}
1368
1369// PreCheckoutConfig conatins information for answerPreCheckoutQuery request.
1370type PreCheckoutConfig struct {
1371	PreCheckoutQueryID string // required
1372	OK                 bool   // required
1373	ErrorMessage       string
1374}
1375
1376func (config PreCheckoutConfig) method() string {
1377	return "answerPreCheckoutQuery"
1378}
1379
1380func (config PreCheckoutConfig) params() (Params, error) {
1381	params := make(Params)
1382
1383	params["pre_checkout_query_id"] = config.PreCheckoutQueryID
1384	params.AddBool("ok", config.OK)
1385	params.AddNonEmpty("error_message", config.ErrorMessage)
1386
1387	return params, nil
1388}
1389
1390// DeleteMessageConfig contains information of a message in a chat to delete.
1391type DeleteMessageConfig struct {
1392	ChannelUsername string
1393	ChatID          int64
1394	MessageID       int
1395}
1396
1397func (config DeleteMessageConfig) method() string {
1398	return "deleteMessage"
1399}
1400
1401func (config DeleteMessageConfig) 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
1407	return params, nil
1408}
1409
1410// PinChatMessageConfig contains information of a message in a chat to pin.
1411type PinChatMessageConfig struct {
1412	ChatID              int64
1413	ChannelUsername     string
1414	MessageID           int
1415	DisableNotification bool
1416}
1417
1418func (config PinChatMessageConfig) method() string {
1419	return "pinChatMessage"
1420}
1421
1422func (config PinChatMessageConfig) params() (Params, error) {
1423	params := make(Params)
1424
1425	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1426	params.AddNonZero("message_id", config.MessageID)
1427	params.AddBool("disable_notification", config.DisableNotification)
1428
1429	return params, nil
1430}
1431
1432// UnpinChatMessageConfig contains information of a chat message to unpin.
1433//
1434// If MessageID is not specified, it will unpin the most recent pin.
1435type UnpinChatMessageConfig struct {
1436	ChatID          int64
1437	ChannelUsername string
1438	MessageID       int
1439}
1440
1441func (config UnpinChatMessageConfig) method() string {
1442	return "unpinChatMessage"
1443}
1444
1445func (config UnpinChatMessageConfig) params() (Params, error) {
1446	params := make(Params)
1447
1448	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1449	params.AddNonZero("message_id", config.MessageID)
1450
1451	return params, nil
1452}
1453
1454// UnpinAllChatMessagesConfig contains information of all messages to unpin in
1455// a chat.
1456type UnpinAllChatMessagesConfig struct {
1457	ChatID          int64
1458	ChannelUsername string
1459}
1460
1461func (config UnpinAllChatMessagesConfig) method() string {
1462	return "unpinAllChatMessages"
1463}
1464
1465func (config UnpinAllChatMessagesConfig) params() (Params, error) {
1466	params := make(Params)
1467
1468	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1469
1470	return params, nil
1471}
1472
1473// SetChatPhotoConfig allows you to set a group, supergroup, or channel's photo.
1474type SetChatPhotoConfig struct {
1475	BaseFile
1476}
1477
1478func (config SetChatPhotoConfig) method() string {
1479	return "setChatPhoto"
1480}
1481
1482func (config SetChatPhotoConfig) name() string {
1483	return "photo"
1484}
1485
1486func (config SetChatPhotoConfig) getFile() interface{} {
1487	return config.File
1488}
1489
1490func (config SetChatPhotoConfig) useExistingFile() bool {
1491	return config.UseExisting
1492}
1493
1494// DeleteChatPhotoConfig allows you to delete a group, supergroup, or channel's photo.
1495type DeleteChatPhotoConfig struct {
1496	ChatID          int64
1497	ChannelUsername string
1498}
1499
1500func (config DeleteChatPhotoConfig) method() string {
1501	return "deleteChatPhoto"
1502}
1503
1504func (config DeleteChatPhotoConfig) params() (Params, error) {
1505	params := make(Params)
1506
1507	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1508
1509	return params, nil
1510}
1511
1512// SetChatTitleConfig allows you to set the title of something other than a private chat.
1513type SetChatTitleConfig struct {
1514	ChatID          int64
1515	ChannelUsername string
1516
1517	Title string
1518}
1519
1520func (config SetChatTitleConfig) method() string {
1521	return "setChatTitle"
1522}
1523
1524func (config SetChatTitleConfig) params() (Params, error) {
1525	params := make(Params)
1526
1527	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1528	params["title"] = config.Title
1529
1530	return params, nil
1531}
1532
1533// SetChatDescriptionConfig allows you to set the description of a supergroup or channel.
1534type SetChatDescriptionConfig struct {
1535	ChatID          int64
1536	ChannelUsername string
1537
1538	Description string
1539}
1540
1541func (config SetChatDescriptionConfig) method() string {
1542	return "setChatDescription"
1543}
1544
1545func (config SetChatDescriptionConfig) params() (Params, error) {
1546	params := make(Params)
1547
1548	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1549	params["description"] = config.Description
1550
1551	return params, nil
1552}
1553
1554// GetStickerSetConfig allows you to get the stickers in a set.
1555type GetStickerSetConfig struct {
1556	Name string
1557}
1558
1559func (config GetStickerSetConfig) method() string {
1560	return "getStickerSet"
1561}
1562
1563func (config GetStickerSetConfig) params() (Params, error) {
1564	params := make(Params)
1565
1566	params["name"] = config.Name
1567
1568	return params, nil
1569}
1570
1571// UploadStickerConfig allows you to upload a sticker for use in a set later.
1572type UploadStickerConfig struct {
1573	UserID     int64
1574	PNGSticker interface{}
1575}
1576
1577func (config UploadStickerConfig) method() string {
1578	return "uploadStickerFile"
1579}
1580
1581func (config UploadStickerConfig) params() (Params, error) {
1582	params := make(Params)
1583
1584	params.AddNonZero64("user_id", config.UserID)
1585
1586	return params, nil
1587}
1588
1589func (config UploadStickerConfig) name() string {
1590	return "png_sticker"
1591}
1592
1593func (config UploadStickerConfig) getFile() interface{} {
1594	return config.PNGSticker
1595}
1596
1597func (config UploadStickerConfig) useExistingFile() bool {
1598	_, ok := config.PNGSticker.(string)
1599
1600	return ok
1601}
1602
1603// NewStickerSetConfig allows creating a new sticker set.
1604//
1605// You must set either PNGSticker or TGSSticker.
1606type NewStickerSetConfig struct {
1607	UserID        int64
1608	Name          string
1609	Title         string
1610	PNGSticker    interface{}
1611	TGSSticker    interface{}
1612	Emojis        string
1613	ContainsMasks bool
1614	MaskPosition  *MaskPosition
1615}
1616
1617func (config NewStickerSetConfig) method() string {
1618	return "createNewStickerSet"
1619}
1620
1621func (config NewStickerSetConfig) params() (Params, error) {
1622	params := make(Params)
1623
1624	params.AddNonZero64("user_id", config.UserID)
1625	params["name"] = config.Name
1626	params["title"] = config.Title
1627
1628	if sticker, ok := config.PNGSticker.(string); ok {
1629		params[config.name()] = sticker
1630	} else if sticker, ok := config.TGSSticker.(string); ok {
1631		params[config.name()] = sticker
1632	}
1633
1634	params["emojis"] = config.Emojis
1635
1636	params.AddBool("contains_masks", config.ContainsMasks)
1637
1638	err := params.AddInterface("mask_position", config.MaskPosition)
1639
1640	return params, err
1641}
1642
1643func (config NewStickerSetConfig) getFile() interface{} {
1644	return config.PNGSticker
1645}
1646
1647func (config NewStickerSetConfig) name() string {
1648	return "png_sticker"
1649}
1650
1651func (config NewStickerSetConfig) useExistingFile() bool {
1652	if config.PNGSticker != nil {
1653		_, ok := config.PNGSticker.(string)
1654		return ok
1655	}
1656
1657	if config.TGSSticker != nil {
1658		_, ok := config.TGSSticker.(string)
1659		return ok
1660	}
1661
1662	panic("NewStickerSetConfig had nil PNGSticker and TGSSticker")
1663}
1664
1665// AddStickerConfig allows you to add a sticker to a set.
1666type AddStickerConfig struct {
1667	UserID       int64
1668	Name         string
1669	PNGSticker   interface{}
1670	TGSSticker   interface{}
1671	Emojis       string
1672	MaskPosition *MaskPosition
1673}
1674
1675func (config AddStickerConfig) method() string {
1676	return "addStickerToSet"
1677}
1678
1679func (config AddStickerConfig) params() (Params, error) {
1680	params := make(Params)
1681
1682	params.AddNonZero64("user_id", config.UserID)
1683	params["name"] = config.Name
1684	params["emojis"] = config.Emojis
1685
1686	if sticker, ok := config.PNGSticker.(string); ok {
1687		params[config.name()] = sticker
1688	} else if sticker, ok := config.TGSSticker.(string); ok {
1689		params[config.name()] = sticker
1690	}
1691
1692	err := params.AddInterface("mask_position", config.MaskPosition)
1693
1694	return params, err
1695}
1696
1697func (config AddStickerConfig) name() string {
1698	return "png_sticker"
1699}
1700
1701func (config AddStickerConfig) getFile() interface{} {
1702	return config.PNGSticker
1703}
1704
1705func (config AddStickerConfig) useExistingFile() bool {
1706	_, ok := config.PNGSticker.(string)
1707
1708	return ok
1709}
1710
1711// SetStickerPositionConfig allows you to change the position of a sticker in a set.
1712type SetStickerPositionConfig struct {
1713	Sticker  string
1714	Position int
1715}
1716
1717func (config SetStickerPositionConfig) method() string {
1718	return "setStickerPositionInSet"
1719}
1720
1721func (config SetStickerPositionConfig) params() (Params, error) {
1722	params := make(Params)
1723
1724	params["sticker"] = config.Sticker
1725	params.AddNonZero("position", config.Position)
1726
1727	return params, nil
1728}
1729
1730// DeleteStickerConfig allows you to delete a sticker from a set.
1731type DeleteStickerConfig struct {
1732	Sticker string
1733}
1734
1735func (config DeleteStickerConfig) method() string {
1736	return "deleteStickerFromSet"
1737}
1738
1739func (config DeleteStickerConfig) params() (Params, error) {
1740	params := make(Params)
1741
1742	params["sticker"] = config.Sticker
1743
1744	return params, nil
1745}
1746
1747// SetStickerSetThumbConfig allows you to set the thumbnail for a sticker set.
1748type SetStickerSetThumbConfig struct {
1749	Name   string
1750	UserID int
1751	Thumb  interface{}
1752}
1753
1754func (config SetStickerSetThumbConfig) method() string {
1755	return "setStickerSetThumb"
1756}
1757
1758func (config SetStickerSetThumbConfig) params() (Params, error) {
1759	params := make(Params)
1760
1761	params["name"] = config.Name
1762	params.AddNonZero("user_id", config.UserID)
1763
1764	if thumb, ok := config.Thumb.(string); ok {
1765		params["thumb"] = thumb
1766	}
1767
1768	return params, nil
1769}
1770
1771func (config SetStickerSetThumbConfig) name() string {
1772	return "thumb"
1773}
1774
1775func (config SetStickerSetThumbConfig) getFile() interface{} {
1776	return config.Thumb
1777}
1778
1779func (config SetStickerSetThumbConfig) useExistingFile() bool {
1780	_, ok := config.Thumb.(string)
1781	return ok
1782}
1783
1784// SetChatStickerSetConfig allows you to set the sticker set for a supergroup.
1785type SetChatStickerSetConfig struct {
1786	ChatID             int64
1787	SuperGroupUsername string
1788
1789	StickerSetName string
1790}
1791
1792func (config SetChatStickerSetConfig) method() string {
1793	return "setChatStickerSet"
1794}
1795
1796func (config SetChatStickerSetConfig) params() (Params, error) {
1797	params := make(Params)
1798
1799	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1800	params["sticker_set_name"] = config.StickerSetName
1801
1802	return params, nil
1803}
1804
1805// DeleteChatStickerSetConfig allows you to remove a supergroup's sticker set.
1806type DeleteChatStickerSetConfig struct {
1807	ChatID             int64
1808	SuperGroupUsername string
1809}
1810
1811func (config DeleteChatStickerSetConfig) method() string {
1812	return "deleteChatStickerSet"
1813}
1814
1815func (config DeleteChatStickerSetConfig) params() (Params, error) {
1816	params := make(Params)
1817
1818	params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1819
1820	return params, nil
1821}
1822
1823// MediaGroupConfig allows you to send a group of media.
1824//
1825// Media consist of InputMedia items (InputMediaPhoto, InputMediaVideo).
1826type MediaGroupConfig struct {
1827	ChatID          int64
1828	ChannelUsername string
1829
1830	Media               []interface{}
1831	DisableNotification bool
1832	ReplyToMessageID    int
1833}
1834
1835func (config MediaGroupConfig) method() string {
1836	return "sendMediaGroup"
1837}
1838
1839func (config MediaGroupConfig) params() (Params, error) {
1840	params := make(Params)
1841
1842	params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1843	if err := params.AddInterface("media", config.Media); err != nil {
1844		return params, nil
1845	}
1846	params.AddBool("disable_notification", config.DisableNotification)
1847	params.AddNonZero("reply_to_message_id", config.ReplyToMessageID)
1848
1849	return params, nil
1850}
1851
1852// GetMyCommandsConfig gets a list of the currently registered commands.
1853type GetMyCommandsConfig struct{}
1854
1855func (config GetMyCommandsConfig) method() string {
1856	return "getMyCommands"
1857}
1858
1859func (config GetMyCommandsConfig) params() (Params, error) {
1860	return nil, nil
1861}
1862
1863// SetMyCommandsConfig sets a list of commands the bot understands.
1864type SetMyCommandsConfig struct {
1865	commands []BotCommand
1866}
1867
1868func (config SetMyCommandsConfig) method() string {
1869	return "setMyCommands"
1870}
1871
1872func (config SetMyCommandsConfig) params() (Params, error) {
1873	params := make(Params)
1874
1875	err := params.AddInterface("commands", config.commands)
1876
1877	return params, err
1878}
1879
1880// DiceConfig contains information about a sendDice request.
1881type DiceConfig struct {
1882	BaseChat
1883	// Emoji on which the dice throw animation is based.
1884	// Currently, must be one of “🎲”, “🎯”, or “🏀”.
1885	// Dice can have values 1-6 for “🎲” and “🎯”, and values 1-5 for “🏀”.
1886	// Defaults to “🎲”
1887	Emoji string
1888}
1889
1890func (config DiceConfig) method() string {
1891	return "sendDice"
1892}
1893
1894func (config DiceConfig) params() (Params, error) {
1895	params, err := config.BaseChat.params()
1896	if err != nil {
1897		return params, err
1898	}
1899
1900	params.AddNonEmpty("emoji", config.Emoji)
1901
1902	return params, err
1903}