grammy 1.30.0 β 1.30.1
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/README.md +7 -2
- package/out/bot.d.ts +21 -3
- package/out/bot.js +33 -11
- package/out/convenience/inline_query.d.ts +1 -1
- package/out/convenience/webhook.js +8 -0
- package/out/web.mjs +23 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
<!-- deno-fmt-ignore-start -->
|
|
12
12
|
|
|
13
|
-
[](https://core.telegram.org/bots/api)
|
|
14
14
|
[](https://deno.land/x/grammy)
|
|
15
15
|
[](https://www.npmjs.org/package/grammy)
|
|
16
16
|
[](#contributors-)
|
|
@@ -142,7 +142,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
142
142
|
<table>
|
|
143
143
|
<tbody>
|
|
144
144
|
<tr>
|
|
145
|
-
<td align="center" valign="top" width="11.11%"><a href="https://github.com/KnorpelSenf"><img src="https://avatars.githubusercontent.com/u/12952387?v=4?s=100" width="100px;" alt="KnorpelSenf"/><br /><sub><b>KnorpelSenf</b></sub></a><br /><a href="#ideas-KnorpelSenf" title="Ideas, Planning, & Feedback">π€</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Code">π»</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Documentation">π</a> <a href="#design-KnorpelSenf" title="Design">π¨</a> <a href="#example-KnorpelSenf" title="Examples">π‘</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Tests">β οΈ</a> <a href="#plugin-KnorpelSenf" title="Plugin/utility libraries">π</a> <a href="#platform-KnorpelSenf" title="Packaging/porting to new platform">π¦</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AKnorpelSenf" title="Reviewed Pull Requests">π</a> <a href="#mentoring-KnorpelSenf" title="Mentoring">π§βπ«</a> <a href="#projectManagement-KnorpelSenf" title="Project Management">π</a> <a href="#infra-KnorpelSenf" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#audio-KnorpelSenf" title="Audio">π</a> <a href="#a11y-KnorpelSenf" title="Accessibility">οΈοΈοΈοΈβΏοΈ</a></td>
|
|
145
|
+
<td align="center" valign="top" width="11.11%"><a href="https://github.com/KnorpelSenf"><img src="https://avatars.githubusercontent.com/u/12952387?v=4?s=100" width="100px;" alt="KnorpelSenf"/><br /><sub><b>KnorpelSenf</b></sub></a><br /><a href="#ideas-KnorpelSenf" title="Ideas, Planning, & Feedback">π€</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Code">π»</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Documentation">π</a> <a href="#design-KnorpelSenf" title="Design">π¨</a> <a href="#example-KnorpelSenf" title="Examples">π‘</a> <a href="https://github.com/grammyjs/grammY/commits?author=KnorpelSenf" title="Tests">β οΈ</a> <a href="#plugin-KnorpelSenf" title="Plugin/utility libraries">π</a> <a href="#platform-KnorpelSenf" title="Packaging/porting to new platform">π¦</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AKnorpelSenf" title="Reviewed Pull Requests">π</a> <a href="#mentoring-KnorpelSenf" title="Mentoring">π§βπ«</a> <a href="#projectManagement-KnorpelSenf" title="Project Management">π</a> <a href="#infra-KnorpelSenf" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#audio-KnorpelSenf" title="Audio">π</a> <a href="#a11y-KnorpelSenf" title="Accessibility">οΈοΈοΈοΈβΏοΈ</a> <a href="#talk-KnorpelSenf" title="Talks">π’</a></td>
|
|
146
146
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/HeeroML"><img src="https://avatars.githubusercontent.com/u/42873000?v=4?s=100" width="100px;" alt="Heero"/><br /><sub><b>Heero</b></sub></a><br /><a href="#plugin-HeeroML" title="Plugin/utility libraries">π</a> <a href="#userTesting-HeeroML" title="User Testing">π</a> <a href="#example-HeeroML" title="Examples">π‘</a> <a href="https://github.com/grammyjs/grammY/commits?author=HeeroML" title="Documentation">π</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AHeeroML" title="Reviewed Pull Requests">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=HeeroML" title="Code">π»</a> <a href="#ideas-HeeroML" title="Ideas, Planning, & Feedback">π€</a></td>
|
|
147
147
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/wojpawlik"><img src="https://avatars.githubusercontent.com/u/23058303?v=4?s=100" width="100px;" alt="Wojciech Pawlik"/><br /><sub><b>Wojciech Pawlik</b></sub></a><br /><a href="#ideas-wojpawlik" title="Ideas, Planning, & Feedback">π€</a> <a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Awojpawlik" title="Reviewed Pull Requests">π</a> <a href="#infra-wojpawlik" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#platform-wojpawlik" title="Packaging/porting to new platform">π¦</a> <a href="#tool-wojpawlik" title="Tools">π§</a></td>
|
|
148
148
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/MegaITA"><img src="https://avatars.githubusercontent.com/u/32493080?v=4?s=100" width="100px;" alt="Alessandro Bertozzi"/><br /><sub><b>Alessandro Bertozzi</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=MegaITA" title="Documentation">π</a></td>
|
|
@@ -309,6 +309,11 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
309
309
|
<tr>
|
|
310
310
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/rayz1065"><img src="https://avatars.githubusercontent.com/u/37779815?v=4?s=100" width="100px;" alt="rayz"/><br /><sub><b>rayz</b></sub></a><br /><a href="#question-rayz1065" title="Answering Questions">π¬</a> <a href="#ideas-rayz1065" title="Ideas, Planning, & Feedback">π€</a> <a href="https://github.com/grammyjs/grammY/commits?author=rayz1065" title="Code">π»</a></td>
|
|
311
311
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/z44d"><img src="https://avatars.githubusercontent.com/u/162994967?v=4?s=100" width="100px;" alt="Zaid"/><br /><sub><b>Zaid</b></sub></a><br /><a href="#tool-z44d" title="Tools">π§</a></td>
|
|
312
|
+
<td align="center" valign="top" width="11.11%"><a href="https://github.com/matmilbury"><img src="https://avatars.githubusercontent.com/u/73319876?v=4?s=100" width="100px;" alt="Mat Milbury"/><br /><sub><b>Mat Milbury</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/issues?q=author%3Amatmilbury" title="Bug reports">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=matmilbury" title="Code">π»</a></td>
|
|
313
|
+
<td align="center" valign="top" width="11.11%"><a href="https://lao.sb/"><img src="https://avatars.githubusercontent.com/u/2545261?v=4?s=100" width="100px;" alt="Shibo Lyu"/><br /><sub><b>Shibo Lyu</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/commits?author=laosb" title="Code">π»</a></td>
|
|
314
|
+
<td align="center" valign="top" width="11.11%"><a href="https://nometa.xyz/"><img src="https://avatars.githubusercontent.com/u/68379695?v=4?s=100" width="100px;" alt="Mased"/><br /><sub><b>Mased</b></sub></a><br /><a href="#translation-MasedMSD" title="Translation">π</a> <a href="https://github.com/grammyjs/grammY/commits?author=MasedMSD" title="Documentation">π</a></td>
|
|
315
|
+
<td align="center" valign="top" width="11.11%"><a href="https://github.com/ExposedCat"><img src="https://avatars.githubusercontent.com/u/44642024?v=4?s=100" width="100px;" alt="Artem Prokop"/><br /><sub><b>Artem Prokop</b></sub></a><br /><a href="#userTesting-ExposedCat" title="User Testing">π</a></td>
|
|
316
|
+
<td align="center" valign="top" width="11.11%"><a href="https://chinoman10.com/"><img src="https://avatars.githubusercontent.com/u/8300763?v=4?s=100" width="100px;" alt="SΓ©rgio Rebelo"/><br /><sub><b>SΓ©rgio Rebelo</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3AChinoman10" title="Reviewed Pull Requests">π</a></td>
|
|
312
317
|
</tr>
|
|
313
318
|
</tbody>
|
|
314
319
|
</table>
|
package/out/bot.d.ts
CHANGED
|
@@ -21,11 +21,11 @@ export interface PollingOptions {
|
|
|
21
21
|
timeout?: number;
|
|
22
22
|
/**
|
|
23
23
|
* A list of the update types you want your bot to receive. For example,
|
|
24
|
-
* specify [
|
|
24
|
+
* specify ["message", "edited_channel_post", "callback_query"] to only
|
|
25
25
|
* receive updates of these types. See Update for a complete list of
|
|
26
26
|
* available update types. Specify an empty list to receive all update types
|
|
27
|
-
* except chat_member
|
|
28
|
-
* be used.
|
|
27
|
+
* except chat_member, message_reaction, and message_reaction_count
|
|
28
|
+
* (default). If not specified, the previous setting will be used.
|
|
29
29
|
*
|
|
30
30
|
* Please note that this parameter doesn't affect updates created before the
|
|
31
31
|
* call to the getUpdates, so unwanted updates may be received for a short
|
|
@@ -43,6 +43,9 @@ export interface PollingOptions {
|
|
|
43
43
|
* fetched. The bot information `bot.botInfo` will be available when the
|
|
44
44
|
* function is run. For convenience, the callback function receives the
|
|
45
45
|
* value of `bot.botInfo` as an argument.
|
|
46
|
+
*
|
|
47
|
+
* When this function is invoked, the bot already signals that it is
|
|
48
|
+
* running. In other words, `bot.isRunning()` already returns true.
|
|
46
49
|
*/
|
|
47
50
|
onStart?: (botInfo: UserFromGetMe) => void | Promise<void>;
|
|
48
51
|
}
|
|
@@ -260,6 +263,21 @@ export declare class Bot<C extends Context = Context, A extends Api = Api> exten
|
|
|
260
263
|
* > for the promise returned by `bot.start()` to resolve.
|
|
261
264
|
*/
|
|
262
265
|
stop(): Promise<void>;
|
|
266
|
+
/**
|
|
267
|
+
* Returns true if the bot is currently running via built-in long polling,
|
|
268
|
+
* and false otherwise.
|
|
269
|
+
*
|
|
270
|
+
* If this method returns true, it means that `bot.start()` has been called,
|
|
271
|
+
* and that the bot has neither crashed nor was it stopped via a call to
|
|
272
|
+
* `bot.stop()`. This also means that you cannot use this method to check if
|
|
273
|
+
* a webhook server is running, or if grammY runner was started.
|
|
274
|
+
*
|
|
275
|
+
* Note that this method will already begin to return true even before the
|
|
276
|
+
* call to `bot.start()` has completed its initialization phase (and hence
|
|
277
|
+
* before `bot.isInited()` returns true). By extension, this method
|
|
278
|
+
* returns true before `onStart` callback of `bot.start()` is invoked.
|
|
279
|
+
*/
|
|
280
|
+
isRunning(): boolean;
|
|
263
281
|
/**
|
|
264
282
|
* Sets the bots error handler that is used during long polling.
|
|
265
283
|
*
|
package/out/bot.js
CHANGED
|
@@ -346,6 +346,23 @@ a known bot info object.");
|
|
|
346
346
|
debug("Bot is not running!");
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Returns true if the bot is currently running via built-in long polling,
|
|
351
|
+
* and false otherwise.
|
|
352
|
+
*
|
|
353
|
+
* If this method returns true, it means that `bot.start()` has been called,
|
|
354
|
+
* and that the bot has neither crashed nor was it stopped via a call to
|
|
355
|
+
* `bot.stop()`. This also means that you cannot use this method to check if
|
|
356
|
+
* a webhook server is running, or if grammY runner was started.
|
|
357
|
+
*
|
|
358
|
+
* Note that this method will already begin to return true even before the
|
|
359
|
+
* call to `bot.start()` has completed its initialization phase (and hence
|
|
360
|
+
* before `bot.isInited()` returns true). By extension, this method
|
|
361
|
+
* returns true before `onStart` callback of `bot.start()` is invoked.
|
|
362
|
+
*/
|
|
363
|
+
isRunning() {
|
|
364
|
+
return this.pollingRunning;
|
|
365
|
+
}
|
|
349
366
|
/**
|
|
350
367
|
* Sets the bots error handler that is used during long polling.
|
|
351
368
|
*
|
|
@@ -370,17 +387,22 @@ a known bot info object.");
|
|
|
370
387
|
const limit = options === null || options === void 0 ? void 0 : options.limit;
|
|
371
388
|
const timeout = (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 30; // seconds
|
|
372
389
|
let allowed_updates = (_b = options === null || options === void 0 ? void 0 : options.allowed_updates) !== null && _b !== void 0 ? _b : []; // reset to default if unspecified
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
390
|
+
try {
|
|
391
|
+
while (this.pollingRunning) {
|
|
392
|
+
// fetch updates
|
|
393
|
+
const updates = await this.fetchUpdates({ limit, timeout, allowed_updates });
|
|
394
|
+
// check if polling stopped
|
|
395
|
+
if (updates === undefined)
|
|
396
|
+
break;
|
|
397
|
+
// handle updates
|
|
398
|
+
await this.handleUpdates(updates);
|
|
399
|
+
// Telegram uses the last setting if `allowed_updates` is omitted so
|
|
400
|
+
// we can save some traffic by only sending it in the first request
|
|
401
|
+
allowed_updates = undefined;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
finally {
|
|
405
|
+
this.pollingRunning = false;
|
|
384
406
|
}
|
|
385
407
|
}
|
|
386
408
|
/**
|
|
@@ -163,7 +163,7 @@ export declare const InlineQueryResultBuilder: {
|
|
|
163
163
|
* @param options Remaining options
|
|
164
164
|
*/
|
|
165
165
|
game(id: string, game_short_name: string, options?: InlineQueryResultOptions<InlineQueryResultGame, "game_short_name">): {
|
|
166
|
-
reply_markup?: import("@grammyjs/types/markup.js").InlineKeyboardMarkup;
|
|
166
|
+
reply_markup?: import("@grammyjs/types/markup.js").InlineKeyboardMarkup | undefined;
|
|
167
167
|
type: string;
|
|
168
168
|
id: string;
|
|
169
169
|
game_short_name: string;
|
|
@@ -12,6 +12,14 @@ const callbackAdapter = (update, callback, header, unauthorized = () => callback
|
|
|
12
12
|
});
|
|
13
13
|
const adapters = { ...frameworks_js_1.adapters, callback: callbackAdapter };
|
|
14
14
|
function webhookCallback(bot, adapter = platform_node_js_1.defaultAdapter, onTimeout, timeoutMilliseconds, secretToken) {
|
|
15
|
+
if (bot.isRunning()) {
|
|
16
|
+
throw new Error("Bot is already running via long polling, the webhook setup won't receive any updates!");
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
bot.start = () => {
|
|
20
|
+
throw new Error("You already started the bot via webhooks, calling `bot.start()` starts the bot with long polling and this will prevent your webhook setup from receiving any updates!");
|
|
21
|
+
};
|
|
22
|
+
}
|
|
15
23
|
const { onTimeout: timeout = "throw", timeoutMilliseconds: ms = 10000, secretToken: token, } = typeof onTimeout === "object"
|
|
16
24
|
? onTimeout
|
|
17
25
|
: { onTimeout, timeoutMilliseconds, secretToken };
|
package/out/web.mjs
CHANGED
|
@@ -3465,6 +3465,9 @@ a known bot info object.");
|
|
|
3465
3465
|
debug2("Bot is not running!");
|
|
3466
3466
|
}
|
|
3467
3467
|
}
|
|
3468
|
+
isRunning() {
|
|
3469
|
+
return this.pollingRunning;
|
|
3470
|
+
}
|
|
3468
3471
|
catch(errorHandler) {
|
|
3469
3472
|
this.errorHandler = errorHandler;
|
|
3470
3473
|
}
|
|
@@ -3472,15 +3475,19 @@ a known bot info object.");
|
|
|
3472
3475
|
const limit = options?.limit;
|
|
3473
3476
|
const timeout = options?.timeout ?? 30;
|
|
3474
3477
|
let allowed_updates = options?.allowed_updates ?? [];
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3478
|
+
try {
|
|
3479
|
+
while(this.pollingRunning){
|
|
3480
|
+
const updates = await this.fetchUpdates({
|
|
3481
|
+
limit,
|
|
3482
|
+
timeout,
|
|
3483
|
+
allowed_updates
|
|
3484
|
+
});
|
|
3485
|
+
if (updates === undefined) break;
|
|
3486
|
+
await this.handleUpdates(updates);
|
|
3487
|
+
allowed_updates = undefined;
|
|
3488
|
+
}
|
|
3489
|
+
} finally{
|
|
3490
|
+
this.pollingRunning = false;
|
|
3484
3491
|
}
|
|
3485
3492
|
}
|
|
3486
3493
|
async fetchUpdates({ limit, timeout, allowed_updates }) {
|
|
@@ -4899,6 +4906,13 @@ const adapters1 = {
|
|
|
4899
4906
|
callback: callbackAdapter
|
|
4900
4907
|
};
|
|
4901
4908
|
function webhookCallback(bot, adapter = defaultAdapter, onTimeout, timeoutMilliseconds, secretToken) {
|
|
4909
|
+
if (bot.isRunning()) {
|
|
4910
|
+
throw new Error("Bot is already running via long polling, the webhook setup won't receive any updates!");
|
|
4911
|
+
} else {
|
|
4912
|
+
bot.start = ()=>{
|
|
4913
|
+
throw new Error("You already started the bot via webhooks, calling `bot.start()` starts the bot with long polling and this will prevent your webhook setup from receiving any updates!");
|
|
4914
|
+
};
|
|
4915
|
+
}
|
|
4902
4916
|
const { onTimeout: timeout = "throw", timeoutMilliseconds: ms = 10_000, secretToken: token } = typeof onTimeout === "object" ? onTimeout : {
|
|
4903
4917
|
onTimeout,
|
|
4904
4918
|
timeoutMilliseconds,
|