Skip to content

Add opt-in raw chat ID attribute to the Telegram provider - #326

Merged
umputun merged 1 commit into
go-pkgz:masterfrom
paskal:feat/telegram-chat-id-attribute
Nov 9, 2026
Merged

umputun merged 1 commit into
go-pkgz:masterfrom
paskal:feat/telegram-chat-id-attribute

Conversation

@paskal

@paskal paskal commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Previously, the Telegram provider exposed only the hashed telegram_... user ID, so an app that logs users in with Telegram alone could not message them through its bot. After this change, TelegramHandler has a ChatIDAttribute field. Empty, the default, keeps the current behavior. When set, a fresh login stores the user's raw chat ID as a decimal string under that key in the user attributes, so it reaches the JWT and the /auth/user and login responses. The user ID stays hashed either way. v1 and v2 get the same change.

telegram := provider.TelegramHandler{
	ProviderName:    "telegram",
	ChatIDAttribute: "telegram_chat_id",
	// other fields as before
}

// in a handler behind the auth middleware
user := token.MustGetUserInfo(r)
chatID := user.StrAttr("telegram_chat_id")

Tokens issued before the key was set carry no attribute until the user logs in again.

TestTelegramProcessUpdates_ChatIDAttribute, in v1 and v2, covers both modes and checks the attribute in the login response and in the JWT read back through the token service; with the SetStrAttr call removed, its set-key case fails. Tests pass with -race for both modules, and golangci-lint v2.12.2 reports no issues.

Resolves #267

The Telegram user ID is a hash of the chat ID, so an app that logs users
in with Telegram alone has no way to message them through its bot.
ChatIDAttribute, when set, stores the raw chat ID as a string attribute
under that key on a fresh login. Empty keeps the current behavior, so the
raw ID does not reach the token and the user responses of apps that do
not need it.
@paskal
paskal requested a review from umputun as a code owner November 8, 2026 21:00
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 42523015358

Coverage increased (+0.01%) to 86.841%

Details

  • Coverage increased (+0.01%) from the base build.
  • Patch coverage: 6 of 6 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3853
Covered Lines: 3346
Line Coverage: 86.84%
Coverage Strength: 10.03 hits per line

💛 - Coveralls

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 42523015349

Coverage increased (+0.1%) to 86.931%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 6 of 6 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3887
Covered Lines: 3379
Line Coverage: 86.93%
Coverage Strength: 10.11 hits per line

💛 - Coveralls

@umputun umputun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@umputun
umputun merged commit c8b8b0b into go-pkgz:master Nov 9, 2026
6 checks passed
@paskal
paskal deleted the feat/telegram-chat-id-attribute branch November 9, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram - support retrieving provider user ID

3 participants