mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 14:35:00 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user