gramio 0.0.28 → 0.0.30
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/dist/bot.d.ts +8 -3
- package/dist/bot.js +21 -1
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.js +24 -0
- package/package.json +6 -6
package/dist/bot.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CallbackData } from "@gramio/callback-data";
|
|
2
|
-
import type
|
|
2
|
+
import { type Attachment, type Context, type ContextType, type MaybeArray, type UpdateName } from "@gramio/contexts";
|
|
3
3
|
import type { APIMethodParams, APIMethods, SetMyCommandsParams, TelegramBotCommand, TelegramReactionTypeEmojiEmoji, TelegramUser } from "@gramio/types";
|
|
4
4
|
import { Plugin } from "./plugin";
|
|
5
5
|
import type { BotOptions, DeriveDefinitions, ErrorDefinitions, Handler, Hooks, MaybePromise, SuppressedAPIMethods } from "./types";
|
|
@@ -20,7 +20,12 @@ export declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends D
|
|
|
20
20
|
private runHooks;
|
|
21
21
|
private runImmutableHooks;
|
|
22
22
|
private _callApi;
|
|
23
|
-
downloadFile(
|
|
23
|
+
downloadFile(attachment: Attachment | {
|
|
24
|
+
file_id: string;
|
|
25
|
+
} | string): Promise<ArrayBuffer>;
|
|
26
|
+
downloadFile(attachment: Attachment | {
|
|
27
|
+
file_id: string;
|
|
28
|
+
} | string, path: string): Promise<string>;
|
|
24
29
|
/**
|
|
25
30
|
* Register custom class-error for type-safe catch in `onError` hook
|
|
26
31
|
*
|
|
@@ -104,7 +109,7 @@ export declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends D
|
|
|
104
109
|
args: string | null;
|
|
105
110
|
}) => unknown, options?: Omit<SetMyCommandsParams, "commands"> & Omit<TelegramBotCommand, "command">): this;
|
|
106
111
|
/** Currently not isolated!!! */
|
|
107
|
-
group(grouped: (bot: typeof this) => Bot<any, any>):
|
|
112
|
+
group(grouped: (bot: typeof this) => Bot<any, any>): typeof this;
|
|
108
113
|
init(): Promise<void>;
|
|
109
114
|
start({ webhook, dropPendingUpdates, allowedUpdates, }?: {
|
|
110
115
|
webhook?: Omit<APIMethodParams<"setWebhook">, "drop_pending_updates" | "allowed_updates">;
|
package/dist/bot.js
CHANGED
|
@@ -33,9 +33,14 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
33
33
|
}
|
|
34
34
|
return useValue ? value : void 0;
|
|
35
35
|
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
36
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
40
|
exports.Bot = void 0;
|
|
41
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
38
42
|
const callback_data_1 = require("@gramio/callback-data");
|
|
43
|
+
const contexts_1 = require("@gramio/contexts");
|
|
39
44
|
const files_1 = require("@gramio/files");
|
|
40
45
|
const format_1 = require("@gramio/format");
|
|
41
46
|
const inspectable_1 = require("inspectable");
|
|
@@ -163,11 +168,26 @@ let Bot = (() => {
|
|
|
163
168
|
});
|
|
164
169
|
return data.result;
|
|
165
170
|
}
|
|
166
|
-
async downloadFile(
|
|
171
|
+
async downloadFile(attachment, path) {
|
|
172
|
+
function getFileId(attachment) {
|
|
173
|
+
if (attachment instanceof contexts_1.PhotoAttachment) {
|
|
174
|
+
return attachment.bigSize.fileId;
|
|
175
|
+
}
|
|
176
|
+
if ("fileId" in attachment && typeof attachment.fileId === "string")
|
|
177
|
+
return attachment.fileId;
|
|
178
|
+
if ("file_id" in attachment)
|
|
179
|
+
return attachment.file_id;
|
|
180
|
+
throw new Error("Invalid attachment");
|
|
181
|
+
}
|
|
182
|
+
const fileId = typeof attachment === "string" ? attachment : getFileId(attachment);
|
|
167
183
|
const file = await this.api.getFile({ file_id: fileId });
|
|
168
184
|
const url = `https://api.telegram.org/file/bot${this.options.token}/${file.file_path}`;
|
|
169
185
|
const res = await fetch(url);
|
|
170
186
|
const buffer = await res.arrayBuffer();
|
|
187
|
+
if (path) {
|
|
188
|
+
await promises_1.default.writeFile(path, Buffer.from(buffer));
|
|
189
|
+
return path;
|
|
190
|
+
}
|
|
171
191
|
return buffer;
|
|
172
192
|
}
|
|
173
193
|
/**
|
package/dist/plugin.d.ts
CHANGED
|
@@ -19,6 +19,9 @@ export declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extend
|
|
|
19
19
|
MaybeArray<keyof APIMethods> | undefined
|
|
20
20
|
][];
|
|
21
21
|
groups: ((bot: Bot<any, any>) => Bot<any, any>)[];
|
|
22
|
+
onStarts: Hooks.OnStart[];
|
|
23
|
+
onStops: Hooks.OnStop[];
|
|
24
|
+
onErrors: Hooks.OnError<any, any>[];
|
|
22
25
|
name: string;
|
|
23
26
|
errorsDefinitions: Record<string, {
|
|
24
27
|
new (...args: any): any;
|
|
@@ -49,4 +52,8 @@ export declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extend
|
|
|
49
52
|
onResponse(handler: Hooks.OnResponse): this;
|
|
50
53
|
onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
|
|
51
54
|
onResponseError(handler: Hooks.OnResponseError): this;
|
|
55
|
+
onStart(handler: Hooks.OnStart): this;
|
|
56
|
+
onStop(handler: Hooks.OnStop): this;
|
|
57
|
+
onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<Bot, T> & Derives["global"] & Derives[T]>): this;
|
|
58
|
+
onError(handler: Hooks.OnError<Errors, Context<Bot> & Derives["global"]>): this;
|
|
52
59
|
}
|
package/dist/plugin.js
CHANGED
|
@@ -64,6 +64,9 @@ let Plugin = (() => {
|
|
|
64
64
|
onResponses = [];
|
|
65
65
|
onResponseErrors = [];
|
|
66
66
|
groups = [];
|
|
67
|
+
onStarts = [];
|
|
68
|
+
onStops = [];
|
|
69
|
+
onErrors = [];
|
|
67
70
|
name;
|
|
68
71
|
errorsDefinitions = {};
|
|
69
72
|
dependencies = [];
|
|
@@ -122,6 +125,27 @@ let Plugin = (() => {
|
|
|
122
125
|
this.onResponseErrors.push([methodsOrHandler, undefined]);
|
|
123
126
|
return this;
|
|
124
127
|
}
|
|
128
|
+
onStart(handler) {
|
|
129
|
+
this.onStarts.push(handler);
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
onStop(handler) {
|
|
133
|
+
this.onStops.push(handler);
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
onError(updateNameOrHandler, handler) {
|
|
137
|
+
if (typeof updateNameOrHandler === "function") {
|
|
138
|
+
this.onErrors.push(updateNameOrHandler);
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
if (handler) {
|
|
142
|
+
this.onErrors.push(async (errContext) => {
|
|
143
|
+
if (errContext.context.is(updateNameOrHandler))
|
|
144
|
+
await handler(errContext);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
125
149
|
};
|
|
126
150
|
return Plugin = _classThis;
|
|
127
151
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gramio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"description": "Powerful Telegram Bot API framework",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -24,20 +24,20 @@
|
|
|
24
24
|
"author": "kravets",
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@biomejs/biome": "1.
|
|
28
|
-
"@types/node": "^20.12.
|
|
27
|
+
"@biomejs/biome": "1.7.2",
|
|
28
|
+
"@types/node": "^20.12.8",
|
|
29
29
|
"typescript": "^5.4.5"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@gramio/callback-data": "^0.0.2",
|
|
33
|
-
"@gramio/contexts": "^0.0.
|
|
33
|
+
"@gramio/contexts": "^0.0.12",
|
|
34
34
|
"@gramio/files": "^0.0.5",
|
|
35
35
|
"@gramio/format": "^0.0.8",
|
|
36
36
|
"@gramio/keyboards": "^0.3.0",
|
|
37
|
-
"@gramio/types": "^7.2.
|
|
37
|
+
"@gramio/types": "^7.2.2",
|
|
38
38
|
"inspectable": "^3.0.0",
|
|
39
39
|
"middleware-io": "^2.8.1",
|
|
40
|
-
"undici": "^6.
|
|
40
|
+
"undici": "^6.15.0"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"dist"
|