|
|
|
@ -276,8 +276,8 @@ func (b *Bot) ProcessUpdate(upd Update) {
|
|
|
|
|
match := cmdRx.FindAllStringSubmatch(m.Text, -1)
|
|
|
|
|
if match != nil {
|
|
|
|
|
// Syntax: "</command>@<bot> <payload>"
|
|
|
|
|
|
|
|
|
|
command, botName := match[0][1], match[0][3]
|
|
|
|
|
|
|
|
|
|
if botName != "" && !strings.EqualFold(b.Me.Username, botName) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -301,11 +301,30 @@ func (b *Bot) ProcessUpdate(upd Update) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.Contact != nil {
|
|
|
|
|
b.handle(OnContact, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if m.Location != nil {
|
|
|
|
|
b.handle(OnLocation, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if m.Venue != nil {
|
|
|
|
|
b.handle(OnVenue, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if m.Game != nil {
|
|
|
|
|
b.handle(OnGame, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if m.Dice != nil {
|
|
|
|
|
b.handle(OnDice, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if m.Invoice != nil {
|
|
|
|
|
b.handle(OnInvoice, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.Payment != nil {
|
|
|
|
|
b.handle(OnPayment, c)
|
|
|
|
|
return
|
|
|
|
@ -526,16 +545,6 @@ func (b *Bot) handleMedia(c Context) bool {
|
|
|
|
|
fired = b.handle(OnVideo, c)
|
|
|
|
|
case m.VideoNote != nil:
|
|
|
|
|
fired = b.handle(OnVideoNote, c)
|
|
|
|
|
case m.Contact != nil:
|
|
|
|
|
fired = b.handle(OnContact, c)
|
|
|
|
|
case m.Location != nil:
|
|
|
|
|
fired = b.handle(OnLocation, c)
|
|
|
|
|
case m.Venue != nil:
|
|
|
|
|
fired = b.handle(OnVenue, c)
|
|
|
|
|
case m.Game != nil:
|
|
|
|
|
fired = b.handle(OnGame, c)
|
|
|
|
|
case m.Dice != nil:
|
|
|
|
|
fired = b.handle(OnDice, c)
|
|
|
|
|
default:
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
@ -585,6 +594,7 @@ func (b *Bot) SendAlbum(to Recipient, a Album, opts ...interface{}) ([]Message,
|
|
|
|
|
return nil, ErrBadRecipient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendOpts := extractOptions(opts)
|
|
|
|
|
media := make([]string, len(a))
|
|
|
|
|
files := make(map[string]File)
|
|
|
|
|
|
|
|
|
@ -607,41 +617,11 @@ func (b *Bot) SendAlbum(to Recipient, a Album, opts ...interface{}) ([]Message,
|
|
|
|
|
return nil, errors.Errorf("telebot: album entry #%d does not exist", i)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch y := x.(type) {
|
|
|
|
|
case *Photo:
|
|
|
|
|
data, _ = json.Marshal(struct {
|
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
Media string `json:"media"`
|
|
|
|
|
Caption string `json:"caption,omitempty"`
|
|
|
|
|
ParseMode ParseMode `json:"parse_mode,omitempty"`
|
|
|
|
|
}{
|
|
|
|
|
Type: "photo",
|
|
|
|
|
Media: repr,
|
|
|
|
|
Caption: y.Caption,
|
|
|
|
|
ParseMode: y.ParseMode,
|
|
|
|
|
})
|
|
|
|
|
case *Video:
|
|
|
|
|
data, _ = json.Marshal(struct {
|
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
Caption string `json:"caption"`
|
|
|
|
|
Media string `json:"media"`
|
|
|
|
|
Width int `json:"width,omitempty"`
|
|
|
|
|
Height int `json:"height,omitempty"`
|
|
|
|
|
Duration int `json:"duration,omitempty"`
|
|
|
|
|
SupportsStreaming bool `json:"supports_streaming,omitempty"`
|
|
|
|
|
}{
|
|
|
|
|
Type: "video",
|
|
|
|
|
Caption: y.Caption,
|
|
|
|
|
Media: repr,
|
|
|
|
|
Width: y.Width,
|
|
|
|
|
Height: y.Height,
|
|
|
|
|
Duration: y.Duration,
|
|
|
|
|
SupportsStreaming: y.SupportsStreaming,
|
|
|
|
|
})
|
|
|
|
|
default:
|
|
|
|
|
return nil, errors.Errorf("telebot: album entry #%d is not valid", i)
|
|
|
|
|
}
|
|
|
|
|
im := x.InputMedia()
|
|
|
|
|
im.Media = repr
|
|
|
|
|
im.ParseMode = sendOpts.ParseMode
|
|
|
|
|
|
|
|
|
|
data, _ = json.Marshal(im)
|
|
|
|
|
media[i] = string(data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -649,8 +629,6 @@ func (b *Bot) SendAlbum(to Recipient, a Album, opts ...interface{}) ([]Message,
|
|
|
|
|
"chat_id": to.Recipient(),
|
|
|
|
|
"media": "[" + strings.Join(media, ",") + "]",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendOpts := extractOptions(opts)
|
|
|
|
|
b.embedSendOptions(params, sendOpts)
|
|
|
|
|
|
|
|
|
|
data, err := b.sendFiles("sendMediaGroup", files, params)
|
|
|
|
@ -769,7 +747,7 @@ func (b *Bot) Edit(msg Editable, what interface{}, opts ...interface{}) (*Messag
|
|
|
|
|
switch v := what.(type) {
|
|
|
|
|
case *ReplyMarkup:
|
|
|
|
|
return b.EditReplyMarkup(msg, v)
|
|
|
|
|
case InputMedia:
|
|
|
|
|
case Inputtable:
|
|
|
|
|
return b.EditMedia(msg, v, opts...)
|
|
|
|
|
case string:
|
|
|
|
|
method = "editMessageText"
|
|
|
|
@ -889,14 +867,14 @@ func (b *Bot) EditCaption(msg Editable, caption string, opts ...interface{}) (*M
|
|
|
|
|
// b.EditMedia(m, &tele.Photo{File: tele.FromDisk("chicken.jpg")})
|
|
|
|
|
// b.EditMedia(m, &tele.Video{File: tele.FromURL("http://video.mp4")})
|
|
|
|
|
//
|
|
|
|
|
func (b *Bot) EditMedia(msg Editable, media InputMedia, opts ...interface{}) (*Message, error) {
|
|
|
|
|
func (b *Bot) EditMedia(msg Editable, media Inputtable, opts ...interface{}) (*Message, error) {
|
|
|
|
|
var (
|
|
|
|
|
repr string
|
|
|
|
|
thumb *Photo
|
|
|
|
|
|
|
|
|
|
thumbName = "thumb"
|
|
|
|
|
file = media.MediaFile()
|
|
|
|
|
files = make(map[string]File)
|
|
|
|
|
|
|
|
|
|
thumb *Photo
|
|
|
|
|
thumbName = "thumb"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
switch {
|
|
|
|
@ -915,76 +893,18 @@ func (b *Bot) EditMedia(msg Editable, media InputMedia, opts ...interface{}) (*M
|
|
|
|
|
repr = "attach://" + s
|
|
|
|
|
files[s] = *file
|
|
|
|
|
default:
|
|
|
|
|
return nil, errors.Errorf("telebot: can't edit media, it does not exist")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type FileJSON struct {
|
|
|
|
|
// All types.
|
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
Caption string `json:"caption"`
|
|
|
|
|
Media string `json:"media"`
|
|
|
|
|
ParseMode ParseMode `json:"parse_mode,omitempty"`
|
|
|
|
|
|
|
|
|
|
// Video.
|
|
|
|
|
Width int `json:"width,omitempty"`
|
|
|
|
|
Height int `json:"height,omitempty"`
|
|
|
|
|
SupportsStreaming bool `json:"supports_streaming,omitempty"`
|
|
|
|
|
|
|
|
|
|
// Video and audio.
|
|
|
|
|
Duration int `json:"duration,omitempty"`
|
|
|
|
|
|
|
|
|
|
// Document.
|
|
|
|
|
FileName string `json:"file_name"`
|
|
|
|
|
|
|
|
|
|
// Document, video and audio.
|
|
|
|
|
Thumbnail string `json:"thumb,omitempty"`
|
|
|
|
|
MIME string `json:"mime_type,omitempty"`
|
|
|
|
|
|
|
|
|
|
// Audio.
|
|
|
|
|
Title string `json:"title,omitempty"`
|
|
|
|
|
Performer string `json:"performer,omitempty"`
|
|
|
|
|
return nil, errors.Errorf("telebot: cannot edit media, it does not exist")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := &FileJSON{Media: repr}
|
|
|
|
|
|
|
|
|
|
switch m := media.(type) {
|
|
|
|
|
case *Photo:
|
|
|
|
|
result.Type = "photo"
|
|
|
|
|
result.Caption = m.Caption
|
|
|
|
|
case *Video:
|
|
|
|
|
result.Type = "video"
|
|
|
|
|
result.Caption = m.Caption
|
|
|
|
|
result.Width = m.Width
|
|
|
|
|
result.Height = m.Height
|
|
|
|
|
result.Duration = m.Duration
|
|
|
|
|
result.SupportsStreaming = m.SupportsStreaming
|
|
|
|
|
result.MIME = m.MIME
|
|
|
|
|
thumb = m.Thumbnail
|
|
|
|
|
case *Document:
|
|
|
|
|
result.Type = "document"
|
|
|
|
|
result.Caption = m.Caption
|
|
|
|
|
result.FileName = m.FileName
|
|
|
|
|
result.MIME = m.MIME
|
|
|
|
|
thumb = m.Thumbnail
|
|
|
|
|
case *Audio:
|
|
|
|
|
result.Type = "audio"
|
|
|
|
|
result.Caption = m.Caption
|
|
|
|
|
result.Duration = m.Duration
|
|
|
|
|
result.MIME = m.MIME
|
|
|
|
|
result.Title = m.Title
|
|
|
|
|
result.Performer = m.Performer
|
|
|
|
|
thumb = m.Thumbnail
|
|
|
|
|
case *Document:
|
|
|
|
|
thumb = m.Thumbnail
|
|
|
|
|
case *Animation:
|
|
|
|
|
result.Type = "animation"
|
|
|
|
|
result.Caption = m.Caption
|
|
|
|
|
result.Width = m.Width
|
|
|
|
|
result.Height = m.Height
|
|
|
|
|
result.Duration = m.Duration
|
|
|
|
|
result.MIME = m.MIME
|
|
|
|
|
result.FileName = m.FileName
|
|
|
|
|
thumb = m.Thumbnail
|
|
|
|
|
default:
|
|
|
|
|
return nil, errors.Errorf("telebot: media entry is not valid")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msgID, chatID := msg.MessageSig()
|
|
|
|
@ -993,15 +913,16 @@ func (b *Bot) EditMedia(msg Editable, media InputMedia, opts ...interface{}) (*M
|
|
|
|
|
sendOpts := extractOptions(opts)
|
|
|
|
|
b.embedSendOptions(params, sendOpts)
|
|
|
|
|
|
|
|
|
|
if sendOpts != nil {
|
|
|
|
|
result.ParseMode = params["parse_mode"]
|
|
|
|
|
}
|
|
|
|
|
im := media.InputMedia()
|
|
|
|
|
im.Media = repr
|
|
|
|
|
im.ParseMode = sendOpts.ParseMode
|
|
|
|
|
|
|
|
|
|
if thumb != nil {
|
|
|
|
|
result.Thumbnail = "attach://" + thumbName
|
|
|
|
|
im.Thumbnail = "attach://" + thumbName
|
|
|
|
|
files[thumbName] = *thumb.MediaFile()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data, _ := json.Marshal(result)
|
|
|
|
|
data, _ := json.Marshal(im)
|
|
|
|
|
params["media"] = string(data)
|
|
|
|
|
|
|
|
|
|
if chatID == 0 { // if inline message
|
|
|
|
|