diff --git a/apps/bot/src/index.ts b/apps/bot/src/index.ts index 7419c04..1f2451c 100644 --- a/apps/bot/src/index.ts +++ b/apps/bot/src/index.ts @@ -2,6 +2,7 @@ /* eslint-disable consistent-return */ import { env as environment } from './config/env'; import { commandsList, KEYBOARD_REMOVE, KEYBOARD_SHARE_PHONE } from './message'; +import { normalizePhoneNumber } from './utils/phone'; import { createOrUpdateUser, getCustomer, updateCustomerMaster } from '@repo/graphql/api'; import { Enum_Customer_Role } from '@repo/graphql/types'; import { Telegraf } from 'telegraf'; @@ -45,7 +46,7 @@ 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 phone = normalizePhoneNumber(contact.phone_number); if (isRegistration) { const response = await createOrUpdateUser({ diff --git a/apps/bot/src/utils/phone.ts b/apps/bot/src/utils/phone.ts new file mode 100644 index 0000000..924ad3a --- /dev/null +++ b/apps/bot/src/utils/phone.ts @@ -0,0 +1,5 @@ +export function normalizePhoneNumber(phone: string): string { + const digitsOnly = phone.replaceAll(/\D/gu, ''); + + return `+${digitsOnly}`; +}