Merge pull request #1071 from danielz1z/fix/capabilities-object-format
fix: handle object-format capabilities in normalizeCapabilities
This commit is contained in:
@@ -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 => ({
|
||||
|
||||
@@ -4,6 +4,9 @@ import type { ClawdbotConfig } from "./config.js";
|
||||
|
||||
function normalizeCapabilities(capabilities: string[] | undefined): string[] | undefined {
|
||||
if (!capabilities) return undefined;
|
||||
// Handle object-format capabilities (e.g., { inlineButtons: "dm" }) gracefully.
|
||||
// Channel-specific handlers (like resolveTelegramInlineButtonsScope) process these separately.
|
||||
if (!Array.isArray(capabilities)) return undefined;
|
||||
const normalized = capabilities.map((entry) => entry.trim()).filter(Boolean);
|
||||
return normalized.length > 0 ? normalized : undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user