all repos — telegram-bot-api @ 2326345451850fb4504d464e365d1b5490bc5072

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