From 763c5de03fc4f9a2bd4a2db72cd32b9da89982a2 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Sun, 18 Feb 2024 09:57:14 -0300 Subject: [PATCH] fix: adjusts in messageType --- package.json | 3 ++- src/whatsapp/services/whatsapp.business.service.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 3c26f4de..ef023149 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "express": "^4.18.2", "express-async-errors": "^3.1.1", "fast-levenshtein": "^3.0.0", + "form-data": "^4.0.0", "hbs": "^4.2.0", "https-proxy-agent": "^7.0.2", "i18next": "^23.7.19", @@ -113,4 +114,4 @@ "ts-node-dev": "^2.0.0", "typescript": "^4.9.5" } -} \ No newline at end of file +} diff --git a/src/whatsapp/services/whatsapp.business.service.ts b/src/whatsapp/services/whatsapp.business.service.ts index 5515d6fb..f208a716 100644 --- a/src/whatsapp/services/whatsapp.business.service.ts +++ b/src/whatsapp/services/whatsapp.business.service.ts @@ -1,6 +1,7 @@ import axios from 'axios'; import { arrayUnique, isURL } from 'class-validator'; import EventEmitter2 from 'eventemitter2'; +import FormData from 'form-data'; import fs from 'fs/promises'; import { getMIMEType } from 'node-mime-types'; @@ -298,8 +299,6 @@ export class BusinessStartupService extends WAStartupService { let messageRaw: MessageRaw; let pushName: any; - console.log('received?.messages[0]', received?.messages[0]); - if (received.contacts) pushName = received.contacts[0].profile.name; if (received.messages) { @@ -756,7 +755,6 @@ export class BusinessStartupService extends WAStartupService { return messageRaw; } catch (error) { this.logger.error(error); - console.log(error.data); throw new BadRequestException(error.toString()); } } @@ -779,9 +777,11 @@ export class BusinessStartupService extends WAStartupService { const integration = await this.findIntegration(); const formData = new FormData(); - const arquivoBuffer = await fs.readFile(mediaMessage.media); - const arquivoBlob = new Blob([arquivoBuffer], { type: mediaMessage.mimetype }); - formData.append('file', arquivoBlob); + + const fileBuffer = await fs.readFile(mediaMessage.media); + + const fileBlob = new Blob([fileBuffer], { type: mediaMessage.mimetype }); + formData.append('file', fileBlob); formData.append('typeFile', mediaMessage.mimetype); formData.append('messaging_product', 'whatsapp'); const headers = { Authorization: `Bearer ${integration.token}` };