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", 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 diff --git a/package.json b/package.json index 96c408a24..00d44ca66 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", @@ -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, ' ');