From 0a7ea40b721bc94a6f0284f9efbf9986160993c8 Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Thu, 14 Dec 2017 12:33:44 +0500 Subject: [PATCH] :sparkles: Added SendMediaGroup method --- send_media_group.go | 34 ++++++++++++++++++++++++++++++++++ types.go | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 send_media_group.go diff --git a/send_media_group.go b/send_media_group.go new file mode 100644 index 0000000..67a50d9 --- /dev/null +++ b/send_media_group.go @@ -0,0 +1,34 @@ +package telegram + +import ( + "strconv" + + json "github.com/pquerna/ffjson/ffjson" + http "github.com/valyala/fasthttp" +) + +// SendMediaGroup send a group of photos or videos as an album. On success, an array of the sent +// Messages is returned. +func (bot *Bot) SendMediaGroup(chatID int64, media []InputFile, replyToMessageID int, disableNotification bool) ([]*Message, error) { + args := http.AcquireArgs() + args.Add("chat_id", strconv.FormatInt(chatID, 10)) + args.Add("disable_notification", strconv.FormatBool(disableNotification)) + + if replyToMessageID != 0 { + args.Add("reply_to_message_id", strconv.Itoa(replyToMessageID)) + } + + dst, err := json.Marshal(media) + if err != nil { + return nil, err + } + + resp, err := bot.request(dst, "sendMediaGroup", args) + if err != nil { + return nil, err + } + + var data []*Message + err = json.Unmarshal(*resp.Result, &data) + return data, err +} diff --git a/types.go b/types.go index fb18028..9639f85 100644 --- a/types.go +++ b/types.go @@ -39,6 +39,8 @@ const ( MimePDF = "application/pdf" MimeZIP = "application/zip" + PrefixAttach = "attach://" + StatusAdministrator = "administrator" StatusCreator = "creator" StatusKicked = "kicked"