From fab1927b34675b6ed83993542f39d435367fe23e Mon Sep 17 00:00:00 2001 From: "@milesibastos" Date: Wed, 28 Aug 2024 15:36:41 -0300 Subject: [PATCH 1/4] chore: update axios 1.7.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 96c408a24..d6eaacc30 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@prisma/client": "^5.15.0", "@sentry/node": "^8.28.0", "amqplib": "^0.10.3", - "axios": "^1.6.5", + "axios": "^1.7.5", "baileys": "6.7.7", "class-validator": "^0.14.1", "compression": "^1.7.4", From 955c61be31df14ea1914fe68758d4089ea74f1db Mon Sep 17 00:00:00 2001 From: "@milesibastos" Date: Tue, 24 Sep 2024 08:23:54 -0300 Subject: [PATCH 2/4] too opinionated... cleaning-up --- .vscode/settings.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8f568c693..e79c25aee 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,4 @@ { - "editor.fontSize": 13, - "editor.fontLigatures": true, - "editor.letterSpacing": 0.5, - "editor.smoothScrolling": true, "editor.tabSize": 2, "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit", From 25e939925a7741bf26bf0ea74f8677b166768290 Mon Sep 17 00:00:00 2001 From: "@milesibastos" Date: Tue, 24 Sep 2024 08:26:53 -0300 Subject: [PATCH 3/4] chore: build fixes --- Docker/scripts/generate_database.sh | 0 Dockerfile | 16 ++++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) mode change 100644 => 100755 Docker/scripts/generate_database.sh diff --git a/Docker/scripts/generate_database.sh b/Docker/scripts/generate_database.sh old mode 100644 new mode 100755 diff --git a/Dockerfile b/Dockerfile index f9fa812c3..e1b08d0f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ -FROM node:20-alpine AS builder +FROM node:20 AS builder -RUN apk update && \ - apk add git ffmpeg wget curl bash +RUN apt-get update && \ + apt-get install -y git ffmpeg wget curl bash dos2unix && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* LABEL version="2.1.1" description="Api to control whatsapp features through http requests." LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes" @@ -29,10 +31,12 @@ RUN ./Docker/scripts/generate_database.sh RUN npm run build -FROM node:20-alpine AS final +FROM node:20 AS final -RUN apk update && \ - apk add tzdata ffmpeg bash +RUN apt-get update && \ + apt-get install -y tzdata ffmpeg bash && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* ENV TZ=America/Sao_Paulo From aee60a6ed00b9673f24f235c9a19908069992912 Mon Sep 17 00:00:00 2001 From: Leonardo Amaro Date: Fri, 27 Sep 2024 12:36:02 -0300 Subject: [PATCH 4/4] =?UTF-8?q?integra=C3=A7=C3=A3o=20wavoip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/api/integrations/channel/wavoip/index.ts | 58 +++++++++++++++++++ .../whatsapp/whatsapp.baileys.service.ts | 3 + 3 files changed, 62 insertions(+) create mode 100644 src/api/integrations/channel/wavoip/index.ts diff --git a/package.json b/package.json index d6eaacc30..00d44ca66 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "socks-proxy-agent": "^8.0.1", "tsup": "^8.2.4", "uuid": "^9.0.0", + "voice-calls-baileys": "^1.0.5", "xml2js": "^0.6.2", "yamljs": "^0.3.0" }, diff --git a/src/api/integrations/channel/wavoip/index.ts b/src/api/integrations/channel/wavoip/index.ts new file mode 100644 index 000000000..6777ddc88 --- /dev/null +++ b/src/api/integrations/channel/wavoip/index.ts @@ -0,0 +1,58 @@ +import axios from 'axios'; +import { useVoiceCallsBaileys } from 'voice-calls-baileys'; + +async function makeRequest(token: string) { + try { + const url = 'https://api.wavoip.com/devices/evolution'; // Substitua pela URL da sua API + const payload = { + name: '', + token: token, + }; + + const response = await axios.post(url, payload); + const data = response.data; + + if (data?.type === 'success') { + console.log('Requisição bem-sucedida!'); + console.log('Token:', token); + return true; + } else { + console.log('Resposta não válida. Tentando novamente...', response.data); + return false; + } + } catch (error) { + if (error?.response?.status === 500) { + console.error('Erro 500: ', error.response.data || 'Erro no servidor.'); + } else { + console.error(`Erro ${error?.response?.status}:`, error?.response?.data?.message || error?.message || error); + } + return false; + } +} + +async function retryRequest(token: string) { + let hasRetry = true; + while (hasRetry) { + const success = await makeRequest(token); + if (success) { + hasRetry = false; + break; + } + await new Promise((resolve) => setTimeout(resolve, 1000)); // Espera 1 segundo antes de tentar novamente + } +} + +const start_connection = async (client, instance) => { + const token = instance.token; + + if (!token) { + console.log('Token não recebido'); + return; + } + + await retryRequest(token); + + useVoiceCallsBaileys(token, client, 'open', true); +}; + +export default start_connection; diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 13eea7b5a..7483996bd 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -130,6 +130,8 @@ import sharp from 'sharp'; import { PassThrough } from 'stream'; import { v4 } from 'uuid'; +import startWavoip from '../wavoip'; + const groupMetadataCache = new CacheService(new CacheEngine(configService, 'groups').getEngine()); export class BaileysStartupService extends ChannelStartupService { @@ -366,6 +368,7 @@ export class BaileysStartupService extends ChannelStartupService { } if (connection === 'open') { + startWavoip(this.client, this.instance); this.instance.wuid = this.client.user.id.replace(/:\d+/, ''); this.instance.profilePictureUrl = (await this.profilePicture(this.instance.wuid)).profilePictureUrl; const formattedWuid = this.instance.wuid.split('@')[0].padEnd(30, ' ');