Skip to content
Open
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
87 changes: 87 additions & 0 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,93 @@ func (config DocumentConfig) files() []RequestFile {
return files
}

type InputMedia struct {
Media string json:"media"
Type string json:"type"
Caption string json:"caption"
ParseMode string json:"parse_mode"
}

func (config InputMedia) params() (map[string]string, error) {
params, _ := config.params()
params["media"] = config.Media
params["type"] = config.Type
if config.Caption != "" {
params["caption"] = config.Caption
if config.ParseMode != "" {
params["parse_mode"] = config.ParseMode
}
}

return params, nil
}

// Values returns a url.Values representation of PhotoConfig.
func (config InputMedia) values() ([]byte, error) {
// v := url.Values{}
// // if err != nil {
// // return v, err
// // }

// v.Add(config.name(), config.Media)
// v.Add("type", config.Type)
// if config.Caption != "" {
// v.Add("caption", config.Caption)
// if config.ParseMode != "" {
// v.Add("parse_mode", config.ParseMode)
// }
// }
data, err := json.Marshal(config)
if err != nil {
return data, err
}

return data, nil
}

// name returns the field name for the Photo.
func (config InputMedia) name() string {
return "media"
}

type EditMessageMediaConfig struct {
ChatID int64
ChannelUsername string
MessageID int
InlineMessageID string
ReplyMarkup *InlineKeyboardMarkup

InputMedia
}

func (EditMessageMediaConfig) method() string {
return "editMessageMedia"
}

func (edit EditMessageMediaConfig) values() (url.Values, error) {
v := url.Values{}
data, err := edit.InputMedia.values()
v.Add("media", string(data))
if edit.InlineMessageID == "" {
if edit.ChannelUsername != "" {
v.Add("chat_id", edit.ChannelUsername)
} else {
v.Add("chat_id", strconv.FormatInt(edit.ChatID, 10))
}
v.Add("message_id", strconv.Itoa(edit.MessageID))
} else {
v.Add("inline_message_id", edit.InlineMessageID)
}
if edit.ReplyMarkup != nil {
data, err := json.Marshal(edit.ReplyMarkup)
if err != nil {
return v, err
}
v.Add("reply_markup", string(data))
}
return v, err
}

// StickerConfig contains information about a SendSticker request.
type StickerConfig struct {
BaseFile
Expand Down
13 changes: 13 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ func NewInputMediaDocument(media RequestFileData) InputMediaDocument {
}
}

func NewEditMessageMedia(chatID int64, messageID int, caption string, parse_mode string, fileType string, fileID string) EditMessageMediaConfig {
return EditMessageMediaConfig{
ChatID: chatID,
MessageID: messageID,
InputMedia: InputMedia{
Type: fileType,
Media: fileID,
Caption: caption,
ParseMode: parse_mode,
},
}
}

// NewContact allows you to send a shared contact.
func NewContact(chatID int64, phoneNumber, firstName string) ContactConfig {
return ContactConfig{
Expand Down