diff --git a/ext/context.go b/ext/context.go index 9f478e62..03b0f1c6 100644 --- a/ext/context.go +++ b/ext/context.go @@ -65,11 +65,7 @@ func NewContext(update *gotgbot.Update, data map[string]interface{}) *Context { case update.MessageReaction != nil: user = update.MessageReaction.User chat = &update.MessageReaction.Chat - sender = &gotgbot.Sender{ - User: update.MessageReaction.User, - Chat: update.MessageReaction.ActorChat, - ChatId: update.MessageReaction.Chat.Id, - } + sender = update.MessageReaction.GetSender() case update.MessageReactionCount != nil: chat = &update.MessageReactionCount.Chat @@ -110,7 +106,7 @@ func NewContext(update *gotgbot.Update, data map[string]interface{}) *Context { case update.PollAnswer != nil: user = update.PollAnswer.User - sender = &gotgbot.Sender{User: update.PollAnswer.User, Chat: update.PollAnswer.VoterChat} + sender = update.PollAnswer.GetSender() case update.MyChatMember != nil: user = &update.MyChatMember.From diff --git a/ext/handlers/filters/types.go b/ext/handlers/filters/types.go index 14c10352..6c4e6c10 100644 --- a/ext/handlers/filters/types.go +++ b/ext/handlers/filters/types.go @@ -13,5 +13,5 @@ type ( PollAnswer func(pa *gotgbot.PollAnswer) bool PreCheckoutQuery func(pcq *gotgbot.PreCheckoutQuery) bool ShippingQuery func(sq *gotgbot.ShippingQuery) bool - Reaction func(mra *gotgbot.MessageReactionUpdated) bool + Reaction func(mru *gotgbot.MessageReactionUpdated) bool ) diff --git a/sender.go b/sender.go index ea954a38..a3cc2b01 100644 --- a/sender.go +++ b/sender.go @@ -28,6 +28,23 @@ func (m Message) GetSender() *Sender { } } +// GetSender populates the relevant fields of a Sender struct given a reaction. +func (mru MessageReactionUpdated) GetSender() *Sender { + return &Sender{ + User: mru.User, + Chat: mru.ActorChat, + ChatId: mru.Chat.Id, + } +} + +// GetSender populates the relevant fields of a Sender struct given a poll answer. +func (pa PollAnswer) GetSender() *Sender { + return &Sender{ + User: pa.User, + Chat: pa.VoterChat, + } +} + // Id determines the sender ID. // When a message is being sent by a chat/channel, telegram usually populates the User field with dummy values. // For this reason, we prefer to return the Chat.Id if it is available, rather than a dummy User.Id.