fix(paradizweb): send telegram booking leads after contact capture

This commit is contained in:
OpenClaw Assistant
2026-03-03 00:04:55 +03:00
parent d49445849b
commit a3d2beb54a

View File

@@ -4,6 +4,7 @@ import { execFile } from 'node:child_process';
import { readFileSync, existsSync } from 'node:fs';
const HUMAN_RE = /(жив[а-яёa-z]*\s*(человек|менеджер|оператор)|менеджер|оператор|свяж(ите|ись)|перезвон|позвон)/i;
const BOOK_RE = /(бро(нь|нировать|нирую|нирование)|забронировать|оформ(ить|ляю)\s*бронь)/i;
const PHONE_RE = /\+?\d[\d\s()\-]{8,}\d/;
const EMAIL_RE = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/i;
@@ -74,6 +75,8 @@ function json(res, code, payload) {
const OPENCLAW_BIN = env.OPENCLAW_BIN || '/home/openclaw/.npm-global/bin/openclaw';
const pendingHumanByClient = new Map();
const pendingBookingByClient = new Map();
const bookingLeadSentByClient = new Map();
const aiDisclosedByClient = new Map();
function hasContactInfo(text) {
@@ -107,6 +110,25 @@ async function sendTelegramHumanLead(userText) {
return res.ok;
}
async function sendTelegramBookingLead(userText) {
if (!TG_BOT || !TG_CHAT) return false;
const phone = (String(userText).match(PHONE_RE) || [])[0] || '-';
const email = (String(userText).match(EMAIL_RE) || [])[0] || '-';
const text = [
'📌 Новая заявка на бронь (сайт)',
`Телефон: ${phone}`,
`E-mail: ${email}`,
`Сообщение: ${String(userText).slice(0, 700)}`
].join('\n');
const body = new URLSearchParams({ chat_id: String(TG_CHAT), text, disable_web_page_preview: 'true' }).toString();
const res = await fetch(`https://api.telegram.org/bot${TG_BOT}/sendMessage`, {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
body
});
return res.ok;
}
function runAgent(userText) {
return new Promise((resolve, reject) => {
const guardrail = [
@@ -186,6 +208,19 @@ const server = http.createServer(async (req, res) => {
});
}
if (BOOK_RE.test(question)) {
const hasContact = hasContactInfo(question);
if (!hasContact) {
if (clientId) pendingBookingByClient.set(clientId, true);
} else if (!clientId || !bookingLeadSentByClient.get(clientId)) {
await sendTelegramBookingLead(question).catch(() => {});
if (clientId) {
bookingLeadSentByClient.set(clientId, true);
pendingBookingByClient.delete(clientId);
}
}
}
if (clientId && pendingHumanByClient.get(clientId) && hasContactInfo(question)) {
await sendTelegramHumanLead(question).catch(() => {});
pendingHumanByClient.delete(clientId);
@@ -195,6 +230,12 @@ const server = http.createServer(async (req, res) => {
});
}
if (clientId && pendingBookingByClient.get(clientId) && hasContactInfo(question) && !bookingLeadSentByClient.get(clientId)) {
await sendTelegramBookingLead(question).catch(() => {});
pendingBookingByClient.delete(clientId);
bookingLeadSentByClient.set(clientId, true);
}
if (isExternalActionRequest(question)) {
return json(res, 200, {
ok: true,