|
|
|
@ -175,22 +175,33 @@ var (
|
|
|
|
|
//
|
|
|
|
|
// b.Handle("/ban", onBan, middleware.Whitelist(ids...))
|
|
|
|
|
func (b *Bot) Handle(endpoint interface{}, h HandlerFunc, m ...MiddlewareFunc) {
|
|
|
|
|
end := extractEndpoint(endpoint)
|
|
|
|
|
if end == "" {
|
|
|
|
|
panic("telebot: unsupported endpoint")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(b.group.middleware) > 0 {
|
|
|
|
|
m = appendMiddleware(b.group.middleware, m)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handler := func(c Context) error {
|
|
|
|
|
b.handlers[end] = func(c Context) error {
|
|
|
|
|
return applyMiddleware(h, m...)(c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch end := endpoint.(type) {
|
|
|
|
|
case string:
|
|
|
|
|
b.handlers[end] = handler
|
|
|
|
|
case CallbackEndpoint:
|
|
|
|
|
b.handlers[end.CallbackUnique()] = handler
|
|
|
|
|
default:
|
|
|
|
|
panic("telebot: unsupported endpoint")
|
|
|
|
|
// Trigger executes the registered handler by the endpoint.
|
|
|
|
|
func (b *Bot) Trigger(endpoint interface{}, c Context) error {
|
|
|
|
|
end := extractEndpoint(endpoint)
|
|
|
|
|
if end == "" {
|
|
|
|
|
return fmt.Errorf("telebot: unsupported endpoint")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handler, ok := b.handlers[end]
|
|
|
|
|
if !ok {
|
|
|
|
|
return fmt.Errorf("telebot: no handler found for given endpoint")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return handler(c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start brings bot into motion by consuming incoming
|
|
|
|
@ -400,15 +411,15 @@ func (b *Bot) Forward(to Recipient, msg Editable, opts ...interface{}) (*Message
|
|
|
|
|
return extractMessage(data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ForwardMessages method forwards multiple messages of any kind.
|
|
|
|
|
// ForwardMany method forwards multiple messages of any kind.
|
|
|
|
|
// If some of the specified messages can't be found or forwarded, they are skipped.
|
|
|
|
|
// Service messages and messages with protected content can't be forwarded.
|
|
|
|
|
// Album grouping is kept for forwarded messages.
|
|
|
|
|
func (b *Bot) ForwardMessages(to Recipient, msgs []Editable, opts ...*SendOptions) ([]Message, error) {
|
|
|
|
|
func (b *Bot) ForwardMany(to Recipient, msgs []Editable, opts ...*SendOptions) ([]Message, error) {
|
|
|
|
|
if to == nil {
|
|
|
|
|
return nil, ErrBadRecipient
|
|
|
|
|
}
|
|
|
|
|
return b.forwardCopyMessages(to, msgs, "forwardMessages", opts...)
|
|
|
|
|
return b.forwardCopyMany(to, msgs, "forwardMessages", opts...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy behaves just like Forward() but the copied message doesn't have a link to the original message (see Bots API).
|
|
|
|
@ -437,18 +448,18 @@ func (b *Bot) Copy(to Recipient, msg Editable, options ...interface{}) (*Message
|
|
|
|
|
return extractMessage(data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CopyMessages this method makes a copy of messages of any kind.
|
|
|
|
|
// CopyMany this method makes a copy of messages of any kind.
|
|
|
|
|
// If some of the specified messages can't be found or copied, they are skipped.
|
|
|
|
|
// Service messages, giveaway messages, giveaway winners messages, and
|
|
|
|
|
// invoice messages can't be copied. A quiz poll can be copied only if the value of the field
|
|
|
|
|
// correct_option_id is known to the bot. The method is analogous
|
|
|
|
|
// to the method forwardMessages, but the copied messages don't have a link to the original message.
|
|
|
|
|
// Album grouping is kept for copied messages.
|
|
|
|
|
func (b *Bot) CopyMessages(to Recipient, msgs []Editable, opts ...*SendOptions) ([]Message, error) {
|
|
|
|
|
func (b *Bot) CopyMany(to Recipient, msgs []Editable, opts ...*SendOptions) ([]Message, error) {
|
|
|
|
|
if to == nil {
|
|
|
|
|
return nil, ErrBadRecipient
|
|
|
|
|
}
|
|
|
|
|
return b.forwardCopyMessages(to, msgs, "copyMessages", opts...)
|
|
|
|
|
return b.forwardCopyMany(to, msgs, "copyMessages", opts...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Edit is magic, it lets you change already sent message.
|
|
|
|
@ -693,11 +704,10 @@ func (b *Bot) Delete(msg Editable) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteMessages deletes multiple messages simultaneously.
|
|
|
|
|
// DeleteMany deletes multiple messages simultaneously.
|
|
|
|
|
// If some of the specified messages can't be found, they are skipped.
|
|
|
|
|
func (b *Bot) DeleteMessages(msgs []Editable) error {
|
|
|
|
|
func (b *Bot) DeleteMany(msgs []Editable) error {
|
|
|
|
|
params := make(map[string]string)
|
|
|
|
|
|
|
|
|
|
embedMessages(params, msgs)
|
|
|
|
|
|
|
|
|
|
_, err := b.Raw("deleteMessages", params)
|
|
|
|
@ -1260,3 +1270,13 @@ func (b *Bot) botInfo(language, key string) (*BotInfo, error) {
|
|
|
|
|
}
|
|
|
|
|
return resp.Result, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func extractEndpoint(endpoint interface{}) string {
|
|
|
|
|
switch end := endpoint.(type) {
|
|
|
|
|
case string:
|
|
|
|
|
return end
|
|
|
|
|
case CallbackEndpoint:
|
|
|
|
|
return end.CallbackUnique()
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|