grammy-tools 1.36.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +339 -0
- package/out/bot.d.ts +314 -0
- package/out/bot.js +669 -0
- package/out/composer.d.ts +764 -0
- package/out/composer.js +704 -0
- package/out/context.d.ts +1618 -0
- package/out/context.js +1976 -0
- package/out/convenience/constants.d.ts +98 -0
- package/out/convenience/constants.js +37 -0
- package/out/convenience/frameworks.d.ts +216 -0
- package/out/convenience/frameworks.js +370 -0
- package/out/convenience/inline_query.d.ts +401 -0
- package/out/convenience/inline_query.js +461 -0
- package/out/convenience/input_media.d.ts +72 -0
- package/out/convenience/input_media.js +82 -0
- package/out/convenience/keyboard.d.ts +763 -0
- package/out/convenience/keyboard.js +935 -0
- package/out/convenience/session.d.ts +345 -0
- package/out/convenience/session.js +455 -0
- package/out/convenience/webhook.d.ts +59 -0
- package/out/convenience/webhook.js +80 -0
- package/out/core/api.d.ts +1628 -0
- package/out/core/api.js +1907 -0
- package/out/core/client.d.ts +180 -0
- package/out/core/client.js +226 -0
- package/out/core/error.d.ts +53 -0
- package/out/core/error.js +87 -0
- package/out/core/payload.d.ts +39 -0
- package/out/core/payload.js +199 -0
- package/out/filter.d.ts +959 -0
- package/out/filter.js +378 -0
- package/out/mod.d.ts +14 -0
- package/out/mod.js +43 -0
- package/out/platform.node.d.ts +16 -0
- package/out/platform.node.js +43 -0
- package/out/shim.node.d.ts +2 -0
- package/out/shim.node.js +7 -0
- package/out/types.d.ts +1 -0
- package/out/types.js +17 -0
- package/out/types.node.d.ts +78 -0
- package/out/types.node.js +107 -0
- package/out/web.d.ts +1 -0
- package/out/web.mjs +5172 -0
- package/package.json +71 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.InputFile = void 0;
|
|
18
|
+
const fs_1 = require("fs");
|
|
19
|
+
const node_fetch_1 = require("node-fetch");
|
|
20
|
+
const path_1 = require("path");
|
|
21
|
+
const platform_node_1 = require("./platform.node");
|
|
22
|
+
const debug = (0, platform_node_1.debug)("grammy:warn");
|
|
23
|
+
// === Export all API types
|
|
24
|
+
__exportStar(require("@grammyjs/types"), exports);
|
|
25
|
+
// === InputFile handling and File augmenting
|
|
26
|
+
/**
|
|
27
|
+
* An `InputFile` wraps a number of different sources for [sending
|
|
28
|
+
* files](https://grammy.dev/guide/files#uploading-your-own-files).
|
|
29
|
+
*
|
|
30
|
+
* It corresponds to the `InputFile` type in the [Telegram Bot API
|
|
31
|
+
* Reference](https://core.telegram.org/bots/api#inputfile).
|
|
32
|
+
*/
|
|
33
|
+
class InputFile {
|
|
34
|
+
/**
|
|
35
|
+
* Constructs an `InputFile` that can be used in the API to send files.
|
|
36
|
+
*
|
|
37
|
+
* @param file A path to a local file or a `Buffer` or a `fs.ReadStream` that specifies the file data
|
|
38
|
+
* @param filename Optional name of the file
|
|
39
|
+
*/
|
|
40
|
+
constructor(file, filename) {
|
|
41
|
+
this.consumed = false;
|
|
42
|
+
this.fileData = file;
|
|
43
|
+
filename !== null && filename !== void 0 ? filename : (filename = this.guessFilename(file));
|
|
44
|
+
this.filename = filename;
|
|
45
|
+
if (typeof file === "string" &&
|
|
46
|
+
(file.startsWith("http:") || file.startsWith("https:"))) {
|
|
47
|
+
debug(`InputFile received the local file path '${file}' that looks like a URL. Is this a mistake?`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
guessFilename(file) {
|
|
51
|
+
if (typeof file === "string")
|
|
52
|
+
return (0, path_1.basename)(file);
|
|
53
|
+
if ("url" in file)
|
|
54
|
+
return (0, path_1.basename)(file.url);
|
|
55
|
+
if (!(file instanceof URL))
|
|
56
|
+
return undefined;
|
|
57
|
+
if (file.pathname !== "/") {
|
|
58
|
+
const filename = (0, path_1.basename)(file.pathname);
|
|
59
|
+
if (filename)
|
|
60
|
+
return filename;
|
|
61
|
+
}
|
|
62
|
+
return (0, path_1.basename)(file.hostname);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Internal method. Do not use.
|
|
66
|
+
*
|
|
67
|
+
* Converts this instance into a binary representation that can be sent to
|
|
68
|
+
* the Bot API server in the request body.
|
|
69
|
+
*/
|
|
70
|
+
async toRaw() {
|
|
71
|
+
if (this.consumed) {
|
|
72
|
+
throw new Error("Cannot reuse InputFile data source!");
|
|
73
|
+
}
|
|
74
|
+
const data = this.fileData;
|
|
75
|
+
// Handle local files
|
|
76
|
+
if (typeof data === "string")
|
|
77
|
+
return (0, fs_1.createReadStream)(data);
|
|
78
|
+
// Handle URLs and URLLike objects
|
|
79
|
+
if (data instanceof URL) {
|
|
80
|
+
return data.protocol === "file" // node-fetch does not support file URLs
|
|
81
|
+
? (0, fs_1.createReadStream)(data.pathname)
|
|
82
|
+
: fetchFile(data);
|
|
83
|
+
}
|
|
84
|
+
if ("url" in data)
|
|
85
|
+
return fetchFile(data.url);
|
|
86
|
+
// Return buffers as-is
|
|
87
|
+
if (data instanceof Uint8Array)
|
|
88
|
+
return data;
|
|
89
|
+
// Unwrap supplier functions
|
|
90
|
+
if (typeof data === "function") {
|
|
91
|
+
return new InputFile(await data()).toRaw();
|
|
92
|
+
}
|
|
93
|
+
// Mark streams and iterators as consumed and return them as-is
|
|
94
|
+
this.consumed = true;
|
|
95
|
+
return data;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.InputFile = InputFile;
|
|
99
|
+
async function* fetchFile(url) {
|
|
100
|
+
const { body } = await (0, node_fetch_1.default)(url);
|
|
101
|
+
for await (const chunk of body) {
|
|
102
|
+
if (typeof chunk === "string") {
|
|
103
|
+
throw new Error(`Could not transfer file, received string data instead of bytes from '${url}'`);
|
|
104
|
+
}
|
|
105
|
+
yield chunk;
|
|
106
|
+
}
|
|
107
|
+
}
|
package/out/web.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./mod";
|