refactor!: rename chat providers to channels

This commit is contained in:
Peter Steinberger
2026-01-13 06:16:43 +00:00
parent 0cd632ba84
commit 90342a4f3a
393 changed files with 8004 additions and 6737 deletions

View File

@@ -5,9 +5,11 @@ import { resolveOutboundTarget } from "./targets.js";
describe("resolveOutboundTarget", () => {
it("falls back to whatsapp allowFrom via config", () => {
const cfg: ClawdbotConfig = { whatsapp: { allowFrom: ["+1555"] } };
const cfg: ClawdbotConfig = {
channels: { whatsapp: { allowFrom: ["+1555"] } },
};
const res = resolveOutboundTarget({
provider: "whatsapp",
channel: "whatsapp",
to: "",
cfg,
mode: "explicit",
@@ -18,31 +20,31 @@ describe("resolveOutboundTarget", () => {
it.each([
{
name: "normalizes whatsapp target when provided",
input: { provider: "whatsapp" as const, to: " (555) 123-4567 " },
input: { channel: "whatsapp" as const, to: " (555) 123-4567 " },
expected: { ok: true as const, to: "+5551234567" },
},
{
name: "keeps whatsapp group targets",
input: { provider: "whatsapp" as const, to: "120363401234567890@g.us" },
input: { channel: "whatsapp" as const, to: "120363401234567890@g.us" },
expected: { ok: true as const, to: "120363401234567890@g.us" },
},
{
name: "normalizes prefixed/uppercase whatsapp group targets",
input: {
provider: "whatsapp" as const,
channel: "whatsapp" as const,
to: " WhatsApp:Group:120363401234567890@G.US ",
},
expected: { ok: true as const, to: "120363401234567890@g.us" },
},
{
name: "falls back to whatsapp allowFrom",
input: { provider: "whatsapp" as const, to: "", allowFrom: ["+1555"] },
input: { channel: "whatsapp" as const, to: "", allowFrom: ["+1555"] },
expected: { ok: true as const, to: "+1555" },
},
{
name: "normalizes whatsapp allowFrom fallback targets",
input: {
provider: "whatsapp" as const,
channel: "whatsapp" as const,
to: "",
allowFrom: ["whatsapp:(555) 123-4567"],
},
@@ -50,17 +52,17 @@ describe("resolveOutboundTarget", () => {
},
{
name: "rejects invalid whatsapp target",
input: { provider: "whatsapp" as const, to: "wat" },
input: { channel: "whatsapp" as const, to: "wat" },
expectedErrorIncludes: "WhatsApp",
},
{
name: "rejects whatsapp without to when allowFrom missing",
input: { provider: "whatsapp" as const, to: " " },
input: { channel: "whatsapp" as const, to: " " },
expectedErrorIncludes: "WhatsApp",
},
{
name: "rejects whatsapp allowFrom fallback when invalid",
input: { provider: "whatsapp" as const, to: "", allowFrom: ["wat"] },
input: { channel: "whatsapp" as const, to: "", allowFrom: ["wat"] },
expectedErrorIncludes: "WhatsApp",
},
])("$name", ({ input, expected, expectedErrorIncludes }) => {
@@ -76,7 +78,7 @@ describe("resolveOutboundTarget", () => {
});
it("rejects telegram with missing target", () => {
const res = resolveOutboundTarget({ provider: "telegram", to: " " });
const res = resolveOutboundTarget({ channel: "telegram", to: " " });
expect(res.ok).toBe(false);
if (!res.ok) {
expect(res.error.message).toContain("Telegram");
@@ -84,7 +86,7 @@ describe("resolveOutboundTarget", () => {
});
it("rejects webchat delivery", () => {
const res = resolveOutboundTarget({ provider: "webchat", to: "x" });
const res = resolveOutboundTarget({ channel: "webchat", to: "x" });
expect(res.ok).toBe(false);
if (!res.ok) {
expect(res.error.message).toContain("WebChat");