fix(paradizweb): format booking lead telegram messages as readable fields
This commit is contained in:
@@ -114,14 +114,32 @@ async function sendTelegramHumanLead(userText) {
|
|||||||
|
|
||||||
async function sendTelegramBookingLead(userText) {
|
async function sendTelegramBookingLead(userText) {
|
||||||
if (!TG_BOT || !TG_CHAT) return false;
|
if (!TG_BOT || !TG_CHAT) return false;
|
||||||
const phone = (String(userText).match(PHONE_RE) || [])[0] || '-';
|
|
||||||
const email = (String(userText).match(EMAIL_RE) || [])[0] || '-';
|
let payload = null;
|
||||||
const text = [
|
try { payload = JSON.parse(String(userText)); } catch {}
|
||||||
'📌 Новая заявка на бронь (сайт)',
|
|
||||||
`Телефон: ${phone}`,
|
const phone = payload?.phone || (String(userText).match(PHONE_RE) || [])[0] || '-';
|
||||||
`E-mail: ${email}`,
|
const email = payload?.email || (String(userText).match(EMAIL_RE) || [])[0] || '-';
|
||||||
`Сообщение: ${String(userText).slice(0, 700)}`
|
|
||||||
].join('\n');
|
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 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`, {
|
const res = await fetch(`https://api.telegram.org/bot${TG_BOT}/sendMessage`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
Reference in New Issue
Block a user