diff --git a/backend/src/services/WbotServices/ImportContactsService.ts b/backend/src/services/WbotServices/ImportContactsService.ts index 2b9df572..81f618cc 100644 --- a/backend/src/services/WbotServices/ImportContactsService.ts +++ b/backend/src/services/WbotServices/ImportContactsService.ts @@ -1,13 +1,13 @@ import * as Sentry from "@sentry/node"; +import { isString, isArray } from "lodash"; +import path from "path"; +import fs from "fs"; import GetDefaultWhatsApp from "../../helpers/GetDefaultWhatsApp"; import { getWbot } from "../../libs/wbot"; import Contact from "../../models/Contact"; import { logger } from "../../utils/logger"; import ShowBaileysService from "../BaileysServices/ShowBaileysService"; import CreateContactService from "../ContactServices/CreateContactService"; -import { isString, isArray } from "lodash"; -import path from "path"; -import fs from 'fs'; const ImportContactsService = async (companyId: number): Promise => { const defaultWhatsapp = await GetDefaultWhatsApp(companyId); @@ -20,35 +20,38 @@ const ImportContactsService = async (companyId: number): Promise => { phoneContacts = JSON.parse(JSON.stringify(contactsString.contacts)); const publicFolder = path.resolve(__dirname, "..", "..", "..", "public"); - const beforeFilePath = path.join(publicFolder, 'contatos_antes.txt'); - fs.writeFile(beforeFilePath, JSON.stringify(phoneContacts, null, 2), (err) => { - if (err) { - logger.error(`Failed to write contacts to file: ${err}`); - throw err; + const beforeFilePath = path.join(publicFolder, "contatos_antes.txt"); + fs.writeFile( + beforeFilePath, + JSON.stringify(phoneContacts, null, 2), + err => { + if (err) { + logger.error(`Failed to write contacts to file: ${err}`); + throw err; + } + console.log("O arquivo contatos_antes.txt foi criado!"); } - console.log('O arquivo contatos_antes.txt foi criado!'); - }); - + ); } catch (err) { Sentry.captureException(err); logger.error(`Could not get whatsapp contacts from phone. Err: ${err}`); } const publicFolder = path.resolve(__dirname, "..", "..", "..", "public"); - const afterFilePath = path.join(publicFolder, 'contatos_depois.txt'); - fs.writeFile(afterFilePath, JSON.stringify(phoneContacts, null, 2), (err) => { + const afterFilePath = path.join(publicFolder, "contatos_depois.txt"); + fs.writeFile(afterFilePath, JSON.stringify(phoneContacts, null, 2), err => { if (err) { logger.error(`Failed to write contacts to file: ${err}`); throw err; } - console.log('O arquivo contatos_depois.txt foi criado!'); + console.log("O arquivo contatos_depois.txt foi criado!"); }); const phoneContactsList = isString(phoneContacts) ? JSON.parse(phoneContacts) : phoneContacts; - console.log(isArray(phoneContacts)) + console.log(isArray(phoneContacts)); if (Array.isArray(phoneContactsList)) { phoneContactsList.forEach(async ({ id, name, notify }) => { if (id === "status@broadcast" || id.includes("g.us")) return; @@ -58,7 +61,7 @@ const ImportContactsService = async (companyId: number): Promise => { where: { number, companyId } }); - console.log(existingContact) + console.log(existingContact); if (existingContact) { // Atualiza o nome do contato existente existingContact.name = name || notify;