Documentation
¶
Overview ¶
Package telegram contains the common functions and structures for working with Telegram messenger such as decoding, verification, etc.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder helps to decode initData metadata. See `DecodeInitData` for more details.
func NewDecoder ¶
NewDecoder creates a new telegram.Decoder. BotToken is required. See `DecodeInitData` for more details.
func (*Decoder) DecodeInitData ¶
func (d *Decoder) DecodeInitData(initDataRaw string) (*InitDataMeta, error)
DecodeInitData decodes URL-encoded "initData" and verifies its integrity. It compares the received hash parameter with the hexadecimal representation of the HMAC-SHA-256 signature of the data-check-string with the secret key, which is the HMAC-SHA-256 signature of the bot's token with the constant string WebAppData used as a key.
type InitDataMeta ¶
type InitDataMeta struct {
// UserJSON is an optional JSON string containing data about the current user.
// Use InitDataMeta.User to decode it to *WebAppUser.
UserJSON *string `schema:"user"`
// ChatInstance is a global identifier, uniquely corresponding to
// the chat from which the Mini App was opened. Returned only for
// Mini Apps launched from a direct link.
ChatInstance string `schema:"chat_instance"`
// ChatType is a type of the chat from which the Mini App was opened. Can be
// either “sender” for a private chat with the user opening the link,
// “private”, “group”, “supergroup”, or “channel”. Returned only
// for Mini Apps launched from direct links.
ChatType string `schema:"chat_type"`
// Raw data transferred to the Mini App. It is used for validation.
Raw url.Values `schema:"-"`
}
InitDataMeta is a structure with input data transferred to the Mini App.
func (InitDataMeta) User ¶
func (m InitDataMeta) User() (*WebAppUser, error)
User unmarshalls UserJSON to WebAppUser if it is not nil.
type LoggerAdapter ¶
LoggerAdapter implements tgbotapi.BotLogger for zerolog.Logger. All logs are printed in debug level.
func (LoggerAdapter) Printf ¶
func (a LoggerAdapter) Printf(format string, v ...interface{})
Printf implements tgbotapi.BotLogger.
func (LoggerAdapter) Println ¶
func (a LoggerAdapter) Println(v ...interface{})
Println implements tgbotapi.BotLogger.
type WebAppUser ¶
type WebAppUser struct {
// A unique identifier for the user. It has at most
// 52 significant bits.
ID int64 `json:"id"`
// Username of the user. It is optional.
Username string `json:"username"`
// FirstName of the user.
FirstName string `json:"first_name"`
// LastName of the user. It is optional.
LastName string `json:"last_name"`
}
WebAppUser is a structure containing the information about Telegram user.