fix: handle object-format capabilities in normalizeCapabilities

When capabilities is configured as an object (e.g., { inlineButtons: "dm" })
instead of a string array, normalizeCapabilities() would crash with
"capabilities.map is not a function".

This can occur when using the new Telegram inline buttons scoping feature:
  channels.telegram.capabilities.inlineButtons = "dm"

The fix adds an Array.isArray() guard to return undefined for non-array
capabilities, allowing channel-specific handlers (like
resolveTelegramInlineButtonsScope) to process the object format separately.

Fixes crash when using object-format TelegramCapabilitiesConfig.
This commit is contained in:
danielz1z
2026-01-17 05:11:57 +00:00
parent 572e04d5fb
commit f42b12646d
2 changed files with 23 additions and 0 deletions

View File

@@ -105,6 +105,26 @@ describe("resolveChannelCapabilities", () => {
}),
).toEqual(["polls"]);
});
it("handles object-format capabilities gracefully (e.g., { inlineButtons: 'dm' })", () => {
const cfg = {
channels: {
telegram: {
// Object format - used for granular control like inlineButtons scope.
// Channel-specific handlers (resolveTelegramInlineButtonsScope) process these.
capabilities: { inlineButtons: "dm" },
},
},
};
// Should return undefined (not crash), allowing channel-specific handlers to process it.
expect(
resolveChannelCapabilities({
cfg: cfg as ClawdbotConfig,
channel: "telegram",
}),
).toBeUndefined();
});
});
const createRegistry = (channels: PluginRegistry["channels"]): PluginRegistry => ({