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

Open
#154 4 comments 0 reactions 1 assignee View on GitHub

@negasus is already working on this.

Since Feb 6, 2025.

Assessment

This issue has not been assessed yet.

Description

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.

Dominant language
Go
Stars
1.8k
Forks
161
Avg merge
2d 17h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from go-telegram/bot

All issues in go-telegram/bot

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.