(new): rich message support
(fix): runtime reliability (tests): regression coverage (doc): v1.1 release notes
This commit is contained in:
+27
-1
@@ -16,6 +16,8 @@ const (
|
||||
HandlerCommandKind HandlerEventKind = "command"
|
||||
// HandlerMessageKind identifies a message fallback handler.
|
||||
HandlerMessageKind HandlerEventKind = "message"
|
||||
// HandlerMiddlewareKind identifies middleware execution.
|
||||
HandlerMiddlewareKind HandlerEventKind = "middleware"
|
||||
// HandlerPayloadKind identifies a callback payload handler.
|
||||
HandlerPayloadKind HandlerEventKind = "payload"
|
||||
// HandlerUpdateKind identifies a generic update handler.
|
||||
@@ -41,6 +43,24 @@ type Event interface {
|
||||
isEvent()
|
||||
}
|
||||
|
||||
func emitContextError(ctx *MessageContext, event ErrorEvent) {
|
||||
if ctx == nil {
|
||||
return
|
||||
}
|
||||
if ctx.Logger != nil {
|
||||
ctx.Logger.Errorln(event.Err)
|
||||
}
|
||||
if ctx.observer == nil {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if recovered := recover(); recovered != nil && ctx.Logger != nil {
|
||||
ctx.Logger.Errorln(fmt.Sprintf("panic in observer: %v", recovered))
|
||||
}
|
||||
}()
|
||||
ctx.observer.OnError(ctx.Context(), event)
|
||||
}
|
||||
|
||||
// UpdateReceivedEvent describes an update entering the bot runtime.
|
||||
type UpdateReceivedEvent struct {
|
||||
UpdateID int
|
||||
@@ -162,9 +182,15 @@ func (bot *Bot[T]) safeEmitEvent(ctx context.Context, event Event) {
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
bot.logger.Errorln(fmt.Sprintf("panic in observer: %v", r))
|
||||
if bot.logger != nil {
|
||||
bot.logger.Errorln(fmt.Sprintf("panic in observer: %v", r))
|
||||
}
|
||||
}
|
||||
}()
|
||||
bot.emitEvent(ctx, event)
|
||||
}
|
||||
|
||||
func (bot *Bot[T]) emitEvent(ctx context.Context, event Event) {
|
||||
switch e := event.(type) {
|
||||
case UpdateReceivedEvent:
|
||||
bot.observer.OnUpdateReceived(ctx, e)
|
||||
|
||||
Reference in New Issue
Block a user