Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ Page cleanup can be controlled with global `clearChatOnPageOpen`, component `cle

The returned TBF application now has an idempotent `stop(signal?)` method. Automatic `SIGINT` and `SIGTERM` handling is opt-in through `gracefulShutdown.handleSignals` and defaults to `false`.

`stop()` also tolerates Telegraf's `Bot is not running!` state, allowing storage-only CLI, seed, and migration processes to shut down without an `AggregateError`. Other shutdown failures are still reported.

## Publishing a release

Run `npm run release:dry-run` and bump `package.json` before merging a release into `master`. A push to `master` triggers `.github/workflows/publish.yml`, runs the complete prepublish check, publishes the missing version through npm Trusted Publishing, and creates a GitHub Release tagged `v<version>`. Existing npm versions and releases are not duplicated.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,14 @@ The priority is transition option, page option, global config, and finally the c

`await openPage()` waits until the selected page action completes.

The page and plugin loader accepts callable CommonJS exports from `.js`, `.cjs`, `.ts`, and `.cts` entries, including directory entry points. TypeScript declarations, source maps, JSON, documentation, and other build assets are ignored, so applications do not need to disable `.d.ts` or source-map output inside their compiled page directories.

### Graceful shutdown

TBF returns an idempotent `stop()` method that stops Telegraf, the message cleanup timer and HTTP server, then closes storage:

Stopping is safe when Telegraf polling is already inactive. TBF still closes the HTTP server and storage client, while unexpected Telegraf shutdown errors continue to be reported.

```ts
const app = await TBF({ telegram: { token } });

Expand Down
5 changes: 5 additions & 0 deletions lib/helpers/stop_bot.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type StoppableBot = {
stop(signal?: string): void;
};
declare function stopBot(bot: StoppableBot, signal?: string): void;
export { stopBot };
14 changes: 14 additions & 0 deletions lib/helpers/stop_bot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/helpers/stop_bot.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 49 additions & 3 deletions lib/paginator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/paginator.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@powerdot/telegram_bot_framework",
"version": "2.0.1",
"version": "2.0.2",
"description": "A component-oriented Telegram bot framework built on Telegraf",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
14 changes: 14 additions & 0 deletions src/helpers/stop_bot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type StoppableBot = {
stop(signal?: string): void;
};

function stopBot(bot: StoppableBot, signal?: string): void {
try {
bot.stop(signal);
} catch (error) {
if (error instanceof Error && error.message === "Bot is not running!") return;
throw error;
}
}

export { stopBot };
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Middleware_Router from "./bot_middlewares/router";

import AutoRemoveMessages from "./auto_remove_messages";
import { resolveConfig } from "./config";
import { stopBot } from "./helpers/stop_bot";

let Create = async ({ webServer, telegram, storage, mongo, config }: TBFArgs): Promise<TBFPromiseReturn> => {
const resolvedConfig = resolveConfig(config);
Expand Down Expand Up @@ -52,7 +53,7 @@ let Create = async ({ webServer, telegram, storage, mongo, config }: TBFArgs): P
process.removeListener("SIGTERM", handleSignal);
if (autoRemoveTimer) clearInterval(autoRemoveTimer);
try {
bot.stop(signal);
stopBot(bot, signal);
} catch (error) {
errors.push(error);
}
Expand Down
Loading
Loading