all repos — telegram-bot-api @ 4064ced03f921894c1c8ee0b40476903f7d10b40

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