@gramio/files
Advanced tools
Comparing version 0.0.5 to 0.0.7
@@ -0,4 +1,24 @@ | ||
/** | ||
* @module | ||
* | ||
* Set of utils for work with files and Telegram Bot API | ||
* | ||
* @example | ||
* ```typescript | ||
* import { MediaInput, MediaUpload } from "@gramio/files"; | ||
* | ||
* // method for sendMediaGroup | ||
* context.sendMediaGroup([ | ||
* MediaInput.document( | ||
* MediaUpload.url( | ||
* "https://raw.githubusercontent.com/gramiojs/types/main/README.md" | ||
* ) | ||
* ), | ||
* MediaInput.document(MediaUpload.path("./package.json")), | ||
* ]); | ||
* ``` | ||
*/ | ||
export * from "./utils"; | ||
export * from "./media-methods-helper"; | ||
export { isFile, MEDIA_METHODS } from "./media-methods-helper"; | ||
export * from "./media-input"; | ||
export * from "./media-upload"; |
"use strict"; | ||
/** | ||
* @module | ||
* | ||
* Set of utils for work with files and Telegram Bot API | ||
* | ||
* @example | ||
* ```typescript | ||
* import { MediaInput, MediaUpload } from "@gramio/files"; | ||
* | ||
* // method for sendMediaGroup | ||
* context.sendMediaGroup([ | ||
* MediaInput.document( | ||
* MediaUpload.url( | ||
* "https://raw.githubusercontent.com/gramiojs/types/main/README.md" | ||
* ) | ||
* ), | ||
* MediaInput.document(MediaUpload.path("./package.json")), | ||
* ]); | ||
* ``` | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
@@ -17,5 +37,8 @@ if (k2 === undefined) k2 = k; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MEDIA_METHODS = exports.isFile = void 0; | ||
__exportStar(require("./utils"), exports); | ||
__exportStar(require("./media-methods-helper"), exports); | ||
var media_methods_helper_1 = require("./media-methods-helper"); | ||
Object.defineProperty(exports, "isFile", { enumerable: true, get: function () { return media_methods_helper_1.isFile; } }); | ||
Object.defineProperty(exports, "MEDIA_METHODS", { enumerable: true, get: function () { return media_methods_helper_1.MEDIA_METHODS; } }); | ||
__exportStar(require("./media-input"), exports); | ||
__exportStar(require("./media-upload"), exports); |
@@ -7,3 +7,3 @@ import type { TelegramInputMediaAnimation, TelegramInputMediaAudio, TelegramInputMediaDocument, TelegramInputMediaPhoto, TelegramInputMediaVideo } from "@gramio/types"; | ||
* | ||
* {@link https://core.telegram.org/bots/api/#inputmediaanimation | [Documentation]} | ||
* [Documentation](https://core.telegram.org/bots/api/#inputmediaanimation) | ||
*/ | ||
@@ -14,3 +14,3 @@ static animation(media: TelegramInputMediaAnimation["media"], options?: Omit<TelegramInputMediaAnimation, "media" | "type">): TelegramInputMediaAnimation; | ||
* | ||
* {@link https://core.telegram.org/bots/api/#inputmediadocument | [Documentation]} | ||
* [Documentation](https://core.telegram.org/bots/api/#inputmediadocument) | ||
*/ | ||
@@ -21,3 +21,3 @@ static document(media: TelegramInputMediaDocument["media"], options?: Omit<TelegramInputMediaDocument, "media" | "type">): TelegramInputMediaDocument; | ||
* | ||
* {@link https://core.telegram.org/bots/api/#inputmediaaudio | [Documentation]} | ||
* [Documentation](https://core.telegram.org/bots/api/#inputmediaaudio) | ||
*/ | ||
@@ -28,3 +28,3 @@ static audio(media: TelegramInputMediaAudio["media"], options?: Omit<TelegramInputMediaAudio, "media" | "type">): TelegramInputMediaAudio; | ||
* | ||
* {@link https://core.telegram.org/bots/api/#inputmediaphoto | [Documentation]} | ||
* [Documentation](https://core.telegram.org/bots/api/#inputmediaphoto) | ||
*/ | ||
@@ -35,5 +35,5 @@ static photo(media: TelegramInputMediaPhoto["media"], options?: Omit<TelegramInputMediaPhoto, "media" | "type">): TelegramInputMediaPhoto; | ||
* | ||
* {@link https://core.telegram.org/bots/api/#inputmediavideo | [Documentation]} | ||
* [Documentation](https://core.telegram.org/bots/api/#inputmediavideo) | ||
*/ | ||
static video(media: TelegramInputMediaVideo["media"], options?: Omit<TelegramInputMediaVideo, "media" | "type">): TelegramInputMediaVideo; | ||
} |
@@ -9,3 +9,3 @@ "use strict"; | ||
* | ||
* {@link https://core.telegram.org/bots/api/#inputmediaanimation | [Documentation]} | ||
* [Documentation](https://core.telegram.org/bots/api/#inputmediaanimation) | ||
*/ | ||
@@ -22,3 +22,3 @@ static animation(media, options = {}) { | ||
* | ||
* {@link https://core.telegram.org/bots/api/#inputmediadocument | [Documentation]} | ||
* [Documentation](https://core.telegram.org/bots/api/#inputmediadocument) | ||
*/ | ||
@@ -35,3 +35,3 @@ static document(media, options = {}) { | ||
* | ||
* {@link https://core.telegram.org/bots/api/#inputmediaaudio | [Documentation]} | ||
* [Documentation](https://core.telegram.org/bots/api/#inputmediaaudio) | ||
*/ | ||
@@ -48,3 +48,3 @@ static audio(media, options = {}) { | ||
* | ||
* {@link https://core.telegram.org/bots/api/#inputmediaphoto | [Documentation]} | ||
* [Documentation](https://core.telegram.org/bots/api/#inputmediaphoto) | ||
*/ | ||
@@ -61,3 +61,3 @@ static photo(media, options = {}) { | ||
* | ||
* {@link https://core.telegram.org/bots/api/#inputmediavideo | [Documentation]} | ||
* [Documentation](https://core.telegram.org/bots/api/#inputmediavideo) | ||
*/ | ||
@@ -64,0 +64,0 @@ static video(media, options = {}) { |
@@ -13,2 +13,3 @@ import type { APIMethodParams, APIMethods, TelegramInputFile } from "@gramio/types"; | ||
}; | ||
/** Guard for check is it File or Promise */ | ||
export declare function isFile(file?: TelegramInputFile | object | string): boolean; | ||
@@ -15,0 +16,0 @@ /** @codegenerated */ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MEDIA_METHODS = exports.isFile = void 0; | ||
/** Guard for check is it File or Promise */ | ||
function isFile(file) { | ||
@@ -5,0 +6,0 @@ if (!file || typeof file !== "object") |
@@ -23,5 +23,5 @@ /// <reference types="node" /> | ||
/** | ||
*Method for uploading Media File by text content. | ||
* Method for uploading Media File by text content. | ||
*/ | ||
static text(text: string, filename?: string): File; | ||
} |
@@ -42,3 +42,3 @@ "use strict"; | ||
/** | ||
*Method for uploading Media File by text content. | ||
* Method for uploading Media File by text content. | ||
*/ | ||
@@ -45,0 +45,0 @@ static text(text, filename = "text.txt") { |
@@ -5,4 +5,12 @@ /// <reference types="node" /> | ||
import type { APIMethodParams, APIMethods } from "@gramio/types"; | ||
/** Guard to check is method used for File Uploading */ | ||
export declare function isMediaUpload<T extends keyof APIMethods>(method: T, params: NonNullable<APIMethodParams<T>>): boolean; | ||
/** | ||
* Helper to convert JSON to FormData that can accept Telegram Bot API. | ||
* if File is not top-level property it will be `“attach://<file_attach_name>”` | ||
* | ||
* [Documentation](https://core.telegram.org/bots/api#inputfile) | ||
*/ | ||
export declare function convertJsonToFormData<T extends keyof APIMethods>(method: T, params: NonNullable<APIMethodParams<T>>): Promise<FormData>; | ||
/** Helper for convert Readable stream to buffer */ | ||
export declare function convertStreamToBuffer(stream: Readable): Promise<Buffer>; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const media_methods_helper_1 = require("./media-methods-helper"); | ||
/** Guard to check is method used for File Uploading */ | ||
function isMediaUpload(method, params) { | ||
@@ -21,2 +22,8 @@ const mediaMethod = media_methods_helper_1.MEDIA_METHODS[method]; | ||
} | ||
/** | ||
* Helper to convert JSON to FormData that can accept Telegram Bot API. | ||
* if File is not top-level property it will be `“attach://<file_attach_name>”` | ||
* | ||
* [Documentation](https://core.telegram.org/bots/api#inputfile) | ||
*/ | ||
async function convertJsonToFormData(method, params) { | ||
@@ -68,2 +75,3 @@ const formData = new FormData(); | ||
exports.convertJsonToFormData = convertJsonToFormData; | ||
/** Helper for convert Readable stream to buffer */ | ||
function convertStreamToBuffer(stream) { | ||
@@ -70,0 +78,0 @@ return new Promise((resolve) => { |
{ | ||
"name": "@gramio/files", | ||
"main": "./dist/index.js", | ||
"version": "0.0.5", | ||
"version": "0.0.7", | ||
"type": "commonjs", | ||
"description": "Library for uploading files to Telegram and etc with files", | ||
"description": "Set of utils for work with files and Telegram Bot API", | ||
"keywords": [ | ||
@@ -18,8 +18,9 @@ "gramio", | ||
"lint": "bunx @biomejs/biome check ./src", | ||
"lint:fix": "bun lint --apply" | ||
"lint:fix": "bun lint --apply", | ||
"jsr": "bun scripts/release-jsr.ts" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "1.6.4", | ||
"@types/bun": "^1.0.12", | ||
"@types/node": "^20.12.7", | ||
"@biomejs/biome": "1.7.3", | ||
"@types/bun": "^1.1.1", | ||
"@types/node": "^20.12.11", | ||
"prettier": "^3.2.5", | ||
@@ -29,3 +30,3 @@ "typescript": "^5.4.5" | ||
"dependencies": { | ||
"@gramio/types": "^7.2.1" | ||
"@gramio/types": "^7.3.4" | ||
}, | ||
@@ -32,0 +33,0 @@ "files": [ |
# @gramio/files | ||
[`@gramio/files`](https://github.com/gramiojs/files) is built-in GramIO plugin. You can also use it outside of this framework because it is framework-agnostic. | ||
[`@gramio/files`](https://github.com/gramiojs/files) is set of utils for work with files and Telegram Bot API. You can also use it outside of [GramIO](https://gramio.netlify.app/) framework because it is framework-agnostic. | ||
## Please see [Documentation](https://gramio.netlify.app/files/overview.html) | ||
[![npm](https://img.shields.io/npm/v/@gramio/files?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/@gramio/files) | ||
[![JSR](https://jsr.io/badges/@gramio/files)](https://jsr.io/@gramio/files) | ||
[![JSR Score](https://jsr.io/badges/@gramio/files/score)](https://jsr.io/@gramio/files) | ||
Currently, support Telegram Bot API v7.2 | ||
## Please see [Documentation](https://gramio.netlify.app/files/overview.html) and [API Reference](https://jsr.io/@gramio/files/doc) | ||
Currently, support Telegram Bot API v7.3+ |
17762
439
12
Updated@gramio/types@^7.3.4