gramio 0.4.3 → 0.4.5

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 CHANGED
@@ -6,10 +6,10 @@ var callbackData = require('@gramio/callback-data');
6
6
  var contexts = require('@gramio/contexts');
7
7
  var files = require('@gramio/files');
8
8
  var format = require('@gramio/format');
9
- var utils = require('./utils-BIdmQNPz.cjs');
9
+ var debug = require('debug');
10
+ var utils = require('./utils-CYIya32k.cjs');
10
11
  var middlewareIo = require('middleware-io');
11
12
  var keyboards = require('@gramio/keyboards');
12
- require('debug');
13
13
 
14
14
  class Composer {
15
15
  composer = middlewareIo.Composer.builder();
@@ -518,7 +518,7 @@ class Bot {
518
518
  }
519
519
  }
520
520
  async _callApi(method, params = {}) {
521
- const debug$api$method = utils.debug$api.extend(method);
521
+ const debug$api$method = debug(`gramio:api:${method}`);
522
522
  let url = `${this.options.api.baseURL}${this.options.token}/${this.options.api.useTest ? "test/" : ""}${method}`;
523
523
  const reqOptions = {
524
524
  method: "POST",
@@ -1125,8 +1125,9 @@ class Bot {
1125
1125
 
1126
1126
  const SECRET_TOKEN_HEADER = "X-Telegram-Bot-Api-Secret-Token";
1127
1127
  const WRONG_TOKEN_ERROR = "secret token is invalid";
1128
- const responseOK = new Response("ok!");
1129
- const responseUnauthorized = new Response(WRONG_TOKEN_ERROR, {
1128
+ const RESPONSE_OK = "ok!";
1129
+ const responseOK = () => new Response(RESPONSE_OK);
1130
+ const responseUnauthorized = () => new Response(WRONG_TOKEN_ERROR, {
1130
1131
  status: 401
1131
1132
  // @ts-ignore
1132
1133
  });
@@ -1134,22 +1135,26 @@ const frameworks = {
1134
1135
  elysia: ({ body, headers }) => ({
1135
1136
  update: body,
1136
1137
  header: headers[SECRET_TOKEN_HEADER],
1137
- unauthorized: () => responseUnauthorized
1138
+ unauthorized: responseUnauthorized,
1139
+ response: responseOK
1138
1140
  }),
1139
1141
  fastify: (request, reply) => ({
1140
1142
  update: request.body,
1141
1143
  header: request.headers[SECRET_TOKEN_HEADER],
1142
- unauthorized: () => reply.code(401).send(WRONG_TOKEN_ERROR)
1144
+ unauthorized: () => reply.code(401).send(WRONG_TOKEN_ERROR),
1145
+ response: () => reply.send(RESPONSE_OK)
1143
1146
  }),
1144
1147
  hono: (c) => ({
1145
1148
  update: c.req.json(),
1146
1149
  header: c.req.header(SECRET_TOKEN_HEADER),
1147
- unauthorized: () => c.text(WRONG_TOKEN_ERROR, 401)
1150
+ unauthorized: () => c.text(WRONG_TOKEN_ERROR, 401),
1151
+ response: responseOK
1148
1152
  }),
1149
1153
  express: (req, res) => ({
1150
1154
  update: req.body,
1151
1155
  header: req.header(SECRET_TOKEN_HEADER),
1152
- unauthorized: () => res.status(401).send(WRONG_TOKEN_ERROR)
1156
+ unauthorized: () => res.status(401).send(WRONG_TOKEN_ERROR),
1157
+ response: () => res.send(RESPONSE_OK)
1153
1158
  }),
1154
1159
  koa: (ctx) => ({
1155
1160
  update: ctx.request.body,
@@ -1157,6 +1162,10 @@ const frameworks = {
1157
1162
  unauthorized: () => {
1158
1163
  ctx.status === 401;
1159
1164
  ctx.body = WRONG_TOKEN_ERROR;
1165
+ },
1166
+ response: () => {
1167
+ ctx.status = 200;
1168
+ ctx.body = RESPONSE_OK;
1160
1169
  }
1161
1170
  }),
1162
1171
  http: (req, res) => ({
@@ -1168,31 +1177,59 @@ const frameworks = {
1168
1177
  req.on("end", () => resolve(JSON.parse(body)));
1169
1178
  }),
1170
1179
  header: req.headers[SECRET_TOKEN_HEADER.toLowerCase()],
1171
- unauthorized: () => res.writeHead(401).end(WRONG_TOKEN_ERROR)
1180
+ unauthorized: () => res.writeHead(401).end(WRONG_TOKEN_ERROR),
1181
+ response: () => res.writeHead(200).end(RESPONSE_OK)
1172
1182
  }),
1173
1183
  "std/http": (req) => ({
1174
1184
  update: req.json(),
1175
1185
  header: req.headers.get(SECRET_TOKEN_HEADER),
1176
- response: () => responseOK,
1177
- unauthorized: () => responseUnauthorized
1186
+ response: responseOK,
1187
+ unauthorized: responseUnauthorized
1178
1188
  }),
1179
1189
  "Bun.serve": (req) => ({
1180
1190
  update: req.json(),
1181
1191
  header: req.headers.get(SECRET_TOKEN_HEADER),
1182
- response: () => responseOK,
1183
- unauthorized: () => responseUnauthorized
1192
+ response: responseOK,
1193
+ unauthorized: responseUnauthorized
1194
+ }),
1195
+ cloudflare: (req) => ({
1196
+ update: req.json(),
1197
+ header: req.headers.get(SECRET_TOKEN_HEADER),
1198
+ response: responseOK,
1199
+ unauthorized: responseUnauthorized
1200
+ }),
1201
+ Request: (req) => ({
1202
+ update: req.json(),
1203
+ header: req.headers.get(SECRET_TOKEN_HEADER),
1204
+ response: responseOK,
1205
+ unauthorized: responseUnauthorized
1184
1206
  })
1185
1207
  };
1186
1208
 
1187
- function webhookHandler(bot, framework, secretToken) {
1209
+ function webhookHandler(bot, framework, secretTokenOrOptions) {
1188
1210
  const frameworkAdapter = frameworks[framework];
1211
+ const secretToken = typeof secretTokenOrOptions === "string" ? secretTokenOrOptions : secretTokenOrOptions?.secretToken;
1212
+ const shouldWaitOptions = typeof secretTokenOrOptions === "string" ? false : secretTokenOrOptions?.shouldWait;
1213
+ const isShouldWait = shouldWaitOptions && (typeof shouldWaitOptions === "object" || typeof shouldWaitOptions === "boolean");
1189
1214
  return async (...args) => {
1190
1215
  const { update, response, header, unauthorized } = frameworkAdapter(
1191
1216
  ...args
1192
1217
  );
1193
1218
  if (secretToken && header !== secretToken) return unauthorized();
1194
- bot.updates.queue.add(await update);
1195
- if (response) return response();
1219
+ if (!isShouldWait) {
1220
+ bot.updates.queue.add(await update);
1221
+ if (response) return response();
1222
+ } else {
1223
+ const timeoutOptions = typeof shouldWaitOptions === "object" ? shouldWaitOptions : void 0;
1224
+ const timeout = timeoutOptions?.timeout ?? 3e4;
1225
+ const onTimeout = timeoutOptions?.onTimeout ?? "throw";
1226
+ await utils.timeoutWebhook(
1227
+ bot.updates.handleUpdate(await update, "wait"),
1228
+ timeout,
1229
+ onTimeout
1230
+ );
1231
+ if (response) return response();
1232
+ }
1196
1233
  };
1197
1234
  }
1198
1235
 
package/dist/index.d.cts CHANGED
@@ -1012,31 +1012,37 @@ declare const frameworks: {
1012
1012
  update: any;
1013
1013
  header: any;
1014
1014
  unauthorized: () => Response;
1015
+ response: () => Response;
1015
1016
  };
1016
1017
  fastify: (request: any, reply: any) => {
1017
1018
  update: any;
1018
1019
  header: any;
1019
1020
  unauthorized: () => any;
1021
+ response: () => any;
1020
1022
  };
1021
1023
  hono: (c: any) => {
1022
1024
  update: any;
1023
1025
  header: any;
1024
1026
  unauthorized: () => any;
1027
+ response: () => Response;
1025
1028
  };
1026
1029
  express: (req: any, res: any) => {
1027
1030
  update: any;
1028
1031
  header: any;
1029
1032
  unauthorized: () => any;
1033
+ response: () => any;
1030
1034
  };
1031
1035
  koa: (ctx: any) => {
1032
1036
  update: any;
1033
1037
  header: any;
1034
1038
  unauthorized: () => void;
1039
+ response: () => void;
1035
1040
  };
1036
1041
  http: (req: any, res: any) => {
1037
1042
  update: Promise<TelegramUpdate>;
1038
1043
  header: any;
1039
1044
  unauthorized: () => any;
1045
+ response: () => any;
1040
1046
  };
1041
1047
  "std/http": (req: any) => {
1042
1048
  update: any;
@@ -1050,10 +1056,32 @@ declare const frameworks: {
1050
1056
  response: () => Response;
1051
1057
  unauthorized: () => Response;
1052
1058
  };
1059
+ cloudflare: (req: any) => {
1060
+ update: any;
1061
+ header: any;
1062
+ response: () => Response;
1063
+ unauthorized: () => Response;
1064
+ };
1065
+ Request: (req: any) => {
1066
+ update: any;
1067
+ header: any;
1068
+ response: () => Response;
1069
+ unauthorized: () => Response;
1070
+ };
1053
1071
  };
1054
1072
 
1055
1073
  /** Union type of webhook handlers name */
1056
1074
  type WebhookHandlers = keyof typeof frameworks;
1075
+ interface WebhookHandlerOptionsShouldWait {
1076
+ /** Action to take when timeout occurs. @default "throw" */
1077
+ onTimeout?: "throw" | "return";
1078
+ /** Timeout in milliseconds. @default 10_000 */
1079
+ timeout?: number;
1080
+ }
1081
+ interface WebhookHandlerOptions {
1082
+ secretToken?: string;
1083
+ shouldWait?: boolean | WebhookHandlerOptionsShouldWait;
1084
+ }
1057
1085
  /**
1058
1086
  * Setup handler with yours web-framework to receive updates via webhook
1059
1087
  *
@@ -1082,8 +1110,8 @@ type WebhookHandlers = keyof typeof frameworks;
1082
1110
  * });
1083
1111
  * ```
1084
1112
  */
1085
- declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: Bot, framework: Framework, secretToken?: string): ReturnType<(typeof frameworks)[Framework]> extends {
1113
+ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: Bot, framework: Framework, secretTokenOrOptions?: string | WebhookHandlerOptions): ReturnType<(typeof frameworks)[Framework]> extends {
1086
1114
  response: () => any;
1087
1115
  } ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
1088
1116
 
1089
- export { type AllowedUpdates, type AnyBot, type AnyPlugin, Bot, type BotOptions, type BotStartOptions, type BotStartOptionsLongPolling, type BotStartOptionsWebhook, type CallbackQueryShorthandContext, Composer, type DeriveDefinitions, type ErrorDefinitions, ErrorKind, type FilterDefinitions, type Handler, Hooks, type MaybePromise, type MaybeSuppressedParams, type MaybeSuppressedReturn, Plugin, type PollingStartOptions, type Suppress, type SuppressedAPIMethodParams, type SuppressedAPIMethodReturn, type SuppressedAPIMethods, TelegramError, Updates, type WebhookHandlers, webhookHandler };
1117
+ export { type AllowedUpdates, type AnyBot, type AnyPlugin, Bot, type BotOptions, type BotStartOptions, type BotStartOptionsLongPolling, type BotStartOptionsWebhook, type CallbackQueryShorthandContext, Composer, type DeriveDefinitions, type ErrorDefinitions, ErrorKind, type FilterDefinitions, type Handler, Hooks, type MaybePromise, type MaybeSuppressedParams, type MaybeSuppressedReturn, Plugin, type PollingStartOptions, type Suppress, type SuppressedAPIMethodParams, type SuppressedAPIMethodReturn, type SuppressedAPIMethods, TelegramError, Updates, type WebhookHandlerOptions, type WebhookHandlerOptionsShouldWait, type WebhookHandlers, webhookHandler };
package/dist/index.d.ts CHANGED
@@ -1012,31 +1012,37 @@ declare const frameworks: {
1012
1012
  update: any;
1013
1013
  header: any;
1014
1014
  unauthorized: () => Response;
1015
+ response: () => Response;
1015
1016
  };
1016
1017
  fastify: (request: any, reply: any) => {
1017
1018
  update: any;
1018
1019
  header: any;
1019
1020
  unauthorized: () => any;
1021
+ response: () => any;
1020
1022
  };
1021
1023
  hono: (c: any) => {
1022
1024
  update: any;
1023
1025
  header: any;
1024
1026
  unauthorized: () => any;
1027
+ response: () => Response;
1025
1028
  };
1026
1029
  express: (req: any, res: any) => {
1027
1030
  update: any;
1028
1031
  header: any;
1029
1032
  unauthorized: () => any;
1033
+ response: () => any;
1030
1034
  };
1031
1035
  koa: (ctx: any) => {
1032
1036
  update: any;
1033
1037
  header: any;
1034
1038
  unauthorized: () => void;
1039
+ response: () => void;
1035
1040
  };
1036
1041
  http: (req: any, res: any) => {
1037
1042
  update: Promise<TelegramUpdate>;
1038
1043
  header: any;
1039
1044
  unauthorized: () => any;
1045
+ response: () => any;
1040
1046
  };
1041
1047
  "std/http": (req: any) => {
1042
1048
  update: any;
@@ -1050,10 +1056,32 @@ declare const frameworks: {
1050
1056
  response: () => Response;
1051
1057
  unauthorized: () => Response;
1052
1058
  };
1059
+ cloudflare: (req: any) => {
1060
+ update: any;
1061
+ header: any;
1062
+ response: () => Response;
1063
+ unauthorized: () => Response;
1064
+ };
1065
+ Request: (req: any) => {
1066
+ update: any;
1067
+ header: any;
1068
+ response: () => Response;
1069
+ unauthorized: () => Response;
1070
+ };
1053
1071
  };
1054
1072
 
1055
1073
  /** Union type of webhook handlers name */
1056
1074
  type WebhookHandlers = keyof typeof frameworks;
1075
+ interface WebhookHandlerOptionsShouldWait {
1076
+ /** Action to take when timeout occurs. @default "throw" */
1077
+ onTimeout?: "throw" | "return";
1078
+ /** Timeout in milliseconds. @default 10_000 */
1079
+ timeout?: number;
1080
+ }
1081
+ interface WebhookHandlerOptions {
1082
+ secretToken?: string;
1083
+ shouldWait?: boolean | WebhookHandlerOptionsShouldWait;
1084
+ }
1057
1085
  /**
1058
1086
  * Setup handler with yours web-framework to receive updates via webhook
1059
1087
  *
@@ -1082,8 +1110,8 @@ type WebhookHandlers = keyof typeof frameworks;
1082
1110
  * });
1083
1111
  * ```
1084
1112
  */
1085
- declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: Bot, framework: Framework, secretToken?: string): ReturnType<(typeof frameworks)[Framework]> extends {
1113
+ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: Bot, framework: Framework, secretTokenOrOptions?: string | WebhookHandlerOptions): ReturnType<(typeof frameworks)[Framework]> extends {
1086
1114
  response: () => any;
1087
1115
  } ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
1088
1116
 
1089
- export { type AllowedUpdates, type AnyBot, type AnyPlugin, Bot, type BotOptions, type BotStartOptions, type BotStartOptionsLongPolling, type BotStartOptionsWebhook, type CallbackQueryShorthandContext, Composer, type DeriveDefinitions, type ErrorDefinitions, ErrorKind, type FilterDefinitions, type Handler, Hooks, type MaybePromise, type MaybeSuppressedParams, type MaybeSuppressedReturn, Plugin, type PollingStartOptions, type Suppress, type SuppressedAPIMethodParams, type SuppressedAPIMethodReturn, type SuppressedAPIMethods, TelegramError, Updates, type WebhookHandlers, webhookHandler };
1117
+ export { type AllowedUpdates, type AnyBot, type AnyPlugin, Bot, type BotOptions, type BotStartOptions, type BotStartOptionsLongPolling, type BotStartOptionsWebhook, type CallbackQueryShorthandContext, Composer, type DeriveDefinitions, type ErrorDefinitions, ErrorKind, type FilterDefinitions, type Handler, Hooks, type MaybePromise, type MaybeSuppressedParams, type MaybeSuppressedReturn, Plugin, type PollingStartOptions, type Suppress, type SuppressedAPIMethodParams, type SuppressedAPIMethodReturn, type SuppressedAPIMethods, TelegramError, Updates, type WebhookHandlerOptions, type WebhookHandlerOptionsShouldWait, type WebhookHandlers, webhookHandler };
package/dist/index.js CHANGED
@@ -8,10 +8,10 @@ import { isMediaUpload, convertJsonToFormData, extractFilesToFormData } from '@g
8
8
  export * from '@gramio/files';
9
9
  import { FormattableMap } from '@gramio/format';
10
10
  export * from '@gramio/format';
11
- import { E as ErrorKind, s as sleep, w as withRetries, T as TelegramError, d as debug$updates, a as debug$api, I as IS_BUN, b as simplifyObject } from './utils-CV4fnsQV.js';
11
+ import debug from 'debug';
12
+ import { E as ErrorKind, s as sleep, w as withRetries, T as TelegramError, d as debug$updates, I as IS_BUN, a as simplifyObject, t as timeoutWebhook } from './utils-CJfJNxc_.js';
12
13
  import { Composer as Composer$1, noopNext } from 'middleware-io';
13
14
  export * from '@gramio/keyboards';
14
- import 'debug';
15
15
 
16
16
  class Composer {
17
17
  composer = Composer$1.builder();
@@ -520,7 +520,7 @@ class Bot {
520
520
  }
521
521
  }
522
522
  async _callApi(method, params = {}) {
523
- const debug$api$method = debug$api.extend(method);
523
+ const debug$api$method = debug(`gramio:api:${method}`);
524
524
  let url = `${this.options.api.baseURL}${this.options.token}/${this.options.api.useTest ? "test/" : ""}${method}`;
525
525
  const reqOptions = {
526
526
  method: "POST",
@@ -1127,8 +1127,9 @@ class Bot {
1127
1127
 
1128
1128
  const SECRET_TOKEN_HEADER = "X-Telegram-Bot-Api-Secret-Token";
1129
1129
  const WRONG_TOKEN_ERROR = "secret token is invalid";
1130
- const responseOK = new Response("ok!");
1131
- const responseUnauthorized = new Response(WRONG_TOKEN_ERROR, {
1130
+ const RESPONSE_OK = "ok!";
1131
+ const responseOK = () => new Response(RESPONSE_OK);
1132
+ const responseUnauthorized = () => new Response(WRONG_TOKEN_ERROR, {
1132
1133
  status: 401
1133
1134
  // @ts-ignore
1134
1135
  });
@@ -1136,22 +1137,26 @@ const frameworks = {
1136
1137
  elysia: ({ body, headers }) => ({
1137
1138
  update: body,
1138
1139
  header: headers[SECRET_TOKEN_HEADER],
1139
- unauthorized: () => responseUnauthorized
1140
+ unauthorized: responseUnauthorized,
1141
+ response: responseOK
1140
1142
  }),
1141
1143
  fastify: (request, reply) => ({
1142
1144
  update: request.body,
1143
1145
  header: request.headers[SECRET_TOKEN_HEADER],
1144
- unauthorized: () => reply.code(401).send(WRONG_TOKEN_ERROR)
1146
+ unauthorized: () => reply.code(401).send(WRONG_TOKEN_ERROR),
1147
+ response: () => reply.send(RESPONSE_OK)
1145
1148
  }),
1146
1149
  hono: (c) => ({
1147
1150
  update: c.req.json(),
1148
1151
  header: c.req.header(SECRET_TOKEN_HEADER),
1149
- unauthorized: () => c.text(WRONG_TOKEN_ERROR, 401)
1152
+ unauthorized: () => c.text(WRONG_TOKEN_ERROR, 401),
1153
+ response: responseOK
1150
1154
  }),
1151
1155
  express: (req, res) => ({
1152
1156
  update: req.body,
1153
1157
  header: req.header(SECRET_TOKEN_HEADER),
1154
- unauthorized: () => res.status(401).send(WRONG_TOKEN_ERROR)
1158
+ unauthorized: () => res.status(401).send(WRONG_TOKEN_ERROR),
1159
+ response: () => res.send(RESPONSE_OK)
1155
1160
  }),
1156
1161
  koa: (ctx) => ({
1157
1162
  update: ctx.request.body,
@@ -1159,6 +1164,10 @@ const frameworks = {
1159
1164
  unauthorized: () => {
1160
1165
  ctx.status === 401;
1161
1166
  ctx.body = WRONG_TOKEN_ERROR;
1167
+ },
1168
+ response: () => {
1169
+ ctx.status = 200;
1170
+ ctx.body = RESPONSE_OK;
1162
1171
  }
1163
1172
  }),
1164
1173
  http: (req, res) => ({
@@ -1170,31 +1179,59 @@ const frameworks = {
1170
1179
  req.on("end", () => resolve(JSON.parse(body)));
1171
1180
  }),
1172
1181
  header: req.headers[SECRET_TOKEN_HEADER.toLowerCase()],
1173
- unauthorized: () => res.writeHead(401).end(WRONG_TOKEN_ERROR)
1182
+ unauthorized: () => res.writeHead(401).end(WRONG_TOKEN_ERROR),
1183
+ response: () => res.writeHead(200).end(RESPONSE_OK)
1174
1184
  }),
1175
1185
  "std/http": (req) => ({
1176
1186
  update: req.json(),
1177
1187
  header: req.headers.get(SECRET_TOKEN_HEADER),
1178
- response: () => responseOK,
1179
- unauthorized: () => responseUnauthorized
1188
+ response: responseOK,
1189
+ unauthorized: responseUnauthorized
1180
1190
  }),
1181
1191
  "Bun.serve": (req) => ({
1182
1192
  update: req.json(),
1183
1193
  header: req.headers.get(SECRET_TOKEN_HEADER),
1184
- response: () => responseOK,
1185
- unauthorized: () => responseUnauthorized
1194
+ response: responseOK,
1195
+ unauthorized: responseUnauthorized
1196
+ }),
1197
+ cloudflare: (req) => ({
1198
+ update: req.json(),
1199
+ header: req.headers.get(SECRET_TOKEN_HEADER),
1200
+ response: responseOK,
1201
+ unauthorized: responseUnauthorized
1202
+ }),
1203
+ Request: (req) => ({
1204
+ update: req.json(),
1205
+ header: req.headers.get(SECRET_TOKEN_HEADER),
1206
+ response: responseOK,
1207
+ unauthorized: responseUnauthorized
1186
1208
  })
1187
1209
  };
1188
1210
 
1189
- function webhookHandler(bot, framework, secretToken) {
1211
+ function webhookHandler(bot, framework, secretTokenOrOptions) {
1190
1212
  const frameworkAdapter = frameworks[framework];
1213
+ const secretToken = typeof secretTokenOrOptions === "string" ? secretTokenOrOptions : secretTokenOrOptions?.secretToken;
1214
+ const shouldWaitOptions = typeof secretTokenOrOptions === "string" ? false : secretTokenOrOptions?.shouldWait;
1215
+ const isShouldWait = shouldWaitOptions && (typeof shouldWaitOptions === "object" || typeof shouldWaitOptions === "boolean");
1191
1216
  return async (...args) => {
1192
1217
  const { update, response, header, unauthorized } = frameworkAdapter(
1193
1218
  ...args
1194
1219
  );
1195
1220
  if (secretToken && header !== secretToken) return unauthorized();
1196
- bot.updates.queue.add(await update);
1197
- if (response) return response();
1221
+ if (!isShouldWait) {
1222
+ bot.updates.queue.add(await update);
1223
+ if (response) return response();
1224
+ } else {
1225
+ const timeoutOptions = typeof shouldWaitOptions === "object" ? shouldWaitOptions : void 0;
1226
+ const timeout = timeoutOptions?.timeout ?? 3e4;
1227
+ const onTimeout = timeoutOptions?.onTimeout ?? "throw";
1228
+ await timeoutWebhook(
1229
+ bot.updates.handleUpdate(await update, "wait"),
1230
+ timeout,
1231
+ onTimeout
1232
+ );
1233
+ if (response) return response();
1234
+ }
1198
1235
  };
1199
1236
  }
1200
1237
 
@@ -40,9 +40,22 @@ function simplifyObject(obj) {
40
40
  return result;
41
41
  }
42
42
  const IS_BUN = typeof Bun !== "undefined";
43
- const $debugger = debug("gramio");
44
- const debug$api = $debugger.extend("api");
45
- const debug$updates = $debugger.extend("updates");
43
+ debug("gramio:api");
44
+ const debug$updates = debug("gramio:updates");
45
+ function timeoutWebhook(task, timeout, mode) {
46
+ return new Promise((resolve, reject) => {
47
+ const timeoutTask = setTimeout(() => {
48
+ if (mode === "throw") {
49
+ reject(
50
+ new Error(`Webhook handler execution timed out after ${timeout}ms`)
51
+ );
52
+ } else {
53
+ resolve(void 0);
54
+ }
55
+ }, timeout);
56
+ task.then(resolve).catch(reject).finally(() => clearTimeout(timeoutTask));
57
+ });
58
+ }
46
59
 
47
60
  async function suppressError(fn) {
48
61
  try {
@@ -67,4 +80,4 @@ async function withRetries(resultPromise) {
67
80
  return result;
68
81
  }
69
82
 
70
- export { ErrorKind as E, IS_BUN as I, TelegramError as T, debug$api as a, simplifyObject as b, debug$updates as d, sleep as s, withRetries as w };
83
+ export { ErrorKind as E, IS_BUN as I, TelegramError as T, simplifyObject as a, debug$updates as d, sleep as s, timeoutWebhook as t, withRetries as w };
@@ -42,9 +42,22 @@ function simplifyObject(obj) {
42
42
  return result;
43
43
  }
44
44
  const IS_BUN = typeof Bun !== "undefined";
45
- const $debugger = debug("gramio");
46
- const debug$api = $debugger.extend("api");
47
- const debug$updates = $debugger.extend("updates");
45
+ debug("gramio:api");
46
+ const debug$updates = debug("gramio:updates");
47
+ function timeoutWebhook(task, timeout, mode) {
48
+ return new Promise((resolve, reject) => {
49
+ const timeoutTask = setTimeout(() => {
50
+ if (mode === "throw") {
51
+ reject(
52
+ new Error(`Webhook handler execution timed out after ${timeout}ms`)
53
+ );
54
+ } else {
55
+ resolve(void 0);
56
+ }
57
+ }, timeout);
58
+ task.then(resolve).catch(reject).finally(() => clearTimeout(timeoutTask));
59
+ });
60
+ }
48
61
 
49
62
  async function suppressError(fn) {
50
63
  try {
@@ -72,8 +85,8 @@ async function withRetries(resultPromise) {
72
85
  exports.ErrorKind = ErrorKind;
73
86
  exports.IS_BUN = IS_BUN;
74
87
  exports.TelegramError = TelegramError;
75
- exports.debug$api = debug$api;
76
88
  exports.debug$updates = debug$updates;
77
89
  exports.simplifyObject = simplifyObject;
78
90
  exports.sleep = sleep;
91
+ exports.timeoutWebhook = timeoutWebhook;
79
92
  exports.withRetries = withRetries;
package/dist/utils.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('./utils-BIdmQNPz.cjs');
3
+ var utils = require('./utils-CYIya32k.cjs');
4
4
  require('debug');
5
5
 
6
6
 
package/dist/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- export { w as withRetries } from './utils-CV4fnsQV.js';
1
+ export { w as withRetries } from './utils-CJfJNxc_.js';
2
2
  import 'debug';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "module",
4
- "version": "0.4.3",
4
+ "version": "0.4.5",
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",
@@ -56,20 +56,20 @@
56
56
  "license": "MIT",
57
57
  "devDependencies": {
58
58
  "@biomejs/biome": "1.9.4",
59
- "@types/bun": "^1.2.10",
59
+ "@types/bun": "^1.2.14",
60
60
  "@types/debug": "^4.1.12",
61
61
  "expect-type": "^1.2.1",
62
- "pkgroll": "^2.12.1",
62
+ "pkgroll": "^2.12.2",
63
63
  "typescript": "^5.8.3"
64
64
  },
65
65
  "dependencies": {
66
66
  "@gramio/callback-data": "^0.0.3",
67
67
  "@gramio/contexts": "^0.2.5",
68
68
  "@gramio/files": "^0.3.0",
69
- "@gramio/format": "^0.2.0",
69
+ "@gramio/format": "^0.2.1",
70
70
  "@gramio/keyboards": "^1.2.1",
71
71
  "@gramio/types": "^9.0.2",
72
- "debug": "^4.4.0",
72
+ "debug": "^4.4.1",
73
73
  "middleware-io": "^2.8.1"
74
74
  },
75
75
  "files": ["dist"]