all repos — telegram-bot-api @ fb8759e91dfc6af21bd422f49040e4ff463381b4

Golang bindings for the Telegram Bot API

configs.go (view raw)

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