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

@gramio/types

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gramio/types

Code-generated Telegram Bot API types

  • 7.0.1
  • npm
  • Socket score

Version published
Weekly downloads
318
decreased by-44.6%
Maintainers
1
Weekly downloads
 
Created
Source

Code-generated Telegram Bot API types

Usage as an NPM package

import type { ApiMethods } from "@gramio/types"

type SendMessageReturn = ReturnType<ApiMethods["sendMessage"]>
//   ^? type SendMessageReturn = Promise<TelegramMessage>

Versioning

7.0.x types - for 7.0 Telegram Bot API

Write you own type-safe TBA API wrapper

import { stringify } from "node:querystring"
import type { ApiMethods } from "@gramio/types"

const TOKEN = ""

const api = new Proxy<ApiMethods>({} as ApiMethods, {
    get: (_target, method: string) => async (args: Record<string, any>) => {
        const url =
            `http://api.telegram.org/bot` +
            TOKEN +
            "/" +
            method +
            `?` +
            stringify(args)

        const response = await fetch(url, {
            method: "GET",
        })

        const data = await response.json()
        if (!response.ok) throw new Error("some error")

        return data.result
    },
})

api.sendMessage({
    chat_id: 1,
    text: "msg",
})

Generate types

Prerequire - rust

  1. Clone this repo and open it
git clone https://github.com/kravetsone/gramio-types.git
  1. Clone repo with TBA parser to the src folder
git clone https://github.com/ark0f/tg-bot-api.git
  1. Run the JSON schema generator in the cloned folder
cargo run --package gh-pages-generator --bin gh-pages-generator -- dev
  1. Run types code-generation from the root of the project
bun generate

or, if you don't use bun, use tsx

npx tsx src/index.ts
  1. Profit! Check out the types of Telegram Bot API in types folder!

Keywords

FAQs

Package last updated on 06 Jan 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