all repos — telegram-bot-api @ 03815bf5bd2b255ccbca2e4beefb563a65ce945e

Golang bindings for the Telegram Bot API

configs.go (view raw)

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