app/bot: normalize phone before register
This commit is contained in:
parent
d987c98b30
commit
30b0d4d394
@ -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({
|
||||
|
||||
5
apps/bot/src/utils/phone.ts
Normal file
5
apps/bot/src/utils/phone.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export function normalizePhoneNumber(phone: string): string {
|
||||
const digitsOnly = phone.replaceAll(/\D/gu, '');
|
||||
|
||||
return `+${digitsOnly}`;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user