import React from 'react' import { Link as MuiLink, Typography } from '@material-ui/core' import { Page, usePageStyles } from '../components/page' import { graphql, Link } from 'gatsby' interface Data { mtClasses: { totalCount: number } classes: { totalCount: number } mtMethods: { totalCount: number } methods: { totalCount: number } mtUnions: { totalCount: number } unions: { totalCount: number } clsWithDesc: { totalCount: number } clsWithoutDesc: { totalCount: number } argWithDesc: { totalCount: number nodes: { arguments: { description: string | null }[] }[] } argWithoutDesc: { totalCount: number nodes: { arguments: { description: string | null }[] }[] } updated: { nodes: [ { layer: number rev: number source: { date: string commit: string file: string } } ] } historySchemas: { totalCount: number } historyTypes: { totalCount: number } } function countMissingDescriptionArguments( item: Data['argWithDesc'], eqNull: boolean ) { let count = 0 item.nodes.forEach((node) => node.arguments?.forEach((arg) => { if (eqNull ? arg.description === null : arg.description !== null) count += 1 }) ) item.totalCount = count } export default function IndexPage({ data }: { data: Data }) { const classes = usePageStyles() countMissingDescriptionArguments(data.argWithoutDesc, true) countMissingDescriptionArguments(data.argWithDesc, false) const currentLayer = data.updated.nodes[0] return (
TL Reference layer {currentLayer.layer} {currentLayer.rev > 0 ? ` rev. ${currentLayer.rev}` : ''} / updated {currentLayer.source.date} /{' '} view source
This web application allows easily browsing through myriads of TL objects and reading through their documentation. Unlike{' '} official documentation , this app has simpler structure, search and nice interface. Even though this reference is intended to be used with{' '} MTCute{' '} library, the objects are common to any other MTProto library. The key difference is that MTCute (and this reference) use{' '} camelCase for arguments, while the original schema and some other libraries use snake_case. Types In TL, there are 3 main groups of types: Classes,{' '} Methods and Unions (officially they are called{' '} constructors, methods and types{' '} respectively). Classes and Methods are simply typed objects, that contain some data. The only difference is that Methods are used in RPC calls (i.e. they are sent to the server), and Classes are used inside methods, or sent by the server back (either as an RPC result, or as an update). Union is a type that combines multiple Classes in one type. In some languages, this can be represented as an abstract class. Unions are sent by Telegram in response to RPC results, as well as they are used as arguments for other{' '} Classes or Methods. In TL, every single Class is a part of exactly one{' '} Union, and every Union contains at least one{' '} Class. In MTCute, all types are exposed as a namespace tl{' '} of package @mtcute/tl. By design, we use immutable plain objects with type discriminator to represent{' '} Classes and Methods, and TypeScript unions to represent Unions.
To differentiate between different groups of types, we use different naming for each of them:
  • Classes are prefixed with Raw (e.g.{' '} tl.RawMessage)
  • Additionally, Methods are postfixed with{' '} Request and (e.g.{' '} tl.RawGetMessageRequest)
  • Finally, Unions are simply prefixed with{' '} Type (e.g. tl.TypeUser)
  • Core types Core types are basic built-in types that are used in TL schema. Quick reference:
  • number: 32-bit signed integer
  • Long: 64-bit signed integer
  • Int128: 128-bit signed integer (only used for MTProto)
  • Int256: 256-bit signed integer (only used for MTProto)
  • Double: 64-bit floating point value
  • string: UTF-16 string (strings in JS are also UTF-16)
  • Buffer: Byte array of a known size
  • boolean: One-byte boolean value (true/false)
  • true: Zero-size true value, used for TL flags
  • any: Any other TL object (usually another method)
  • T[]: Array of T
  • TlFlags: 32-bit signed value representing object's TL flags
  • Statistics
  • Generated from layer {data.updated.nodes[0].layer}{' '} (last updated {data.updated.nodes[0].source.date}, commit{' '} {data.updated.nodes[0].source.commit.substr(0, 7)} )
  • Current schema contains{' '} {data.methods.totalCount + data.classes.totalCount + data.unions.totalCount} {' '} types (+{' '} {data.mtClasses.totalCount + data.mtMethods.totalCount + data.mtUnions.totalCount} {' '} for MTProto)
  • Current schema contains {data.classes.totalCount}{' '} classes (+ {data.mtClasses.totalCount} for MTProto)
  • Current schema contains {data.methods.totalCount}{' '} methods (+ {data.mtMethods.totalCount} for MTProto)
  • Current schema contains {data.unions.totalCount}{' '} unions (+ {data.mtUnions.totalCount} for MTProto)
  • Description coverage:{' '} {(function () { const totalWith = data.argWithDesc.totalCount + data.clsWithDesc.totalCount const totalWithout = data.argWithoutDesc.totalCount + data.clsWithoutDesc.totalCount const total = totalWith + totalWithout return ( <> {Math.round((totalWith / total) * 10000) / 100} % {' '} (out of {total} items, {totalWithout}{' '} don't have description {' '} - that is {data.clsWithoutDesc.totalCount} types and {data.argWithoutDesc.totalCount} arguments) ) })()}
  • History is available for{' '} {data.historySchemas.totalCount} schemas {' '} and {data.historyTypes.totalCount} types
  • ) } export const query = graphql` query { mtClasses: allTlObject( filter: { type: { eq: "class" }, prefix: { eq: "mtproto/" } } ) { totalCount } classes: allTlObject( filter: { type: { eq: "class" }, prefix: { ne: "mtproto/" } } ) { totalCount } mtMethods: allTlObject( filter: { type: { eq: "method" }, prefix: { eq: "mtproto/" } } ) { totalCount } methods: allTlObject( filter: { type: { eq: "method" }, prefix: { ne: "mtproto/" } } ) { totalCount } mtUnions: allTlObject( filter: { type: { eq: "union" }, prefix: { eq: "mtproto/" } } ) { totalCount } unions: allTlObject( filter: { type: { eq: "union" }, prefix: { ne: "mtproto/" } } ) { totalCount } updated: allHistoryJson( sort: { fields: source___date, order: DESC } filter: { layer: { ne: null } } limit: 1 ) { nodes { layer rev source { date(formatString: "DD-MM-YYYY") commit file } } } clsWithDesc: allTlObject(filter: { description: { ne: null } }) { totalCount } clsWithoutDesc: allTlObject(filter: { description: { eq: null } }) { totalCount } argWithDesc: allTlObject( filter: { arguments: { elemMatch: { description: { ne: null } } } } ) { totalCount nodes { arguments { description } } } argWithoutDesc: allTlObject( filter: { arguments: { elemMatch: { description: { eq: null } } } } ) { totalCount nodes { arguments { description } } } historySchemas: allHistoryJson { totalCount } historyTypes: allTypesJson { totalCount } } `