Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}

Expand All @@ -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{}),
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
53 changes: 53 additions & 0 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 42 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down