Giter VIP home page Giter VIP logo

lukasandreano / tgwa-params-checker Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 11 KB

Package for checking parameters of Telegram Web Apps startup. The code is taken from the official documentation and put into one package for easy use.

Home Page: https://npmjs.com/package/tgwa-params-checker

License: MIT License

TypeScript 100.00%
nestjs nodejs telegram telegram-checker telegram-web-app telegram-web-apps tg tgwa

tgwa-params-checker's Introduction

What for?

Package for checking parameters of Telegram Web Apps startup. The code is taken from the official documentation and put into one package for easy use.

Getting started with the package

First, install the package:

npm i tgwa-params-checker

Initialize it in your project:

const check = require("tgwa-params-checker");
// or use import
import check from "tgwa-params-checker";

Using example:

const isValidParams = check(
  "startup params from web app window",
  "bot secret key",
  "lifetime in seconds"
);

The function returns true or false.

Parameter lifetime

Whenever parameters are generated, the creation date is attached to them: auth_date.

Initially start parameters will "live"_ two hours - 7200 seconds. And you can change this value by passing the desired number.

In the example above, we drop startup parameters, application secret key, and life time. As the latter, you can pass either a number or 0.

If 0 is specified, then the check for "stupidity" of the startup parameters will be disabled.

const isValidParams = check("", "", 3600); // Startup parameters will live for one hour (3600 seconds)
const isValidParams = check("", "", 0); // The startup parameters will live forever, as long as the key from the application does not change, for example.

Example:

const isValidParams = check(
  "query_id=AAHhpGQWAAAAAOGkZBacHiQ6&user=%7B%22id%22%3A375694561%2C%22first_name%22%3A%22%D0%9D%D0%98%D0%9A%D0%98%D0%A2%D0%90%22%2C%22last_name%22%3A%22%D0%9A%D0%9E%D0%9A%D0%90%22%2C%22username%22%3A%22lukasandreano%22%2C%22language_code%22%3A%22en%22%2C%22is_premium%22%3Atrue%7D&auth_date=1679551046&hash=36e589beaeb21328f4bcbec1816b8aba595f2612a28ea9beed696c2e9d85ecf3",
  "TdpgoP3d9Wggrfs1qtNhw"
); // false

tgwa-params-checker's People

Contributors

lukasandreano avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.