- Added Send Media Group Function and Helper

pull/216/head
AliMVP 7 years ago
parent 212b154115
commit 82c35cec16
  1. 57
      configs.go
  2. 11
      helpers.go

@ -1143,3 +1143,60 @@ func (config DeleteChatPhotoConfig) values() (url.Values, error) {
return v, nil return v, nil
} }
// MediaGroupConfig allows you to send a group of media.
//
// Media consist of InputMedia items (InputMediaPhoto, InputMediaVideo).
type MediaGroupConfig struct {
ChatID int64
ChannelUsername string
Media []interface{}
DisableNotification bool
ReplyToMessageID int
}
func (config MediaGroupConfig) method() string {
return "sendMediaGroup"
}
func (config MediaGroupConfig) values() (url.Values, error) {
v := url.Values{}
if config.ChannelUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.ChannelUsername)
}
bytes, err := json.Marshal(config.Media)
if err != nil {
return v, err
}
v.Add("media", string(bytes))
if config.DisableNotification {
v.Add("disable_notification", strconv.FormatBool(config.DisableNotification))
}
if config.ReplyToMessageID != 0 {
v.Add("reply_to_message_id", strconv.Itoa(config.ReplyToMessageID))
}
return v, nil
}
type InputMediaPhoto struct {
Type string
Media string
Caption string
ParseMode string
}
type InputMediaVideo struct {
Type string
Media string
Caption string
ParseMode string
Width int
Height int
Duration int
SupportsStreaming bool
}

@ -82,6 +82,17 @@ func NewPhotoShare(chatID int64, fileID string) PhotoConfig {
} }
} }
// NewMediaGroupShare shares media group.
//
// chatID is where to send it, medias is the media interface
// already uploaded.
func NewMediaGroupShare(chatID int64, medias []interface{}) MediaGroupConfig {
return MediaGroupConfig{
ChatID: chatID,
Media: medias,
}
}
// NewAudioUpload creates a new audio uploader. // NewAudioUpload creates a new audio uploader.
// //
// chatID is where to send it, file is a string path to the file, // chatID is where to send it, file is a string path to the file,