fix(telegram): wire webhookPort through config and startup

Co-authored-by: xrf9268-hue <244283935+xrf9268-hue@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-02-22 17:49:59 +01:00
parent 5069250faf
commit d0e6763263
6 changed files with 78 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ Docs: https://docs.openclaw.ai
- Telegram/Webhook: keep webhook monitors alive until gateway abort signals fire, preventing false channel exits and immediate webhook auto-restart loops.
- Telegram/Polling: retry recoverable setup-time network failures in monitor startup and await runner teardown before retry to avoid overlapping polling sessions.
- Telegram/Polling: clear Telegram webhooks (`deleteWebhook`) before starting long-poll `getUpdates`, including retry handling for transient cleanup failures.
- Telegram/Webhook: add `channels.telegram.webhookPort` config support and pass it through plugin startup wiring to the monitor listener.
- Signal/RPC: guard malformed Signal RPC JSON responses with a clear status-scoped error and add regression coverage for invalid JSON responses. (#22995) Thanks @adhitShet.
- Gateway/Subagents: guard gateway and subagent session-key/message trim paths against undefined inputs to prevent early `Cannot read properties of undefined (reading 'trim')` crashes during subagent spawn and wait flows.
- Agents/Workspace: guard `resolveUserPath` against undefined/null input to prevent `Cannot read properties of undefined (reading 'trim')` crashes when workspace paths are missing in embedded runner flows.

View File

@@ -122,4 +122,44 @@ describe("telegramPlugin duplicate token guard", () => {
expect(probeTelegram).not.toHaveBeenCalled();
expect(monitorTelegramProvider).not.toHaveBeenCalled();
});
it("passes webhookPort through to monitor startup options", async () => {
const monitorTelegramProvider = vi.fn(async () => undefined);
const probeTelegram = vi.fn(async () => ({ ok: true, bot: { username: "opsbot" } }));
const runtime = {
channel: {
telegram: {
monitorTelegramProvider,
probeTelegram,
},
},
logging: {
shouldLogVerbose: () => false,
},
} as unknown as PluginRuntime;
setTelegramRuntime(runtime);
const cfg = createCfg();
cfg.channels!.telegram!.accounts!.ops = {
...cfg.channels!.telegram!.accounts!.ops,
webhookUrl: "https://example.test/telegram-webhook",
webhookSecret: "secret",
webhookPort: 9876,
};
await telegramPlugin.gateway!.startAccount!(
createStartAccountCtx({
cfg,
accountId: "ops",
runtime: createRuntimeEnv(),
}),
);
expect(monitorTelegramProvider).toHaveBeenCalledWith(
expect.objectContaining({
useWebhook: true,
webhookPort: 9876,
}),
);
});
});

View File

@@ -492,6 +492,7 @@ export const telegramPlugin: ChannelPlugin<ResolvedTelegramAccount, TelegramProb
webhookSecret: account.config.webhookSecret,
webhookPath: account.config.webhookPath,
webhookHost: account.config.webhookHost,
webhookPort: account.config.webhookPort,
});
},
logoutAccount: async ({ accountId, cfg }) => {

View File

@@ -0,0 +1,33 @@
import { describe, expect, it } from "vitest";
import { validateConfigObject } from "./config.js";
describe("Telegram webhookPort config", () => {
it("accepts a positive webhookPort", () => {
const res = validateConfigObject({
channels: {
telegram: {
webhookUrl: "https://example.com/telegram-webhook",
webhookSecret: "secret",
webhookPort: 8787,
},
},
});
expect(res.ok).toBe(true);
});
it("rejects non-positive webhookPort", () => {
const res = validateConfigObject({
channels: {
telegram: {
webhookUrl: "https://example.com/telegram-webhook",
webhookSecret: "secret",
webhookPort: 0,
},
},
});
expect(res.ok).toBe(false);
if (!res.ok) {
expect(res.issues.some((issue) => issue.path === "channels.telegram.webhookPort")).toBe(true);
}
});
});

View File

@@ -133,6 +133,8 @@ export type TelegramAccountConfig = {
webhookPath?: string;
/** Local webhook listener bind host (default: 127.0.0.1). */
webhookHost?: string;
/** Local webhook listener bind port (default: 8787). */
webhookPort?: number;
/** Per-action tool gating (default: true for all). */
actions?: TelegramActionConfig;
/**

View File

@@ -169,6 +169,7 @@ export const TelegramAccountSchemaBase = z
webhookSecret: z.string().optional().register(sensitive),
webhookPath: z.string().optional(),
webhookHost: z.string().optional(),
webhookPort: z.number().int().positive().optional(),
actions: z
.object({
reactions: z.boolean().optional(),