Added SentFrom method to Update type

bot-api-6.1
quenbyako 2021-02-02 14:56:51 +03:00
parent 54104a08f9
commit 2df616ce04
1 changed files with 23 additions and 0 deletions

View File

@ -76,6 +76,29 @@ type Update struct {
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query"`
}
// SentFrom return user sender of update. Can be nil, if telegram wont provide info about him in
// update object.
func (u *Update) SentFrom() *User {
switch {
case u.Message != nil:
return u.Message.From
case u.EditedMessage != nil:
return u.EditedMessage.From
case u.InlineQuery != nil:
return u.InlineQuery.From
case u.ChosenInlineResult != nil:
return u.ChosenInlineResult.From
case u.CallbackQuery != nil:
return u.CallbackQuery.From
case u.ShippingQuery != nil:
return u.ShippingQuery.From
case u.PreCheckoutQuery != nil:
return u.PreCheckoutQuery.From
default:
return nil
}
}
// UpdatesChannel is the channel for getting updates.
type UpdatesChannel <-chan Update