UNPKG

2.27 kBPlain TextView Raw
1import { InputFile } from './core/types/typegram'
2
3/**
4 * The local file specified by path will be uploaded to Telegram using multipart/form-data.
5 *
6 * 10 MB max size for photos, 50 MB for other files.
7 */
8// prettier-ignore
9export const fromLocalFile = (path: string, filename?: string): InputFile => ({ source: path, filename })
10
11/**
12 * The buffer will be uploaded as file to Telegram using multipart/form-data.
13 *
14 * 10 MB max size for photos, 50 MB for other files.
15 */
16// prettier-ignore
17export const fromBuffer = (buffer: Buffer, filename?: string): InputFile => ({ source: buffer, filename })
18
19/**
20 * Contents of the stream will be uploaded as file to Telegram using multipart/form-data.
21 *
22 * 10 MB max size for photos, 50 MB for other files.
23 */
24// prettier-ignore
25export const fromReadableStream = (stream: NodeJS.ReadableStream, filename?: string): InputFile => ({ source: stream, filename })
26
27/**
28 * Contents of the URL will be streamed to Telegram.
29 *
30 * 10 MB max size for photos, 50 MB for other files.
31 */
32// prettier-ignore
33export const fromURLStream = (url: string | URL, filename?: string): InputFile => ({ url: url.toString(), filename })
34
35/**
36 * Provide Telegram with an HTTP URL for the file to be sent.
37 * Telegram will download and send the file.
38 *
39 * * The target file must have the correct MIME type (e.g., audio/mpeg for `sendAudio`, etc.).
40 * * `sendDocument` with URL will currently only work for GIF, PDF and ZIP files.
41 * * To use `sendVoice`, the file must have the type audio/ogg and be no more than 1MB in size.
42 * 1-20MB voice notes will be sent as files.
43 *
44 * 5 MB max size for photos and 20 MB max for other types of content.
45 */
46export const fromURL = (url: string | URL): string => url.toString()
47
48/**
49 * If the file is already stored somewhere on the Telegram servers, you don't need to reupload it:
50 * each file object has a file_id field, simply pass this file_id as a parameter instead of uploading.
51 *
52 * It is not possible to change the file type when resending by file_id.
53 *
54 * It is not possible to resend thumbnails using file_id.
55 * They have to be uploaded using one of the other Input methods.
56 *
57 * There are no limits for files sent this way.
58 */
59export const fromFileId = (fileId: string): string => fileId