tgwebapp

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: Apache-2.0, MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

tgwebapp - Provides authentication for Telegram web app

Exports

  • func AuthenticateTelegramWebApp(w http.ResponseWriter, r *http.Request, authenticated func() error)

Documentation from Telegram

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticateTelegramWebApp

func AuthenticateTelegramWebApp(
	w http.ResponseWriter, r *http.Request,
	getToken func(bot string) string,
	complete func(initData *InitData),
)

AuthenticateTelegramWebApp validates Telegram web app init data https://core.telegram.org/bots/webapps#webappinitdata TODO: Move some of it into Telegram FW module?

Types

type InitData

type InitData struct {
	// QueryID - A unique identifier for the Web App session, required for sending messages via the answerWebAppQuery method.
	QueryID string `json:"query_id"`

	// ChatType - Type of the chat from which the Web 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 Web Apps launched from direct links.
	ChatType string `json:"chat_type,omitempty"`

	// ChatInstance - Global identifier, uniquely corresponding to the chat from which the Web App was opened.
	// Returned only for Web Apps launched from a direct link.
	ChatInstance string `json:"chat_instance,omitempty"`

	// StartParam - The value of the startattach parameter, passed via link. Only returned for Web Apps when launched from the attachment menu via link.
	StartParam string `json:"start_param,omitempty"`

	// CanSendAfter - Time in seconds, after which a message can be sent via the answerWebAppQuery method.
	CanSendAfter int `json:"can_send_after,omitempty"`

	// AuthDate - Unix time when the form was opened.
	AuthDate int `json:"auth_date"`

	// Hash of all passed parameters, which the bot server can use to check their validity.
	Hash string `json:"hash"`
}

InitData describes Telegram web app init data https://core.telegram.org/bots/webapps#webappinitdata

func NewInitDataFromUrlValues added in v0.4.0

func NewInitDataFromUrlValues(values url.Values) InitData

Jump to

Keyboard shortcuts

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