gramio 0.4.9 → 0.4.11
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/index.cjs +33 -8
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +33 -8
- package/dist/utils.cjs +0 -0
- package/dist/utils.js +0 -0
- package/package.json +11 -9
package/dist/index.cjs
CHANGED
|
@@ -49,17 +49,17 @@ class Composer {
|
|
|
49
49
|
derive(updateNameOrHandler, handler) {
|
|
50
50
|
if (typeof updateNameOrHandler === "function")
|
|
51
51
|
this.use(async (context, next) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
context[key] = value;
|
|
52
|
+
const assign = await updateNameOrHandler(context);
|
|
53
|
+
for (const key in assign) {
|
|
54
|
+
context[key] = assign[key];
|
|
56
55
|
}
|
|
57
56
|
return await next();
|
|
58
57
|
});
|
|
59
58
|
else if (handler)
|
|
60
59
|
this.on(updateNameOrHandler, async (context, next) => {
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const assign = await handler(context);
|
|
61
|
+
for (const key in assign) {
|
|
62
|
+
context[key] = assign[key];
|
|
63
63
|
}
|
|
64
64
|
return await next();
|
|
65
65
|
});
|
|
@@ -1033,6 +1033,31 @@ class Bot {
|
|
|
1033
1033
|
return next();
|
|
1034
1034
|
});
|
|
1035
1035
|
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Register handler to `start` command when start parameter is matched
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```ts
|
|
1041
|
+
* new Bot().startParameter(/^ref_(.+)$/, (context) => {
|
|
1042
|
+
* return context.send(`Reference: ${context.rawStartPayload}`);
|
|
1043
|
+
* });
|
|
1044
|
+
* ```
|
|
1045
|
+
*/
|
|
1046
|
+
startParameter(parameter, handler) {
|
|
1047
|
+
return this.on("message", (context, next) => {
|
|
1048
|
+
if (!context.rawStartPayload) return next();
|
|
1049
|
+
if (parameter instanceof RegExp && parameter.test(context.rawStartPayload)) {
|
|
1050
|
+
return handler(context);
|
|
1051
|
+
}
|
|
1052
|
+
if (Array.isArray(parameter) && parameter.includes(context.rawStartPayload)) {
|
|
1053
|
+
return handler(context);
|
|
1054
|
+
}
|
|
1055
|
+
if (typeof parameter === "string" && parameter === context.rawStartPayload) {
|
|
1056
|
+
return handler(context);
|
|
1057
|
+
}
|
|
1058
|
+
return next();
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1036
1061
|
/** Currently not isolated!!! */
|
|
1037
1062
|
group(grouped) {
|
|
1038
1063
|
return grouped(this);
|
|
@@ -1228,7 +1253,7 @@ function webhookHandler(bot, framework, secretTokenOrOptions) {
|
|
|
1228
1253
|
const secretToken = typeof secretTokenOrOptions === "string" ? secretTokenOrOptions : secretTokenOrOptions?.secretToken;
|
|
1229
1254
|
const shouldWaitOptions = typeof secretTokenOrOptions === "string" ? false : secretTokenOrOptions?.shouldWait;
|
|
1230
1255
|
const isShouldWait = shouldWaitOptions && (typeof shouldWaitOptions === "object" || typeof shouldWaitOptions === "boolean");
|
|
1231
|
-
return async (...args) => {
|
|
1256
|
+
return (async (...args) => {
|
|
1232
1257
|
const { update, response, header, unauthorized } = frameworkAdapter(
|
|
1233
1258
|
...args
|
|
1234
1259
|
);
|
|
@@ -1247,7 +1272,7 @@ function webhookHandler(bot, framework, secretTokenOrOptions) {
|
|
|
1247
1272
|
);
|
|
1248
1273
|
if (response) return response();
|
|
1249
1274
|
}
|
|
1250
|
-
};
|
|
1275
|
+
});
|
|
1251
1276
|
}
|
|
1252
1277
|
|
|
1253
1278
|
Symbol.metadata ??= Symbol("Symbol.metadata");
|
package/dist/index.d.cts
CHANGED
|
@@ -980,6 +980,19 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
980
980
|
command(command: MaybeArray<string>, handler: (context: ContextType<typeof this, "message"> & {
|
|
981
981
|
args: string | null;
|
|
982
982
|
}) => unknown): this;
|
|
983
|
+
/**
|
|
984
|
+
* Register handler to `start` command when start parameter is matched
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```ts
|
|
988
|
+
* new Bot().startParameter(/^ref_(.+)$/, (context) => {
|
|
989
|
+
* return context.send(`Reference: ${context.rawStartPayload}`);
|
|
990
|
+
* });
|
|
991
|
+
* ```
|
|
992
|
+
*/
|
|
993
|
+
startParameter(parameter: RegExp | MaybeArray<string>, handler: Handler<ContextType<typeof this, "message"> & {
|
|
994
|
+
rawStartPayload: string;
|
|
995
|
+
}>): this;
|
|
983
996
|
/** Currently not isolated!!! */
|
|
984
997
|
group(grouped: (bot: typeof this) => AnyBot): typeof this;
|
|
985
998
|
/**
|
|
@@ -1114,4 +1127,5 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
|
|
|
1114
1127
|
response: () => any;
|
|
1115
1128
|
} ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
|
|
1116
1129
|
|
|
1117
|
-
export {
|
|
1130
|
+
export { Bot, Composer, ErrorKind, Hooks, Plugin, TelegramError, Updates, webhookHandler };
|
|
1131
|
+
export type { AllowedUpdates, AnyBot, AnyPlugin, BotOptions, BotStartOptions, BotStartOptionsLongPolling, BotStartOptionsWebhook, CallbackQueryShorthandContext, DeriveDefinitions, ErrorDefinitions, FilterDefinitions, Handler, MaybePromise, MaybeSuppressedParams, MaybeSuppressedReturn, PollingStartOptions, Suppress, SuppressedAPIMethodParams, SuppressedAPIMethodReturn, SuppressedAPIMethods, WebhookHandlerOptions, WebhookHandlerOptionsShouldWait, WebhookHandlers };
|
package/dist/index.d.ts
CHANGED
|
@@ -980,6 +980,19 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
980
980
|
command(command: MaybeArray<string>, handler: (context: ContextType<typeof this, "message"> & {
|
|
981
981
|
args: string | null;
|
|
982
982
|
}) => unknown): this;
|
|
983
|
+
/**
|
|
984
|
+
* Register handler to `start` command when start parameter is matched
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```ts
|
|
988
|
+
* new Bot().startParameter(/^ref_(.+)$/, (context) => {
|
|
989
|
+
* return context.send(`Reference: ${context.rawStartPayload}`);
|
|
990
|
+
* });
|
|
991
|
+
* ```
|
|
992
|
+
*/
|
|
993
|
+
startParameter(parameter: RegExp | MaybeArray<string>, handler: Handler<ContextType<typeof this, "message"> & {
|
|
994
|
+
rawStartPayload: string;
|
|
995
|
+
}>): this;
|
|
983
996
|
/** Currently not isolated!!! */
|
|
984
997
|
group(grouped: (bot: typeof this) => AnyBot): typeof this;
|
|
985
998
|
/**
|
|
@@ -1114,4 +1127,5 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
|
|
|
1114
1127
|
response: () => any;
|
|
1115
1128
|
} ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
|
|
1116
1129
|
|
|
1117
|
-
export {
|
|
1130
|
+
export { Bot, Composer, ErrorKind, Hooks, Plugin, TelegramError, Updates, webhookHandler };
|
|
1131
|
+
export type { AllowedUpdates, AnyBot, AnyPlugin, BotOptions, BotStartOptions, BotStartOptionsLongPolling, BotStartOptionsWebhook, CallbackQueryShorthandContext, DeriveDefinitions, ErrorDefinitions, FilterDefinitions, Handler, MaybePromise, MaybeSuppressedParams, MaybeSuppressedReturn, PollingStartOptions, Suppress, SuppressedAPIMethodParams, SuppressedAPIMethodReturn, SuppressedAPIMethods, WebhookHandlerOptions, WebhookHandlerOptionsShouldWait, WebhookHandlers };
|
package/dist/index.js
CHANGED
|
@@ -51,17 +51,17 @@ class Composer {
|
|
|
51
51
|
derive(updateNameOrHandler, handler) {
|
|
52
52
|
if (typeof updateNameOrHandler === "function")
|
|
53
53
|
this.use(async (context, next) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
context[key] = value;
|
|
54
|
+
const assign = await updateNameOrHandler(context);
|
|
55
|
+
for (const key in assign) {
|
|
56
|
+
context[key] = assign[key];
|
|
58
57
|
}
|
|
59
58
|
return await next();
|
|
60
59
|
});
|
|
61
60
|
else if (handler)
|
|
62
61
|
this.on(updateNameOrHandler, async (context, next) => {
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const assign = await handler(context);
|
|
63
|
+
for (const key in assign) {
|
|
64
|
+
context[key] = assign[key];
|
|
65
65
|
}
|
|
66
66
|
return await next();
|
|
67
67
|
});
|
|
@@ -1035,6 +1035,31 @@ class Bot {
|
|
|
1035
1035
|
return next();
|
|
1036
1036
|
});
|
|
1037
1037
|
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Register handler to `start` command when start parameter is matched
|
|
1040
|
+
*
|
|
1041
|
+
* @example
|
|
1042
|
+
* ```ts
|
|
1043
|
+
* new Bot().startParameter(/^ref_(.+)$/, (context) => {
|
|
1044
|
+
* return context.send(`Reference: ${context.rawStartPayload}`);
|
|
1045
|
+
* });
|
|
1046
|
+
* ```
|
|
1047
|
+
*/
|
|
1048
|
+
startParameter(parameter, handler) {
|
|
1049
|
+
return this.on("message", (context, next) => {
|
|
1050
|
+
if (!context.rawStartPayload) return next();
|
|
1051
|
+
if (parameter instanceof RegExp && parameter.test(context.rawStartPayload)) {
|
|
1052
|
+
return handler(context);
|
|
1053
|
+
}
|
|
1054
|
+
if (Array.isArray(parameter) && parameter.includes(context.rawStartPayload)) {
|
|
1055
|
+
return handler(context);
|
|
1056
|
+
}
|
|
1057
|
+
if (typeof parameter === "string" && parameter === context.rawStartPayload) {
|
|
1058
|
+
return handler(context);
|
|
1059
|
+
}
|
|
1060
|
+
return next();
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1038
1063
|
/** Currently not isolated!!! */
|
|
1039
1064
|
group(grouped) {
|
|
1040
1065
|
return grouped(this);
|
|
@@ -1230,7 +1255,7 @@ function webhookHandler(bot, framework, secretTokenOrOptions) {
|
|
|
1230
1255
|
const secretToken = typeof secretTokenOrOptions === "string" ? secretTokenOrOptions : secretTokenOrOptions?.secretToken;
|
|
1231
1256
|
const shouldWaitOptions = typeof secretTokenOrOptions === "string" ? false : secretTokenOrOptions?.shouldWait;
|
|
1232
1257
|
const isShouldWait = shouldWaitOptions && (typeof shouldWaitOptions === "object" || typeof shouldWaitOptions === "boolean");
|
|
1233
|
-
return async (...args) => {
|
|
1258
|
+
return (async (...args) => {
|
|
1234
1259
|
const { update, response, header, unauthorized } = frameworkAdapter(
|
|
1235
1260
|
...args
|
|
1236
1261
|
);
|
|
@@ -1249,7 +1274,7 @@ function webhookHandler(bot, framework, secretTokenOrOptions) {
|
|
|
1249
1274
|
);
|
|
1250
1275
|
if (response) return response();
|
|
1251
1276
|
}
|
|
1252
|
-
};
|
|
1277
|
+
});
|
|
1253
1278
|
}
|
|
1254
1279
|
|
|
1255
1280
|
Symbol.metadata ??= Symbol("Symbol.metadata");
|
package/dist/utils.cjs
CHANGED
|
File without changes
|
package/dist/utils.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gramio",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.11",
|
|
5
5
|
"description": "Powerful, extensible and really type-safe Telegram Bot API framework",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -55,22 +55,24 @@
|
|
|
55
55
|
"author": "kravets",
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@biomejs/biome": "1.
|
|
59
|
-
"@types/bun": "^1.2.
|
|
58
|
+
"@biomejs/biome": "2.1.1",
|
|
59
|
+
"@types/bun": "^1.2.18",
|
|
60
60
|
"@types/debug": "^4.1.12",
|
|
61
|
-
"expect-type": "^1.2.
|
|
62
|
-
"pkgroll": "^2.
|
|
61
|
+
"expect-type": "^1.2.2",
|
|
62
|
+
"pkgroll": "^2.14.1",
|
|
63
63
|
"typescript": "^5.8.3"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@gramio/callback-data": "^0.0.3",
|
|
67
|
-
"@gramio/contexts": "^0.
|
|
67
|
+
"@gramio/contexts": "^0.3.0",
|
|
68
68
|
"@gramio/files": "^0.3.0",
|
|
69
|
-
"@gramio/format": "^0.
|
|
69
|
+
"@gramio/format": "^0.3.3",
|
|
70
70
|
"@gramio/keyboards": "^1.2.1",
|
|
71
|
-
"@gramio/types": "^9.
|
|
71
|
+
"@gramio/types": "^9.1.3",
|
|
72
72
|
"debug": "^4.4.1",
|
|
73
73
|
"middleware-io": "^2.8.1"
|
|
74
74
|
},
|
|
75
|
-
"files": [
|
|
75
|
+
"files": [
|
|
76
|
+
"dist"
|
|
77
|
+
]
|
|
76
78
|
}
|