Added more methods to Updates

bot-api-6.1
quenbyako 2021-02-02 15:38:41 +03:00
parent 2df616ce04
commit 01e6fd26dd
1 changed files with 24 additions and 0 deletions

View File

@ -99,6 +99,30 @@ func (u *Update) SentFrom() *User {
} }
} }
func (u *Update) CallbackData() string {
if u.CallbackQuery != nil {
return u.CallbackQuery.Data
}
return ""
}
func (u *Update) FromChat() *Chat {
switch {
case u.Message != nil:
return u.Message.Chat
case u.EditedMessage != nil:
return u.EditedMessage.Chat
case u.ChannelPost != nil:
return u.ChannelPost.Chat
case u.EditedChannelPost != nil:
return u.EditedChannelPost.Chat
case u.CallbackQuery != nil:
return u.CallbackQuery.Message.Chat
default:
return nil
}
}
// UpdatesChannel is the channel for getting updates. // UpdatesChannel is the channel for getting updates.
type UpdatesChannel <-chan Update type UpdatesChannel <-chan Update