|
| 1 | +import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts"; |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import { resolveWhatsAppAckEmoji } from "./ack-emoji.js"; |
| 4 | + |
| 5 | +function createConfig( |
| 6 | + ackReaction?: NonNullable< |
| 7 | + NonNullable<NonNullable<OpenClawConfig["channels"]>["whatsapp"]>["ackReaction"] |
| 8 | + >, |
| 9 | +): OpenClawConfig { |
| 10 | + const cfg: OpenClawConfig = { |
| 11 | + agents: { |
| 12 | + list: [{ id: "agent", identity: { emoji: "🔥" } }], |
| 13 | + }, |
| 14 | + channels: { |
| 15 | + whatsapp: {}, |
| 16 | + }, |
| 17 | + } as OpenClawConfig; |
| 18 | + if (ackReaction !== undefined) { |
| 19 | + cfg.channels!.whatsapp!.ackReaction = ackReaction; |
| 20 | + } |
| 21 | + return cfg; |
| 22 | +} |
| 23 | + |
| 24 | +describe("resolveWhatsAppAckEmoji", () => { |
| 25 | + it("keeps missing ackReaction config disabled", () => { |
| 26 | + expect( |
| 27 | + resolveWhatsAppAckEmoji({ |
| 28 | + cfg: createConfig(), |
| 29 | + agentId: "agent", |
| 30 | + ackConfig: undefined, |
| 31 | + }), |
| 32 | + ).toBe(""); |
| 33 | + }); |
| 34 | + |
| 35 | + it("uses the configured WhatsApp emoji when present", () => { |
| 36 | + const cfg = createConfig({ emoji: " 👀 ", direct: true, group: "mentions" }); |
| 37 | + |
| 38 | + expect( |
| 39 | + resolveWhatsAppAckEmoji({ |
| 40 | + cfg, |
| 41 | + agentId: "agent", |
| 42 | + ackConfig: cfg.channels?.whatsapp?.ackReaction, |
| 43 | + }), |
| 44 | + ).toBe("👀"); |
| 45 | + }); |
| 46 | + |
| 47 | + it("keeps an explicit empty emoji disabled", () => { |
| 48 | + const cfg = createConfig({ emoji: " ", direct: true, group: "mentions" }); |
| 49 | + |
| 50 | + expect( |
| 51 | + resolveWhatsAppAckEmoji({ |
| 52 | + cfg, |
| 53 | + agentId: "agent", |
| 54 | + ackConfig: cfg.channels?.whatsapp?.ackReaction, |
| 55 | + }), |
| 56 | + ).toBe(""); |
| 57 | + }); |
| 58 | + |
| 59 | + it("falls back to the routed agent identity emoji when the ack object has no emoji", () => { |
| 60 | + const cfg = createConfig({ direct: true, group: "mentions" }); |
| 61 | + |
| 62 | + expect( |
| 63 | + resolveWhatsAppAckEmoji({ |
| 64 | + cfg, |
| 65 | + agentId: "agent", |
| 66 | + ackConfig: cfg.channels?.whatsapp?.ackReaction, |
| 67 | + }), |
| 68 | + ).toBe("🔥"); |
| 69 | + }); |
| 70 | + |
| 71 | + it("uses normalized agent ids for the identity fallback", () => { |
| 72 | + const cfg: OpenClawConfig = { |
| 73 | + agents: { |
| 74 | + list: [{ id: "Agent", identity: { emoji: "🔥" } }], |
| 75 | + }, |
| 76 | + channels: { |
| 77 | + whatsapp: { |
| 78 | + ackReaction: { direct: true, group: "mentions" }, |
| 79 | + }, |
| 80 | + }, |
| 81 | + } as OpenClawConfig; |
| 82 | + |
| 83 | + expect( |
| 84 | + resolveWhatsAppAckEmoji({ |
| 85 | + cfg, |
| 86 | + agentId: "agent", |
| 87 | + ackConfig: cfg.channels?.whatsapp?.ackReaction, |
| 88 | + }), |
| 89 | + ).toBe("🔥"); |
| 90 | + }); |
| 91 | + |
| 92 | + it("uses the default ack emoji when configured without an emoji or agent identity", () => { |
| 93 | + const cfg: OpenClawConfig = { |
| 94 | + channels: { |
| 95 | + whatsapp: { |
| 96 | + ackReaction: { direct: true, group: "mentions" }, |
| 97 | + }, |
| 98 | + }, |
| 99 | + } as OpenClawConfig; |
| 100 | + |
| 101 | + expect( |
| 102 | + resolveWhatsAppAckEmoji({ |
| 103 | + cfg, |
| 104 | + agentId: "agent", |
| 105 | + ackConfig: cfg.channels?.whatsapp?.ackReaction, |
| 106 | + }), |
| 107 | + ).toBe("👀"); |
| 108 | + }); |
| 109 | +}); |
0 commit comments