diff --git a/integrations/paradiz-web/paradiz-web-agent-server.mjs b/integrations/paradiz-web/paradiz-web-agent-server.mjs index 1c9db51..1c4eb83 100644 --- a/integrations/paradiz-web/paradiz-web-agent-server.mjs +++ b/integrations/paradiz-web/paradiz-web-agent-server.mjs @@ -114,14 +114,32 @@ async function sendTelegramHumanLead(userText) { 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'); + + let payload = null; + try { payload = JSON.parse(String(userText)); } catch {} + + const phone = payload?.phone || (String(userText).match(PHONE_RE) || [])[0] || '-'; + const email = payload?.email || (String(userText).match(EMAIL_RE) || [])[0] || '-'; + + const text = payload + ? [ + '📌 Новая заявка на бронь (сайт)', + `Гость: ${payload.guest || '-'}`, + `Телефон: ${phone}`, + `E-mail: ${email}`, + `Период: ${payload.checkin || '-'} → ${payload.checkout || '-'}`, + `Гостей: ${payload.guests || '-'}`, + `Номер: ${payload.room || '-'}`, + `Сумма: ${payload.total || '-'}`, + `Комментарий: ${payload.notes || '-'}`, + ].join('\n') + : [ + '📌 Новая заявка на бронь (сайт)', + `Телефон: ${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',