From 82c35cec16b3ef1fba03f2127c3a175b61a8a401 Mon Sep 17 00:00:00 2001 From: AliMVP Date: Sat, 26 May 2018 23:07:53 +0430 Subject: [PATCH] - Added Send Media Group Function and Helper --- configs.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ helpers.go | 11 +++++++++++ 2 files changed, 68 insertions(+) diff --git a/configs.go b/configs.go index 574b3dd..80db4fe 100644 --- a/configs.go +++ b/configs.go @@ -1143,3 +1143,60 @@ func (config DeleteChatPhotoConfig) values() (url.Values, error) { 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 +} \ No newline at end of file diff --git a/helpers.go b/helpers.go index b5480ea..0acaada 100644 --- a/helpers.go +++ b/helpers.go @@ -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. // // chatID is where to send it, file is a string path to the file,