fix: restore Telegram webhook-mode health after restarts

Landed from contributor PR #39313 by @fellanH.

Co-authored-by: Felix Hellström <30758862+fellanH@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-03-08 02:27:05 +00:00
parent 1ef8d6a01b
commit 9d7d961db8
9 changed files with 63 additions and 4 deletions

View File

@@ -30,6 +30,7 @@ export type MonitorTelegramOpts = {
webhookHost?: string;
proxyFetch?: typeof fetch;
webhookUrl?: string;
webhookCertPath?: string;
};
export function createTelegramRunnerOptions(cfg: OpenClawConfig): RunOptions<unknown> {
@@ -199,6 +200,7 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
fetch: proxyFetch,
abortSignal: opts.abortSignal,
publicUrl: opts.webhookUrl,
webhookCertPath: opts.webhookCertPath,
});
await waitForAbortSignal(opts.abortSignal);
return;

View File

@@ -353,6 +353,27 @@ describe("startTelegramWebhook", () => {
);
});
it("registers webhook with certificate when webhookCertPath is provided", async () => {
setWebhookSpy.mockClear();
await withStartedWebhook(
{
secret: TELEGRAM_SECRET,
path: TELEGRAM_WEBHOOK_PATH,
webhookCertPath: "/path/to/cert.pem",
},
async () => {
expect(setWebhookSpy).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({
certificate: expect.objectContaining({
fileData: "/path/to/cert.pem",
}),
}),
);
},
);
});
it("invokes webhook handler on matching path", async () => {
handlerSpy.mockClear();
createTelegramBotSpy.mockClear();

View File

@@ -1,5 +1,5 @@
import { createServer } from "node:http";
import { webhookCallback } from "grammy";
import { InputFile, webhookCallback } from "grammy";
import type { OpenClawConfig } from "../config/config.js";
import { isDiagnosticsEnabled } from "../infra/diagnostic-events.js";
import { formatErrorMessage } from "../infra/errors.js";
@@ -87,6 +87,7 @@ export async function startTelegramWebhook(opts: {
abortSignal?: AbortSignal;
healthPath?: string;
publicUrl?: string;
webhookCertPath?: string;
}) {
const path = opts.path ?? "/telegram-webhook";
const healthPath = opts.healthPath ?? "/healthz";
@@ -241,6 +242,7 @@ export async function startTelegramWebhook(opts: {
bot.api.setWebhook(publicUrl, {
secret_token: secret,
allowed_updates: resolveTelegramAllowedUpdates(),
certificate: opts.webhookCertPath ? new InputFile(opts.webhookCertPath) : undefined,
}),
});
} catch (err) {