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

typegram

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typegram - npm Package Compare versions

Comparing version 2.3.3 to 3.0.0

callback.d.ts

36

alias.d.ts

@@ -0,1 +1,3 @@

import { Typegram } from "./proxied";
export type Integer = number;

@@ -6,1 +8,35 @@ export type Float = number;

export type True = true;
/** This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual way that files are uploaded via the browser. */
export type InputFile = String;
type DefaultTypegram = Typegram<InputFile>;
/** Wrapper type to bundle all methods of the Telegram API */
export type Telegram = DefaultTypegram["Telegram"];
/** Utility type providing the argument type for the given method name or `{}` if the method does not take any parameters */
export type Opts<
M extends keyof DefaultTypegram["Telegram"]
> = DefaultTypegram["Opts"][M];
/** Utility type providing a promisified version of Telegram */
export type TelegramP = DefaultTypegram["TelegramP"];
/** This object represents the content of a media message to be sent. It should be one of
- InputMediaAnimation
- InputMediaDocument
- InputMediaAudio
- InputMediaPhoto
- InputMediaVideo */
export type InputMedia = DefaultTypegram["InputMedia"];
/** Represents a photo to be sent. */
export type InputMediaPhoto = DefaultTypegram["InputMediaPhoto"];
/** Represents a video to be sent. */
export type InputMediaVideo = DefaultTypegram["InputMediaVideo"];
/** Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. */
export type InputMediaAnimation = DefaultTypegram["InputMediaAnimation"];
/** Represents an audio file to be treated as music to be sent. */
export type InputMediaAudio = DefaultTypegram["InputMediaAudio"];
/** Represents a general file to be sent. */
export type InputMediaDocument = DefaultTypegram["InputMediaDocument"];

12

index.d.ts

@@ -1,3 +0,9 @@

export * from './alias'
export * from './types'
export * from './methods'
export * from "./alias";
export * from "./callback";
export * from "./inline";
export * from "./manage";
export * from "./message";
export * from "./passport";
export * from "./payment";
export * from "./proxied";
export * from "./update";
{
"name": "typegram",
"version": "2.3.3",
"version": "3.0.0",
"description": "Type declarations for the Telegram API",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {

@@ -13,12 +10,16 @@ "type": "git",

},
"keywords": [],
"author": "",
"license": "ISC",
"keywords": [
"telegram",
"telegraf",
"bot",
"api",
"types",
"typings"
],
"author": "KnorpelSenf",
"license": "MIT",
"bugs": {
"url": "https://github.com/KnorpelSenf/typegram/issues"
},
"homepage": "https://github.com/KnorpelSenf/typegram#readme",
"devDependencies": {
"@types/node": "^14.14.8"
}
"homepage": "https://github.com/KnorpelSenf/typegram#readme"
}

@@ -32,7 +32,7 @@ # Types for the Telegram API

(Naturally, when the API specification is actually modelling types to be unions (e.g. `InputMedia`), this is reflected here as a union type, too.)
(Naturally, when the API specification is actually modelling types to be unions (e.g. `InlineQueryResult`), this is reflected here as a union type, too.)
## Available Methods
In addition to the types, this package provides you with another `interface Telegram` which contains all available **methods** of the API.
In addition to the types, this package provides you with another type `Telegram` which contains all available **methods** of the API.
There is no further structure applied to this, but if you can come up with something reasonable, please suggest it in an issue or directly open a PR.

@@ -46,3 +46,3 @@

## Caveat with JSON-serialized objects
## Caveat with JSON-Serialized Objects

@@ -74,4 +74,59 @@ Some methods of the Telegram API are expected to be called with JSON-serialized objects contained in a property of the payload, rather than an actual JSON payload.

## Where do the types come from
## Customizing `InputFile`
The Telegram API lets bots send files in [three different ways](https://core.telegram.org/bots/api#sending-files).
Two of those ways are by specifying a `string`—either a `file_id` or a URL.
The third option, however, is by uploading files to the server.
Depending on the code you're using the `typegram` types for, you may want to support different ways to specify the file to be uploaded.
As an example, you may want to be able to make calls to `sendDocument` with an object that conforms to `{ path: string }` in order to specify the location of a local file.
(Your code is then assumed to able to handle calls to `sendDocument` and the like when supplied with an object alike `{ path: '/tmp/file.txt' }` for the `document` property of the argument object.)
`typegram` cannot possibly know what objects you want to support as `InputFile`s.
Consequently, the exposed type `InputFile` is merely an alias for `string`, thus covering the first two means to send a file.
However, you can specify your own version of what an `InputFile` is, hence effectively creating a completely new version of `typegram` with your custom `InputFile` type used throughout all affected methods and interfaces.
For instance, let's stick with our example and say that you want to support `InputFile`s of the following type.
```ts
interface MyInputFile {
path: string;
}
```
You can then customize `typegram` to fit your needs by
1. importing the magical `Typegram` proxy type and
2. setting this alias:
```ts
type MyTypegram = Typegram<MyInputFile>;
```
You can now access all types that must respect `MyInputFile` through the `MyTypegram` type:
```ts
// The `Telegram` type that contains all API methods:
type Telegram = MyTypegram["Telegram"];
// or, respectively
type TelegramP = MyTypegram["TelegramP"];
// The utility type `Opts`:
type Opts<M extends keyof Telegram> = MyTypegram["Opts"][M];
// The adjusted `InputMedia*` types:
type InputMedia = MyTypegram["InputMedia"];
type InputMediaPhoto = MyTypegram["InputMediaPhoto"];
type InputMediaVideo = MyTypegram["InputMediaVideo"];
type InputMediaAnimation = MyTypegram["InputMediaAnimation"];
type InputMediaAudio = MyTypegram["InputMediaAudio"];
type InputMediaDocument = MyTypegram["InputMediaDocument"];
```
All other interfaces are unaffected by the customization through `MyInputFile`.
They can simply continued to be imported directly from `typegram`.
## Where Do the Types Come from
They're handwritten.

@@ -78,0 +133,0 @@

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