Merge pull request #250 from fullpipe/add-animation

Add sendAnimation
pull/270/head
Ian P Badtrousers 4 years ago committed by GitHub
commit 74866a0de6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -132,6 +132,27 @@ func (v *Video) MediaFile() *File {
return &v.File
}
// Animation object represents a animation file.
type Animation struct {
File
Width int `json:"width"`
Height int `json:"height"`
Duration int `json:"duration,omitempty"`
// (Optional)
Caption string `json:"caption,omitempty"`
Thumbnail *Photo `json:"thumb,omitempty"`
MIME string `json:"mime_type,omitempty"`
FileName string `json:"file_name,omitempty"`
}
// MediaFile returns &Animation.File
func (v *Animation) MediaFile() *File {
return &v.File
}
// Voice object represents a voice note.
type Voice struct {
File

@ -87,6 +87,9 @@ type Message struct {
// For a video, information about it.
Video *Video `json:"video"`
// For a animation, information about it.
Animation *Animation `json:"animation"`
// For a contact, contact information itself.
Contact *Contact `json:"contact"`

@ -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