Skip to content

Commit

Permalink
Make Animation Sendable
Browse files Browse the repository at this point in the history
  • Loading branch information
fullpipe committed Feb 29, 2020
1 parent bd69a13 commit 4e97ab5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions sendable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package telebot
import (
"encoding/json"
"fmt"
"path/filepath"
"strconv"
)

Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 4e97ab5

Please sign in to comment.