Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tg.Update.Msg() method doesn't cover all cases #155

Open
mineroot opened this issue Sep 8, 2024 · 0 comments
Open

tg.Update.Msg() method doesn't cover all cases #155

mineroot opened this issue Sep 8, 2024 · 0 comments

Comments

@mineroot
Copy link

mineroot commented Sep 8, 2024

Example with session.Manager + tgb.Router.MessageReaction()

router := tgb.NewRouter().
Use(sessionManager). // *session.Manager[T]
Message(func(ctx context.Context, msg *tgb.MessageUpdate) error {
	// this works

	// TODO...
	return nil
}).
MessageReaction(func(ctx context.Context, reaction *tgb.MessageReactionUpdate) error {
	// this doesn't work 
        // as session.Manager.Wrap() returns an error "can't get key from update" 

	// TODO...
	return nil
})

session.Manager.Wrap() returns an error because of its default session.KeyFuncChat() which calls tg.Update.Msg() method (not directly)

// Msg returns message from whever possible.
// It returns nil if message is not found.
func (update *Update) Msg() *Message {
	switch {
	case update == nil:
		return nil
	case update.Message != nil:
		return update.Message
	case update.EditedMessage != nil:
		return update.EditedMessage
	case update.ChannelPost != nil:
		return update.ChannelPost
	case update.EditedChannelPost != nil:
		return update.EditedChannelPost
	case update.CallbackQuery != nil && update.CallbackQuery.Message != nil && update.CallbackQuery.Message.Message != nil:
		return update.CallbackQuery.Message.Message
	case update.BusinessMessage != nil:
		return update.BusinessMessage
	case update.EditedBusinessMessage != nil:
		return update.EditedBusinessMessage
	default:
		return nil
	}
}

this method do not cover update.MessageReaction, MessageReactionCount (and probably some other types which can return Chat field needed for session.KeyFuncChat())

So, @mr-linch, is this a bug, or this is intentional? This also can be fixed by passing custom KeyFunc which handles all cases...

What do you think?

BTW, thanks for the great package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant