import AppError from "../../errors/AppError"; import endPointQuery from "../../helpers/EndPointQuery"; import GetDefaultWhatsApp from "../../helpers/GetDefaultWhatsApp"; import { getWbot } from "../../libs/wbot"; const CheckIsValidContact = async (number: string): Promise => { const defaultWhatsapp = await GetDefaultWhatsApp(); const wbot_url = await getWbot(defaultWhatsapp.id); const isValidNumber = await endPointQuery(`${wbot_url}/api/validate`, { mobile: `${number}`, }) console.log('isValidNumber.data.number: ', isValidNumber.data.number) try { // const isValidNumber = await wbot.isRegisteredUser(`${number}@c.us`); if (!isValidNumber || isValidNumber && !isValidNumber.data.isValid) { throw new AppError("invalidNumber"); } } catch (err: any) { if (err.message === "invalidNumber") { throw new AppError("ERR_WAPP_INVALID_CONTACT"); } throw new AppError("ERR_WAPP_CHECK_CONTACT"); } if (isValidNumber && isValidNumber.data.isValid) return isValidNumber.data.number }; export default CheckIsValidContact;