Make Animation Sendable

pull/250/head
Eugene Bravov 4 years ago
parent bd69a13f32
commit 4e97ab59b1
No known key found for this signature in database
GPG Key ID: B1FC4257F86BE3DD

@ -3,6 +3,7 @@ package telebot
import (
"encoding/json"
"fmt"
"path/filepath"
"strconv"
)
@ -166,6 +167,44 @@ func (v *Video) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
return msg, nil
}
// Send delivers animation through bot b to recipient.
// @see https://core.telegram.org/bots/api#sendanimation
func (a *Animation) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params := map[string]string{
"chat_id": to.Recipient(),
"caption": a.Caption,
"file_name": a.FileName,
}
if a.Duration != 0 {
params["duration"] = strconv.Itoa(a.Duration)
}
if a.Width != 0 {
params["width"] = strconv.Itoa(a.Width)
}
if a.Height != 0 {
params["height"] = strconv.Itoa(a.Height)
}
// file_name is required, without file_name GIFs sent as document
if params["file_name"] == "" && a.File.OnDisk() {
params["file_name"] = filepath.Base(a.File.FileLocal)
}
embedSendOptions(params, opt)
msg, err := b.sendObject(&a.File, "animation", params, nil)
if err != nil {
return nil, err
}
msg.Animation.File.stealRef(&a.File)
*a = *msg.Animation
a.Caption = msg.Caption
return msg, nil
}
// Send delivers media through bot b to recipient.
func (v *Voice) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params := map[string]string{

Loading…
Cancel
Save