recruter/src/channels.ts
2026-11-14 21:46:24 +05:00

38 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export interface Contact { phone: string; channel: "whatsapp" | "telegram" }
/** Контракт канала связи (WhatsApp/Telegram). */
export interface ChannelAdapter {
send(to: Contact, text: string): Promise<void>;
}
export interface ScreenState {
vacancyTitle: string;
answers: string[];
}
export type ScreenStep =
| { kind: "ask"; question: string }
| { kind: "done"; suitable: boolean; readyForTraining: boolean };
/** Контракт ведущего скрининг (реальная реализация — LLM). */
export interface Screener {
next(state: ScreenState): Promise<ScreenStep>;
}
export class MockChannelAdapter implements ChannelAdapter {
readonly sent: { to: Contact; text: string }[] = [];
async send(to: Contact, text: string): Promise<void> {
this.sent.push({ to, text });
}
}
/** Мок скрининга: два фиксированных вопроса; годен и готов, если на оба ответ начинается с «да». */
export class MockScreener implements Screener {
static readonly questions = ["Вам подходит работа в смену? (да/нет)", "Готовы выйти на обучение? (да/нет)"];
async next(state: ScreenState): Promise<ScreenStep> {
const q = MockScreener.questions[state.answers.length];
if (q) return { kind: "ask", question: q };
const yes = (s?: string) => /^\s*да/i.test(s ?? "");
return { kind: "done", suitable: yes(state.answers[0]), readyForTraining: yes(state.answers[0]) && yes(state.answers[1]) };
}
}