webapps

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2025 License: MIT Imports: 11 Imported by: 0

README

Telegram WebApps

Tools for telegram web apps: https://core.telegram.org/bots/webapps

Quick start:

Install Package: go get github.com/Fuchsoria/telegram-webapps

Add Imports:

import (
	"fmt"
	"log"
	webapps "github.com/Fuchsoria/telegram-webapps"
)

Use!:

func  main() {
	token  :=  "BOT_TOKEN"
	data  :=  "WebAppInitData_from_TG"

	err, user  := webapps.VerifyWebAppData(data, token)
	if err !=  nil {
		log.Fatal(err)
	}

	fmt.Println(user)
}

Documentation

Index

Constants

View Source
const (
	MaxDataAge = 24 * time.Hour
)

Variables

View Source
var (
	ErrInvalidHash       = errors.New("invalid hash")
	ErrUserFieldMissing  = errors.New("user field missing")
	ErrAuthDateMissing   = errors.New("auth_date field missing")
	ErrAuthDateInvalid   = errors.New("invalid auth_date")
	ErrDataExpired       = errors.New("data is too old")
	ErrInvalidDataFormat = errors.New("invalid data format")
)

Functions

This section is empty.

Types

type WebAppUser

type WebAppUser struct {
	ID                    int    `json:"id"`
	IsBot                 bool   `json:"is_bot"`
	IsPremium             bool   `json:"is_premium"`
	FirstName             string `json:"first_name"`
	LastName              string `json:"last_name"`
	Username              string `json:"username"`
	LanguageCode          string `json:"language_code"`
	AddedToAttachmentMenu bool   `json:"added_to_attachment_menu"`
	AllowsWriteToPm       bool   `json:"allows_write_to_pm"`
	PhotoURL              string `json:"photo_url"`
}

func VerifyWebAppData

func VerifyWebAppData(telegramInitData, token string) (WebAppUser, error)

Jump to

Keyboard shortcuts

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