telegram

package
v1.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BotID added in v1.15.14

func BotID(botToken string) (string, error)

BotID extracts the public bot identifier from a bot token, which Telegram formats as "<bot_id>:<secret>". The secret half must never leave the server, so a token without that shape is rejected instead of being pasted into a browser-facing URL.

func BuildTelegramOAuthURL added in v1.15.14

func BuildTelegramOAuthURL(botToken, redirect string) (string, error)

BuildTelegramOAuthURL is GenerateTelegramOAuthURL with the failure reason preserved, so callers can log why no URL could be produced.

embed=0 selects the redirect flow: Telegram sends the browser back to return_to with the signed result in the fragment. A non-zero embed puts Telegram in widget mode, where it posts the result to window.opener and closes itself — which loses the result entirely for a full-page navigation, since there is no opener.

func GenerateTelegramOAuthURL

func GenerateTelegramOAuthURL(botToken, redirect string) string

GenerateTelegramOAuthURL generates a URL for Telegram OAuth

Types

type AuthData

type AuthData struct {
	Id        *int64  `json:"id,omitempty"`
	FirstName *string `json:"first_name,omitempty"`
	LastName  *string `json:"last_name,omitempty"`
	Username  *string `json:"username,omitempty"`
	PhotoUrl  *string `json:"photo_url,omitempty"`
	AuthDate  *int64  `json:"auth_date,omitempty"`
	Hash      *string `json:"hash,omitempty"`
	// contains filtered or unexported fields
}

func ParseAndValidateBase64

func ParseAndValidateBase64(content []byte, botToken string) (*AuthData, error)

ParseAndValidateBase64 parses base64 content for AuthData and validates it

func ParseAndValidateJson

func ParseAndValidateJson(content []byte, botToken []byte) (*AuthData, error)

ParseAndValidateJson parses json content for AuthData and validates it

func ParseAuthDataBase64

func ParseAuthDataBase64(content []byte) (*AuthData, error)

ParseAuthDataBase64 decodes provided content from base64 and parses result for AuthData. Telegram's tgAuthResult reaches us in whichever base64 flavour the widget and the surrounding URL handling produced, so all four combinations of alphabet (standard or URL-safe) and padding are accepted.

func ParseAuthDataJson

func ParseAuthDataJson(content []byte) (*AuthData, error)

ParseAuthDataJson parses provided json content for AuthData

func (*AuthData) Validate

func (d *AuthData) Validate(botToken []byte) error

Validate checks the hash of AuthData with computed one. To compute hash botToken is required. Ref: https://core.telegram.org/widgets/login#checking-authorization

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL