InitData
The component which is responsible for implementing the Telegram Mini Apps init data. This class represents an object with properties getters. To create its new instance, a developer could use the class constructor as follows:
import { InitData } from '@tma.js/sdk';
const initData = new InitData({
authDate: new Date(),
canSendAfter: 1000,
chat: {
id: 7728558344,
photoUrl: 'https://img.static.telegram.org/image',
type: 'group',
title: 'Telegram Developers',
username: 'johnybravo',
},
chatType: 'sender',
chatInstance: '-9982961682389',
hash: 'myhash',
queryId: 'AAHdF6IQAAAAAN0Xoh',
startParam: 'customvalue',
user: {
addedToAttachmentMenu: false,
allowsWriteToPm: true,
firstName: 'Johny',
id: 22231781,
isBot: false,
isPremium: true,
lastName: 'Bravo',
languageCode: 'en',
photoUrl: 'https://img.static.telegram.org/johnybravo',
username: 'johnybravo',
},
});
import { InitData } from '@tma.js/sdk';
const initData = new InitData({
authDate: new Date(),
canSendAfter: 1000,
chat: {
id: 7728558344,
photoUrl: 'https://img.static.telegram.org/image',
type: 'group',
title: 'Telegram Developers',
username: 'johnybravo',
},
chatType: 'sender',
chatInstance: '-9982961682389',
hash: 'myhash',
queryId: 'AAHdF6IQAAAAAN0Xoh',
startParam: 'customvalue',
user: {
addedToAttachmentMenu: false,
allowsWriteToPm: true,
firstName: 'Johny',
id: 22231781,
isBot: false,
isPremium: true,
lastName: 'Bravo',
languageCode: 'en',
photoUrl: 'https://img.static.telegram.org/johnybravo',
username: 'johnybravo',
},
});
All properties of the passed constructor object excluding authDate
and hash
are optional.
Properties
authDate
Type: Date
Init data generation date.
canSendAfter
Type: number
, optional
The number of seconds after which a message can be sent via the method answerWebAppQuery.
canSendAfterDate
Type: Date
, optional
Date after which it is allowed to call the answerWebAppQuery method.
chat
Type: Chat
, optional
An object containing data about the chat where the bot was launched via the attachment menu. Returned for supergroups, channels and group chats – only for Mini Apps launched via the attachment menu.
chatType
Type: 'sender' | 'private' | 'group' | 'supergroup' | 'channel' | string
, optional
The type of chat from which Mini App was opened.
chatInstance
Type: string
, optional
A global identifier indicating the chat from which Mini App was opened. Returned only for applications opened by direct link.
hash
Type: string
A hash of all passed parameters, which the bot server can use to check their validity.
queryId
Type: string
, optional
A unique identifier for the Mini App session, required for sending messages via the answerWebAppQuery method.
receiver
Type: User
, optional
An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu. Returned only for private chats and only for Mini Apps launched via the attachment menu.
startParam
Type: string
, optional
The value of the startattach
parameter, passed via link. Only returned for Mini Apps when launched from the attachment menu via link.
user
Type: User
, optional
An object containing data about the current user.