From db1dcbf581ab4337fe0e4bbbe29170175ff49987 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 10 Jan 2025 18:51:55 +0300 Subject: [PATCH] app/bot: add contact define name & phone --- apps/bot/src/index.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/bot/src/index.ts b/apps/bot/src/index.ts index b1df537..1ce20ae 100644 --- a/apps/bot/src/index.ts +++ b/apps/bot/src/index.ts @@ -42,13 +42,16 @@ bot.command('addcontact', async (context) => { bot.on(message('contact'), async (context) => { const customer = await getCustomer(context.from.id); - const isRegistration = !customer; + const { contact } = context.message; + const name = (contact.first_name || '') + ' ' + (contact.last_name || '').trim(); + const phone = contact.phone_number; + if (isRegistration) { const response = await createUser({ - name: context.from.first_name, - phone: context.message.contact.phone_number, + name, + phone, telegramId: context.from.id, }).catch((error) => { context.reply('Произошла ошибка.\n' + error); @@ -68,10 +71,6 @@ bot.on(message('contact'), async (context) => { ); } - const { contact } = context.message; - const name = (contact.first_name || '') + ' ' + (contact.last_name || '').trim(); - const phone = contact.phone_number; - const response = await createClient({ name, phone }).catch((error) => { context.reply('Произошла ошибка.\n' + error); });