Skip to content

update.From when it came from unknown source (CallbackQuery/Message) #154

Open
@BeyCoder

Description

@BeyCoder

Problem

Sometimes, update.Message.From or update.Message.Chat could be nil if it's CallbackQuery update. So, I always need to repeat the same if statement. Example:

var userId int64
var chatId int64
if update.CallbackQuery != nil {
	userId = update.CallbackQuery.From.ID
	chatId = update.CallbackQuery.Message.Message.Chat.ID
} else {
	userId = update.Message.From.ID
	chatId = update.Message.Chat.ID
}

Solution

Add the methods FromUser() and FromChat() to models.Update

Conclusion

It will help to easily retrieve the ChatID or UserID from the update. If necessary, I can contribute and send a PR to fix this issue so you can assign me.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions