Merge pull request #991 from longmaba/fix/zalo-pairing-and-webhook

fix(zalo): fix pairing channel detection and webhook payload format
This commit is contained in:
Peter Steinberger
2026-01-16 04:54:08 +00:00
committed by GitHub
7 changed files with 46 additions and 23 deletions

View File

@@ -8,11 +8,10 @@ const pairingIdLabels: Record<string, string> = {
telegram: "telegramUserId",
discord: "discordUserId",
};
const requirePairingAdapter = vi.fn((channel: string) => ({
const getPairingAdapter = vi.fn((channel: string) => ({
idLabel: pairingIdLabels[channel] ?? "userId",
}));
const listPairingChannels = vi.fn(() => ["telegram", "discord"]);
const resolvePairingChannel = vi.fn((raw: string) => raw);
vi.mock("../pairing/pairing-store.js", () => ({
listChannelPairingRequests,
@@ -21,9 +20,8 @@ vi.mock("../pairing/pairing-store.js", () => ({
vi.mock("../channels/plugins/pairing.js", () => ({
listPairingChannels,
resolvePairingChannel,
notifyPairingApproved,
requirePairingAdapter,
getPairingAdapter,
}));
vi.mock("../config/config.js", () => ({

View File

@@ -2,7 +2,6 @@ import type { Command } from "commander";
import {
listPairingChannels,
notifyPairingApproved,
resolvePairingChannel,
} from "../channels/plugins/pairing.js";
import { loadConfig } from "../config/config.js";
import { resolvePairingIdLabel } from "../pairing/pairing-labels.js";
@@ -16,8 +15,14 @@ import { theme } from "../terminal/theme.js";
const CHANNELS: PairingChannel[] = listPairingChannels();
/** Parse channel, allowing extension channels not in core registry. */
function parseChannel(raw: unknown): PairingChannel {
return resolvePairingChannel(raw);
const value = String(raw ?? "").trim().toLowerCase();
if (!value) throw new Error("Channel required");
if (CHANNELS.includes(value as PairingChannel)) return value as PairingChannel;
// Allow extension channels: validate format but don't require registry
if (/^[a-z][a-z0-9_-]{0,63}$/.test(value)) return value as PairingChannel;
throw new Error(`Invalid channel: ${value}`);
}
async function notifyApproved(channel: PairingChannel, id: string) {