Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

telegram-bot-api-types

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telegram-bot-api-types

Telegram Bot API types

  • 7.9.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
129
decreased by-53.26%
Maintainers
0
Weekly downloads
 
Created
Source

@types/telegram-bot-api

This is a d.ts file for Telegram Bot API. It is based on the official Telegram Bot API documentation.

Example

import type { GetFileParams, GetFileRequest, SendPhotoParams, SendPhotoRequest, TelegramBotMethod } from ".";

class APIClient implements GetFileRequest, SendPhotoRequest {
    readonly token: string;
    readonly baseURL: string = `https://api.telegram.org/`;
    constructor(token: string, baseURL?: string) {
        this.token = token;
        if (baseURL) {
            this.baseURL = baseURL;
        }
    }

    jsonRequest<T>(method: TelegramBotMethod, params: T): Promise<Response> {
        return fetch(`${this.baseURL}bot${this.token}/${method}`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(params),
        });
    }

    formDataRequest<T>(method: TelegramBotMethod, params: T): Promise<Response> {
        const formData = new FormData();
        for (const key in params) {
            const value = params[key];
            if (value instanceof File) {
                formData.append(key, value, value.name);
            } else if (value instanceof Blob) {
                formData.append(key, value, 'blob');
            } else if (typeof value === 'string') {
                formData.append(key, value);
            } else {
                formData.append(key, JSON.stringify(value));
            }
        }
        return fetch(`${this.baseURL}bot${this.token}/${method}`, {
            method: 'POST',
            body: formData,
        });
    }

    getFile(params: GetFileParams): Promise<Response> {
        return this.jsonRequest('getFile', params);
    }

    sendPhoto(params: SendPhotoParams): Promise<Response> {
        return this.formDataRequest('sendPhoto', params);
    }
}

const client = new APIClient('123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11');
client.getFile!({ file_id: '123' }).then(console.log);

License

@types/telegram-bot-api is released under the MIT license. See LICENSE for details.

FAQs

Package last updated on 24 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc