bot: implement Trigger function (#687)

* bot: trigger init

* bot: add execution of registered handlers in trigger func
pull/689/head
Nash-Well 4 months ago committed by GitHub
parent a26ba9f0bd
commit 77f77a6840
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1260,3 +1260,25 @@ func (b *Bot) botInfo(language, key string) (*BotInfo, error) {
}
return resp.Result, nil
}
// Trigger executes the registered handler by the endpoint.
func (b *Bot) Trigger(endpoint any, c Context) error {
var (
ok bool
handler HandlerFunc
)
switch end := endpoint.(type) {
case string:
handler, ok = b.handlers[end]
case CallbackEndpoint:
handler, ok = b.handlers[end.CallbackUnique()]
default:
return fmt.Errorf("telebot: unsupported endpoint")
}
if !ok {
return fmt.Errorf("telebot: no handler registered for provided endpoint")
}
return handler(c)
}

Loading…
Cancel
Save