2017-11-18 13:06:20 +00:00
|
|
|
package telebot
|
|
|
|
|
2017-11-25 14:22:13 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
2017-11-18 18:16:16 +00:00
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
// Media is a generic type for all kinds of media that includes File.
|
|
|
|
type Media interface {
|
|
|
|
// MediaType returns string-represented media type.
|
|
|
|
MediaType() string
|
2017-11-25 14:22:13 +00:00
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
// MediaFile returns a pointer to the media file.
|
2017-11-25 14:22:13 +00:00
|
|
|
MediaFile() *File
|
2017-11-18 18:16:16 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
// InputMedia represents a composite InputMedia struct that is
|
|
|
|
// used by Telebot in sending and editing media methods.
|
|
|
|
type InputMedia struct {
|
2022-02-04 18:51:15 +00:00
|
|
|
Type string `json:"type"`
|
|
|
|
Media string `json:"media"`
|
|
|
|
Caption string `json:"caption"`
|
|
|
|
Thumbnail string `json:"thumb,omitempty"`
|
|
|
|
ParseMode string `json:"parse_mode,omitempty"`
|
|
|
|
Entities Entities `json:"caption_entities,omitempty"`
|
|
|
|
Width int `json:"width,omitempty"`
|
|
|
|
Height int `json:"height,omitempty"`
|
|
|
|
Duration int `json:"duration,omitempty"`
|
|
|
|
Title string `json:"title,omitempty"`
|
|
|
|
Performer string `json:"performer,omitempty"`
|
|
|
|
Streaming bool `json:"supports_streaming,omitempty"`
|
|
|
|
DisableTypeDetection bool `json:"disable_content_type_detection,omitempty"`
|
2021-11-07 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inputtable is a generic type for all kinds of media you
|
|
|
|
// can put into an album.
|
|
|
|
type Inputtable interface {
|
|
|
|
Media
|
|
|
|
|
|
|
|
// InputMedia returns already marshalled InputMedia type
|
|
|
|
// ready to be used in sending and editing media methods.
|
|
|
|
InputMedia() InputMedia
|
|
|
|
}
|
|
|
|
|
|
|
|
// Album lets you group multiple media into a single message.
|
|
|
|
type Album []Inputtable
|
|
|
|
|
2017-11-18 18:16:16 +00:00
|
|
|
// Photo object represents a single photo file.
|
2017-11-18 13:06:20 +00:00
|
|
|
type Photo struct {
|
|
|
|
File
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
Caption string `json:"caption,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-25 14:22:13 +00:00
|
|
|
type photoSize struct {
|
|
|
|
File
|
2020-06-19 20:34:37 +00:00
|
|
|
|
2017-11-25 14:22:13 +00:00
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
Caption string `json:"caption,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (p *Photo) MediaType() string {
|
|
|
|
return "photo"
|
|
|
|
}
|
|
|
|
|
2017-11-25 14:22:13 +00:00
|
|
|
func (p *Photo) MediaFile() *File {
|
|
|
|
return &p.File
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (p *Photo) InputMedia() InputMedia {
|
|
|
|
return InputMedia{
|
2021-11-07 18:42:45 +00:00
|
|
|
Type: p.MediaType(),
|
|
|
|
Caption: p.Caption,
|
2021-11-07 16:28:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-19 15:16:39 +00:00
|
|
|
// UnmarshalJSON is custom unmarshaller required to abstract
|
|
|
|
// away the hassle of treating different thumbnail sizes.
|
2020-06-19 20:34:37 +00:00
|
|
|
// Instead, Telebot chooses the hi-res one and just sticks to it.
|
2017-11-19 15:16:39 +00:00
|
|
|
//
|
|
|
|
// I really do find it a beautiful solution.
|
2021-11-07 16:28:21 +00:00
|
|
|
func (p *Photo) UnmarshalJSON(data []byte) error {
|
2017-11-18 18:16:16 +00:00
|
|
|
var hq photoSize
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
if data[0] == '{' {
|
|
|
|
if err := json.Unmarshal(data, &hq); err != nil {
|
2017-11-18 18:16:16 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var sizes []photoSize
|
2021-11-07 16:28:21 +00:00
|
|
|
if err := json.Unmarshal(data, &sizes); err != nil {
|
2017-11-18 18:16:16 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
hq = sizes[len(sizes)-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
p.File = hq.File
|
|
|
|
p.Width = hq.Width
|
|
|
|
p.Height = hq.Height
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-18 13:06:20 +00:00
|
|
|
// Audio object represents an audio file.
|
|
|
|
type Audio struct {
|
|
|
|
File
|
|
|
|
|
2017-11-25 14:22:13 +00:00
|
|
|
Duration int `json:"duration,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
|
2017-11-18 14:41:23 +00:00
|
|
|
// (Optional)
|
|
|
|
Caption string `json:"caption,omitempty"`
|
2019-12-22 05:07:00 +00:00
|
|
|
Thumbnail *Photo `json:"thumb,omitempty"`
|
2017-11-18 14:41:23 +00:00
|
|
|
Title string `json:"title,omitempty"`
|
|
|
|
Performer string `json:"performer,omitempty"`
|
|
|
|
MIME string `json:"mime_type,omitempty"`
|
2019-09-30 15:57:54 +00:00
|
|
|
FileName string `json:"file_name,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (a *Audio) MediaType() string {
|
|
|
|
return "audio"
|
|
|
|
}
|
|
|
|
|
2019-02-20 06:11:21 +00:00
|
|
|
func (a *Audio) MediaFile() *File {
|
2021-11-07 16:28:21 +00:00
|
|
|
a.fileName = a.FileName
|
2019-02-20 06:11:21 +00:00
|
|
|
return &a.File
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (a *Audio) InputMedia() InputMedia {
|
|
|
|
return InputMedia{
|
2021-11-07 18:42:45 +00:00
|
|
|
Type: a.MediaType(),
|
|
|
|
Caption: a.Caption,
|
|
|
|
Duration: a.Duration,
|
|
|
|
Title: a.Title,
|
|
|
|
Performer: a.Performer,
|
2021-11-07 16:28:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-18 13:06:20 +00:00
|
|
|
// Document object represents a general file (as opposed to Photo or Audio).
|
|
|
|
// Telegram users can send files of any type of up to 1.5 GB in size.
|
|
|
|
type Document struct {
|
|
|
|
File
|
|
|
|
|
2017-11-18 14:41:23 +00:00
|
|
|
// (Optional)
|
2022-02-04 18:51:15 +00:00
|
|
|
Thumbnail *Photo `json:"thumb,omitempty"`
|
|
|
|
Caption string `json:"caption,omitempty"`
|
|
|
|
MIME string `json:"mime_type"`
|
|
|
|
FileName string `json:"file_name,omitempty"`
|
|
|
|
DisableTypeDetection bool `json:"disable_content_type_detection,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (d *Document) MediaType() string {
|
|
|
|
return "document"
|
|
|
|
}
|
|
|
|
|
2019-02-20 06:11:21 +00:00
|
|
|
func (d *Document) MediaFile() *File {
|
2021-11-07 16:28:21 +00:00
|
|
|
d.fileName = d.FileName
|
2019-02-20 06:11:21 +00:00
|
|
|
return &d.File
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (d *Document) InputMedia() InputMedia {
|
|
|
|
return InputMedia{
|
2022-02-04 18:51:15 +00:00
|
|
|
Type: d.MediaType(),
|
|
|
|
Caption: d.Caption,
|
|
|
|
DisableTypeDetection: d.DisableTypeDetection,
|
2021-11-07 16:28:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-18 14:41:23 +00:00
|
|
|
// Video object represents a video file.
|
|
|
|
type Video struct {
|
2017-11-25 14:22:13 +00:00
|
|
|
File
|
2017-11-18 13:06:20 +00:00
|
|
|
|
2020-06-19 20:34:37 +00:00
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
2017-11-25 14:22:13 +00:00
|
|
|
Duration int `json:"duration,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
|
2017-11-18 14:41:23 +00:00
|
|
|
// (Optional)
|
2021-11-07 18:42:45 +00:00
|
|
|
Caption string `json:"caption,omitempty"`
|
|
|
|
Thumbnail *Photo `json:"thumb,omitempty"`
|
|
|
|
Streaming bool `json:"supports_streaming,omitempty"`
|
|
|
|
MIME string `json:"mime_type,omitempty"`
|
|
|
|
FileName string `json:"file_name,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (v *Video) MediaType() string {
|
|
|
|
return "video"
|
|
|
|
}
|
|
|
|
|
2017-11-25 14:22:13 +00:00
|
|
|
func (v *Video) MediaFile() *File {
|
2021-11-07 16:28:21 +00:00
|
|
|
v.fileName = v.FileName
|
2017-11-25 14:22:13 +00:00
|
|
|
return &v.File
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (v *Video) InputMedia() InputMedia {
|
|
|
|
return InputMedia{
|
2021-11-07 18:42:45 +00:00
|
|
|
Type: v.MediaType(),
|
|
|
|
Caption: v.Caption,
|
|
|
|
Width: v.Width,
|
|
|
|
Height: v.Height,
|
|
|
|
Duration: v.Duration,
|
|
|
|
Streaming: v.Streaming,
|
2021-11-07 16:28:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 12:33:48 +00:00
|
|
|
// Animation object represents a animation file.
|
|
|
|
type Animation struct {
|
|
|
|
File
|
|
|
|
|
2020-06-19 20:34:37 +00:00
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
2020-02-29 12:33:48 +00:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (a *Animation) MediaType() string {
|
|
|
|
return "animation"
|
|
|
|
}
|
|
|
|
|
2020-04-05 17:23:51 +00:00
|
|
|
func (a *Animation) MediaFile() *File {
|
2021-11-07 16:28:21 +00:00
|
|
|
a.fileName = a.FileName
|
2020-04-05 17:23:51 +00:00
|
|
|
return &a.File
|
2020-02-29 12:33:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (a *Animation) InputMedia() InputMedia {
|
|
|
|
return InputMedia{
|
2021-11-07 18:42:45 +00:00
|
|
|
Type: a.MediaType(),
|
|
|
|
Caption: a.Caption,
|
|
|
|
Width: a.Width,
|
|
|
|
Height: a.Height,
|
|
|
|
Duration: a.Duration,
|
2021-11-07 16:28:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-18 14:41:23 +00:00
|
|
|
// Voice object represents a voice note.
|
|
|
|
type Voice struct {
|
|
|
|
File
|
2017-11-18 13:06:20 +00:00
|
|
|
|
2017-11-18 14:41:23 +00:00
|
|
|
Duration int `json:"duration"`
|
2017-11-18 13:06:20 +00:00
|
|
|
|
2017-11-18 14:41:23 +00:00
|
|
|
// (Optional)
|
2021-04-07 07:41:50 +00:00
|
|
|
Caption string `json:"caption,omitempty"`
|
|
|
|
MIME string `json:"mime_type,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (v *Voice) MediaType() string {
|
|
|
|
return "voice"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Voice) MediaFile() *File {
|
|
|
|
return &v.File
|
|
|
|
}
|
|
|
|
|
|
|
|
// VideoNote represents a video message.
|
2017-11-18 13:06:20 +00:00
|
|
|
type VideoNote struct {
|
|
|
|
File
|
2021-11-07 16:28:21 +00:00
|
|
|
|
2017-11-18 13:06:20 +00:00
|
|
|
Duration int `json:"duration"`
|
|
|
|
|
2017-11-18 14:41:23 +00:00
|
|
|
// (Optional)
|
|
|
|
Thumbnail *Photo `json:"thumb,omitempty"`
|
2018-09-14 09:26:33 +00:00
|
|
|
Length int `json:"length,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
func (v *VideoNote) MediaType() string {
|
2021-11-07 17:31:43 +00:00
|
|
|
return "videoNote"
|
2021-11-07 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VideoNote) MediaFile() *File {
|
|
|
|
return &v.File
|
|
|
|
}
|
|
|
|
|
2021-11-07 17:14:44 +00:00
|
|
|
// Sticker object represents a WebP image, so-called sticker.
|
|
|
|
type Sticker struct {
|
|
|
|
File
|
2022-10-05 12:07:13 +00:00
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
Animated bool `json:"is_animated"`
|
|
|
|
Video bool `json:"is_video"`
|
|
|
|
Thumbnail *Photo `json:"thumb"`
|
|
|
|
Emoji string `json:"emoji"`
|
|
|
|
SetName string `json:"set_name"`
|
|
|
|
MaskPosition *MaskPosition `json:"mask_position"`
|
|
|
|
PremiumAnimation *File `json:"premium_animation"`
|
2021-11-07 17:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Sticker) MediaType() string {
|
|
|
|
return "sticker"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Sticker) MediaFile() *File {
|
|
|
|
return &s.File
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:28:21 +00:00
|
|
|
// Contact object represents a contact to Telegram user.
|
2017-11-18 13:06:20 +00:00
|
|
|
type Contact struct {
|
|
|
|
PhoneNumber string `json:"phone_number"`
|
|
|
|
FirstName string `json:"first_name"`
|
2017-11-18 14:41:23 +00:00
|
|
|
|
|
|
|
// (Optional)
|
|
|
|
LastName string `json:"last_name"`
|
2021-12-17 12:58:08 +00:00
|
|
|
UserID int64 `json:"user_id,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Location object represents geographic position.
|
|
|
|
type Location struct {
|
2021-05-23 16:55:49 +00:00
|
|
|
Lat float32 `json:"latitude"`
|
|
|
|
Lng float32 `json:"longitude"`
|
|
|
|
HorizontalAccuracy *float32 `json:"horizontal_accuracy,omitempty"`
|
|
|
|
Heading int `json:"heading,omitempty"`
|
|
|
|
AlertRadius int `json:"proximity_alert_radius,omitempty"`
|
|
|
|
|
|
|
|
// Period in seconds for which the location will be updated
|
|
|
|
// (see Live Locations, should be between 60 and 86400.)
|
2017-11-26 09:15:11 +00:00
|
|
|
LivePeriod int `json:"live_period,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Venue object represents a venue location with name, address and
|
|
|
|
// optional foursquare ID.
|
|
|
|
type Venue struct {
|
2017-11-18 14:41:23 +00:00
|
|
|
Location Location `json:"location"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Address string `json:"address"`
|
|
|
|
|
|
|
|
// (Optional)
|
2021-05-23 16:55:49 +00:00
|
|
|
FoursquareID string `json:"foursquare_id,omitempty"`
|
|
|
|
FoursquareType string `json:"foursquare_type,omitempty"`
|
|
|
|
GooglePlaceID string `json:"google_place_id,omitempty"`
|
|
|
|
GooglePlaceType string `json:"google_place_type,omitempty"`
|
2017-11-18 13:06:20 +00:00
|
|
|
}
|
2020-04-25 12:31:16 +00:00
|
|
|
|
2020-04-26 16:33:13 +00:00
|
|
|
// Dice object represents a dice with a random value
|
|
|
|
// from 1 to 6 for currently supported base emoji.
|
2020-04-25 12:31:16 +00:00
|
|
|
type Dice struct {
|
2020-04-25 12:59:53 +00:00
|
|
|
Type DiceType `json:"emoji"`
|
|
|
|
Value int `json:"value"`
|
2020-04-25 12:31:16 +00:00
|
|
|
}
|
2022-10-05 21:45:27 +00:00
|
|
|
|
|
|
|
// DiceType defines dice types.
|
|
|
|
type DiceType string
|
|
|
|
|
|
|
|
var (
|
|
|
|
Cube = &Dice{Type: "🎲"}
|
|
|
|
Dart = &Dice{Type: "🎯"}
|
|
|
|
Ball = &Dice{Type: "🏀"}
|
|
|
|
Goal = &Dice{Type: "⚽"}
|
|
|
|
Slot = &Dice{Type: "🎰"}
|
|
|
|
Bowl = &Dice{Type: "🎳"}
|
|
|
|
)
|