app/bot: normalize phone before register

This commit is contained in:
vchikalkin 2025-01-15 18:31:28 +03:00
parent d987c98b30
commit 30b0d4d394
2 changed files with 7 additions and 1 deletions

View File

@ -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({

View File

@ -0,0 +1,5 @@
export function normalizePhoneNumber(phone: string): string {
const digitsOnly = phone.replaceAll(/\D/gu, '');
return `+${digitsOnly}`;
}