all repos — telegram-bot-api @ 0b68c9b7906ce2b3af7c9a42053f32c286b17801

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}
 827
 828func (config EditMessageCaptionConfig) values() (url.Values, error) {
 829	v, _ := config.BaseEdit.values()
 830
 831	v.Add("caption", config.Caption)
 832
 833	return v, nil
 834}
 835
 836func (config EditMessageCaptionConfig) method() string {
 837	return "editMessageCaption"
 838}
 839
 840// EditMessageReplyMarkupConfig allows you to modify the reply markup
 841// of a message.
 842type EditMessageReplyMarkupConfig struct {
 843	BaseEdit
 844}
 845
 846func (config EditMessageReplyMarkupConfig) values() (url.Values, error) {
 847	return config.BaseEdit.values()
 848}
 849
 850func (config EditMessageReplyMarkupConfig) method() string {
 851	return "editMessageReplyMarkup"
 852}
 853
 854// UserProfilePhotosConfig contains information about a
 855// GetUserProfilePhotos request.
 856type UserProfilePhotosConfig struct {
 857	UserID int
 858	Offset int
 859	Limit  int
 860}
 861
 862// FileConfig has information about a file hosted on Telegram.
 863type FileConfig struct {
 864	FileID string
 865}
 866
 867// UpdateConfig contains information about a GetUpdates request.
 868type UpdateConfig struct {
 869	Offset  int
 870	Limit   int
 871	Timeout int
 872}
 873
 874// WebhookConfig contains information about a SetWebhook request.
 875type WebhookConfig struct {
 876	URL            *url.URL
 877	Certificate    interface{}
 878	MaxConnections int
 879}
 880
 881// FileBytes contains information about a set of bytes to upload
 882// as a File.
 883type FileBytes struct {
 884	Name  string
 885	Bytes []byte
 886}
 887
 888// FileReader contains information about a reader to upload as a File.
 889// If Size is -1, it will read the entire Reader into memory to
 890// calculate a Size.
 891type FileReader struct {
 892	Name   string
 893	Reader io.Reader
 894	Size   int64
 895}
 896
 897// InlineConfig contains information on making an InlineQuery response.
 898type InlineConfig struct {
 899	InlineQueryID     string        `json:"inline_query_id"`
 900	Results           []interface{} `json:"results"`
 901	CacheTime         int           `json:"cache_time"`
 902	IsPersonal        bool          `json:"is_personal"`
 903	NextOffset        string        `json:"next_offset"`
 904	SwitchPMText      string        `json:"switch_pm_text"`
 905	SwitchPMParameter string        `json:"switch_pm_parameter"`
 906}
 907
 908// CallbackConfig contains information on making a CallbackQuery response.
 909type CallbackConfig struct {
 910	CallbackQueryID string `json:"callback_query_id"`
 911	Text            string `json:"text"`
 912	ShowAlert       bool   `json:"show_alert"`
 913	URL             string `json:"url"`
 914	CacheTime       int    `json:"cache_time"`
 915}
 916
 917// ChatMemberConfig contains information about a user in a chat for use
 918// with administrative functions such as kicking or unbanning a user.
 919type ChatMemberConfig struct {
 920	ChatID             int64
 921	SuperGroupUsername string
 922	ChannelUsername    string
 923	UserID             int
 924}
 925
 926// KickChatMemberConfig contains extra fields to kick user
 927type KickChatMemberConfig struct {
 928	ChatMemberConfig
 929	UntilDate int64
 930}
 931
 932// RestrictChatMemberConfig contains fields to restrict members of chat
 933type RestrictChatMemberConfig struct {
 934	ChatMemberConfig
 935	UntilDate             int64
 936	CanSendMessages       *bool
 937	CanSendMediaMessages  *bool
 938	CanSendOtherMessages  *bool
 939	CanAddWebPagePreviews *bool
 940}
 941
 942// PromoteChatMemberConfig contains fields to promote members of chat
 943type PromoteChatMemberConfig struct {
 944	ChatMemberConfig
 945	CanChangeInfo      *bool
 946	CanPostMessages    *bool
 947	CanEditMessages    *bool
 948	CanDeleteMessages  *bool
 949	CanInviteUsers     *bool
 950	CanRestrictMembers *bool
 951	CanPinMessages     *bool
 952	CanPromoteMembers  *bool
 953}
 954
 955// ChatConfig contains information about getting information on a chat.
 956type ChatConfig struct {
 957	ChatID             int64
 958	SuperGroupUsername string
 959}
 960
 961// ChatConfigWithUser contains information about getting information on
 962// a specific user within a chat.
 963type ChatConfigWithUser struct {
 964	ChatID             int64
 965	SuperGroupUsername string
 966	UserID             int
 967}
 968
 969// InvoiceConfig contains information for sendInvoice request.
 970type InvoiceConfig struct {
 971	BaseChat
 972	Title               string          // required
 973	Description         string          // required
 974	Payload             string          // required
 975	ProviderToken       string          // required
 976	StartParameter      string          // required
 977	Currency            string          // required
 978	Prices              *[]LabeledPrice // required
 979	PhotoURL            string
 980	PhotoSize           int
 981	PhotoWidth          int
 982	PhotoHeight         int
 983	NeedName            bool
 984	NeedPhoneNumber     bool
 985	NeedEmail           bool
 986	NeedShippingAddress bool
 987	IsFlexible          bool
 988}
 989
 990func (config InvoiceConfig) values() (url.Values, error) {
 991	v, err := config.BaseChat.values()
 992	if err != nil {
 993		return v, err
 994	}
 995	v.Add("title", config.Title)
 996	v.Add("description", config.Description)
 997	v.Add("payload", config.Payload)
 998	v.Add("provider_token", config.ProviderToken)
 999	v.Add("start_parameter", config.StartParameter)
1000	v.Add("currency", config.Currency)
1001	data, err := json.Marshal(config.Prices)
1002	if err != nil {
1003		return v, err
1004	}
1005	v.Add("prices", string(data))
1006	if config.PhotoURL != "" {
1007		v.Add("photo_url", config.PhotoURL)
1008	}
1009	if config.PhotoSize != 0 {
1010		v.Add("photo_size", strconv.Itoa(config.PhotoSize))
1011	}
1012	if config.PhotoWidth != 0 {
1013		v.Add("photo_width", strconv.Itoa(config.PhotoWidth))
1014	}
1015	if config.PhotoHeight != 0 {
1016		v.Add("photo_height", strconv.Itoa(config.PhotoHeight))
1017	}
1018	if config.NeedName != false {
1019		v.Add("need_name", strconv.FormatBool(config.NeedName))
1020	}
1021	if config.NeedPhoneNumber != false {
1022		v.Add("need_phone_number", strconv.FormatBool(config.NeedPhoneNumber))
1023	}
1024	if config.NeedEmail != false {
1025		v.Add("need_email", strconv.FormatBool(config.NeedEmail))
1026	}
1027	if config.NeedShippingAddress != false {
1028		v.Add("need_shipping_address", strconv.FormatBool(config.NeedShippingAddress))
1029	}
1030	if config.IsFlexible != false {
1031		v.Add("is_flexible", strconv.FormatBool(config.IsFlexible))
1032	}
1033
1034	return v, nil
1035}
1036
1037func (config InvoiceConfig) method() string {
1038	return "sendInvoice"
1039}
1040
1041// ShippingConfig contains information for answerShippingQuery request.
1042type ShippingConfig struct {
1043	ShippingQueryID string // required
1044	OK              bool   // required
1045	ShippingOptions *[]ShippingOption
1046	ErrorMessage    string
1047}
1048
1049// PreCheckoutConfig conatins information for answerPreCheckoutQuery request.
1050type PreCheckoutConfig struct {
1051	PreCheckoutQueryID string // required
1052	OK                 bool   // required
1053	ErrorMessage       string
1054}
1055
1056// DeleteMessageConfig contains information of a message in a chat to delete.
1057type DeleteMessageConfig struct {
1058	ChatID    int64
1059	MessageID int
1060}
1061
1062func (config DeleteMessageConfig) method() string {
1063	return "deleteMessage"
1064}
1065
1066func (config DeleteMessageConfig) values() (url.Values, error) {
1067	v := url.Values{}
1068
1069	v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1070	v.Add("message_id", strconv.Itoa(config.MessageID))
1071
1072	return v, nil
1073}
1074
1075// PinChatMessageConfig contains information of a message in a chat to pin.
1076type PinChatMessageConfig struct {
1077	ChatID              int64
1078	MessageID           int
1079	DisableNotification bool
1080}
1081
1082func (config PinChatMessageConfig) method() string {
1083	return "pinChatMessage"
1084}
1085
1086func (config PinChatMessageConfig) values() (url.Values, error) {
1087	v := url.Values{}
1088
1089	v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1090	v.Add("message_id", strconv.Itoa(config.MessageID))
1091	v.Add("disable_notification", strconv.FormatBool(config.DisableNotification))
1092
1093	return v, nil
1094}
1095
1096// UnpinChatMessageConfig contains information of chat to unpin.
1097type UnpinChatMessageConfig struct {
1098	ChatID int64
1099}
1100
1101func (config UnpinChatMessageConfig) method() string {
1102	return "unpinChatMessage"
1103}
1104
1105func (config UnpinChatMessageConfig) values() (url.Values, error) {
1106	v := url.Values{}
1107
1108	v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1109
1110	return v, nil
1111}
1112
1113// SetChatTitleConfig contains information for change chat title.
1114type SetChatTitleConfig struct {
1115	ChatID int64
1116	Title  string
1117}
1118
1119func (config SetChatTitleConfig) method() string {
1120	return "setChatTitle"
1121}
1122
1123func (config SetChatTitleConfig) values() (url.Values, error) {
1124	v := url.Values{}
1125
1126	v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1127	v.Add("title", config.Title)
1128
1129	return v, nil
1130}
1131
1132// SetChatDescriptionConfig contains information for change chat description.
1133type SetChatDescriptionConfig struct {
1134	ChatID      int64
1135	Description string
1136}
1137
1138func (config SetChatDescriptionConfig) method() string {
1139	return "setChatDescription"
1140}
1141
1142func (config SetChatDescriptionConfig) values() (url.Values, error) {
1143	v := url.Values{}
1144
1145	v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1146	v.Add("description", config.Description)
1147
1148	return v, nil
1149}
1150
1151// SetChatPhotoConfig contains information for change chat photo
1152type SetChatPhotoConfig struct {
1153	BaseFile
1154}
1155
1156// name returns the field name for the Photo.
1157func (config SetChatPhotoConfig) name() string {
1158	return "photo"
1159}
1160
1161// method returns Telegram API method name for sending Photo.
1162func (config SetChatPhotoConfig) method() string {
1163	return "setChatPhoto"
1164}
1165
1166// DeleteChatPhotoConfig contains information for delete chat photo.
1167type DeleteChatPhotoConfig struct {
1168	ChatID int64
1169}
1170
1171func (config DeleteChatPhotoConfig) method() string {
1172	return "deleteChatPhoto"
1173}
1174
1175func (config DeleteChatPhotoConfig) values() (url.Values, error) {
1176	v := url.Values{}
1177
1178	v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1179
1180	return v, nil
1181}