diff --git a/bot.go b/bot.go index 85e16c19..b5c1bf9f 100644 --- a/bot.go +++ b/bot.go @@ -25,8 +25,8 @@ type BotAPI struct { Debug bool `json:"debug"` Buffer int `json:"buffer"` - Self User `json:"-"` - Client *http.Client `json:"-"` + Self User `json:"-"` + Client *http.Client `json:"-"` shutdownChannel chan interface{} } @@ -43,9 +43,9 @@ func NewBotAPI(token string) (*BotAPI, error) { // It requires a token, provided by @BotFather on Telegram. func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) { bot := &BotAPI{ - Token: token, - Client: client, - Buffer: 100, + Token: token, + Client: client, + Buffer: 100, shutdownChannel: make(chan interface{}), } @@ -194,7 +194,6 @@ func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldna } ms.SetupRequest(req) - res, err := bot.Client.Do(req) if err != nil { return APIResponse{}, err @@ -309,7 +308,6 @@ func (bot *BotAPI) uploadAndSend(method string, config Fileable) (Message, error } file := config.getFile() - resp, err := bot.UploadFile(method, params, config.name(), file) if err != nil { return Message{}, err @@ -490,7 +488,7 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) { return default: } - + updates, err := bot.GetUpdates(config) if err != nil { log.Println(err) diff --git a/configs.go b/configs.go index 181d4e43..a83e70b8 100644 --- a/configs.go +++ b/configs.go @@ -934,6 +934,59 @@ func (config EditMessageReplyMarkupConfig) method() string { return "editMessageReplyMarkup" } +// EditMessageMediaConfig allows you to modify the media +// of a message. +type EditMessageMediaConfig struct { + BaseFile + BaseEdit + Media interface{} `json:"media"` + ParseMode string + DisableWebPagePreview bool +} + +func (config EditMessageMediaConfig) values() (url.Values, error) { + v, err := config.BaseChat.values() + if err != nil { + return v, err + } + v, err = config.BaseEdit.values() + if err != nil { + return v, err + } + if !config.UseExisting { + fileName := "" + switch mType := config.Media.(type) { + case InputMediaPhoto: + fileName = mType.Media + mType.Media = "attach://" + config.name() + config.Media = mType + case InputMediaVideo: + fileName = mType.Media + mType.Media = "attach://" + config.name() + config.Media = mType + } + config.File = fileName + } + + bytes, err := json.Marshal(config.Media) + if err != nil { + return v, err + } + v.Add("media", string(bytes)) + v.Add("parse_mode", config.ParseMode) + v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview)) + + return v, nil +} + +func (config EditMessageMediaConfig) name() string { + return "fileName" +} + +func (config EditMessageMediaConfig) method() string { + return "editMessageMedia" +} + // UserProfilePhotosConfig contains information about a // GetUserProfilePhotos request. type UserProfilePhotosConfig struct { diff --git a/helpers.go b/helpers.go index f49cbbab..725aeba5 100644 --- a/helpers.go +++ b/helpers.go @@ -572,6 +572,48 @@ func NewEditMessageReplyMarkup(chatID int64, messageID int, replyMarkup InlineKe } } +// NewEditMessageReplyMedia allows you to edit audio, document, photo, or video messages +// keyboard markup. +func NewEditMessageMedia(chatID int64, messageID int, media interface{}) EditMessageMediaConfig { + fileName := "" + switch media.(type) { + case InputMediaPhoto: + photo := media.(InputMediaPhoto) + fileName = photo.Media + case InputMediaVideo: + video := media.(InputMediaVideo) + fileName = video.Media + } + return EditMessageMediaConfig{ + BaseEdit: BaseEdit{ + ChatID: chatID, + MessageID: messageID, + }, + Media: media, + BaseFile: BaseFile{ + FileID: fileName, + UseExisting: true, + }, + } +} + +// NewEditMessageReplyMedia allows you to edit audio, document, photo, or video messages +// keyboard markup. +func NewEditMessageMediaUpload(chatID int64, messageID int, media interface{}) EditMessageMediaConfig { + return EditMessageMediaConfig{ + BaseEdit: BaseEdit{ + ChatID: chatID, + MessageID: messageID, + }, + Media: media, + BaseFile: BaseFile{ + BaseChat: BaseChat{ChatID: chatID}, + File: media, + UseExisting: false, + }, + } +} + // NewHideKeyboard hides the keyboard, with the option for being selective // or hiding for everyone. func NewHideKeyboard(selective bool) ReplyKeyboardHide {