From b8a42150a265d244418b3330085bf307d3ebadc8 Mon Sep 17 00:00:00 2001 From: AliMVP Date: Fri, 28 Sep 2018 20:28:19 +0330 Subject: [PATCH] - Added Send Animation Method --- configs.go | 41 +++++++++++++++++++++++++++++++++++++++++ helpers.go | 16 ++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/configs.go b/configs.go index 8c9c820..d16de8c 100644 --- a/configs.go +++ b/configs.go @@ -240,6 +240,47 @@ func (config ForwardConfig) method() string { return "forwardMessage" } +// AnimationConfig contains information about a SendAnimation request. +type AnimationConfig struct { + BaseFile + Caption string +} + +// Params returns a map[string]string representation of AnimationConfig. +func (config AnimationConfig) params() (map[string]string, error) { + params, _ := config.BaseFile.params() + + if config.Caption != "" { + params["caption"] = config.Caption + } + + return params, nil +} + +// Values returns a url.Values representation of AnimationConfig. +func (config AnimationConfig) values() (url.Values, error) { + v, err := config.BaseChat.values() + if err != nil { + return v, err + } + + v.Add(config.name(), config.FileID) + if config.Caption != "" { + v.Add("caption", config.Caption) + } + return v, nil +} + +// name returns the field name for the Animation. +func (config AnimationConfig) name() string { + return "animation" +} + +// method returns Telegram API method name for sending Animation. +func (config PhotoConfig) Animation() string { + return "sendAnimation" +} + // PhotoConfig contains information about a SendPhoto request. type PhotoConfig struct { BaseFile diff --git a/helpers.go b/helpers.go index d6be102..f724cf8 100644 --- a/helpers.go +++ b/helpers.go @@ -51,6 +51,22 @@ func NewForward(chatID int64, fromChatID int64, messageID int) ForwardConfig { } } +// NewAnimationUpload creates a new animation uploader. +// +// chatID is where to send it, file is a string path to the file, +// FileReader, or FileBytes. +// +// Note that you must send animated GIFs as a document. +func NewAnimationUpload(chatID int64, file interface{}) AnimationConfig { + return AnimationConfig{ + BaseFile: BaseFile{ + BaseChat: BaseChat{ChatID: chatID}, + File: file, + UseExisting: false, + }, + } +} + // NewPhotoUpload creates a new photo uploader. // // chatID is where to send it, file is a string path to the file,