telegram-api-schema-methods
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

telegram-api-schema-methods

NPM Downloads

The library helps to type all methods for the Telegram User API (https://core.telegram.org/methods)

Install

yarn add telegram-api-schema-methods
# or
npm i telegram-api-schema-methods

Example

Example using the @mtproto/core library, which is optional (https://github.com/alik0211/mtproto-core)

import { makeTgUserApiMethods } from 'telegram-api-schema-methods';
import MTProto from '@mtproto/core/envs/node';
import path from 'path';

// 1. Create instance
const mtproto = new MTProto({
    api_id: YOU_API_ID,
    api_hash: YOU_API_HASH,
    storageOptions: {
        path: path.resolve(__dirname, './1.json'),
    },
});

// 2. Create telegram user api methods (automatic typing of parameters and the result of methods)
const tgUserApiMethods = makeTgUserApiMethods({
    request: (...args: any[]) => mtproto.call(...args),
});

// 3. Print the user country code
tgUserApiMethods.helpGetNearestDc({}).then(({ success, data, error }) => {
    if (success) {
        // auto typing result for typescript
        console.log('country:', data.country);
    } else {
        console.error(error);
    }
});

License

MIT

Dependencies (0)

    Dev Dependencies (9)

    Package Sidebar

    Install

    npm i telegram-api-schema-methods

    Weekly Downloads

    14

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    2.06 MB

    Total Files

    51

    Last publish

    Collaborators

    • a1im