Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 6 additions & 60 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,19 @@
version: '3.8'

networks:
public-network:
driver: bridge

services:
api:
container_name: codechat_api
image: codechat/api:v1.3.4
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
ports:
- 8084:8084
volumes:
- instances_connecteds:/codechat/instances
environment:
- SERVER_PORT=8084
- SESSION_SECRET=W0NvZGVDaGF0XTpbU2Vzc

- LOG_LEVEL=ERROR|WARN|INFO|DEBUG|LOG|VERBOSE|DARK
- LOG_COLOR=true

- DATABASE_ENABLED=true
- DATABASE_URL=postgres://[USER]:[PASS]@[HOST]:[PORT]/[DATABASE_NAME]?schema=public
- DATABASE_SYNC_MESSAGES=true
- DATABASE_SAVE_DATA_NEW_MESSAGE=true
- DATABASE_SAVE_MESSAGE_UPDATE=true
- DATABASE_SAVE_DATA_CONTACTS=true
- DATABASE_SAVE_DATA_CHATS=true

- GLOBAL_WEBHOOK_URL=url
- GLOBAL_WEBHOOK_ENABLED=false

- INSTANCE_EXPIRATION_TIME=false

- CONFIG_SESSION_PHONE_CLIENT=CodeChat_V1
- CONFIG_SESSION_PHONE_NAME=Edge

- WA_VERSION=[ 2, 3000, 1023235404 ]

- QRCODE_LIMIT=10
- QRCODE_EXPIRATION_TIME=60
- QRCODE_LIGHT_COLOR='#ffffff'
- QRCODE_DARK_COLOR='#198754'

- CONNECTION_TIMEOUT=300

- AUTHENTICATION_GLOBAL_AUTH_TOKEN=zYzP7ocstxh3SJ23D4FZTCu4ehnM8v4hu
- AUTHENTICATION_JWT_EXPIRES_IN=0
- AUTHENTICATION_JWT_SECRET=3RFYiiRmvNiokSBrLZzx

- PROVIDER_ENABLED=false
- PROVIDER_HOST=127.0.0.1
- PROVIDER_PORT=5656
- PROVIDER_PREFIX=codechat

- BASE_URL=

# - S3_ENABLED=false
# - S3_ACCESS_KEY=[ACCESS_KEY]
# - S3_SECRET_KEY=[SECRET_KEY]
# - S3_BUCKET=[BUCKET]
# - S3_PORT=9000
# - S3_ENDPOINT=[ENDPOINT]
# - S3_USE_SSL=false
- ./instances:/codechat/instances
env_file:
- .env
networks:
- public-network

volumes:
# In terminal run: docker volume create --name=instances_connecteds
instances_connecteds:
external:
name: instances_connecteds
28 changes: 21 additions & 7 deletions src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import {
import { Logger } from '../../config/logger.config';
import { INSTANCE_DIR, ROOT_DIR } from '../../config/path.config';
import { join, normalize } from 'path';
import axios, { AxiosError } from 'axios';
import axios, { AxiosError, AxiosInstance } from 'axios';
import qrcode, { QRCodeToDataURLOptions } from 'qrcode';
import qrcodeTerminal from 'qrcode-terminal';
import { Boom } from '@hapi/boom';
Expand Down Expand Up @@ -156,6 +156,7 @@ import {
import { createProxyAgents } from '../../utils/proxy';
import { fetchLatestBaileysVersionV2 } from '../../utils/wa-version';
import { getJidUser, getUserGroup } from '../../utils/extract-id';
import http from 'http';

type InstanceQrCode = {
count: number;
Expand All @@ -180,6 +181,18 @@ export class WAStartupService {
this.configService,
this.providerFiles,
);

const httpAgent = new http.Agent({
keepAlive: true,
maxSockets: 100,
maxFreeSockets: 10,
timeout: 60000,
});

this.axiosInstance = axios.create({
httpAgent,
timeout: 60000,
});
}

private readonly logger = new Logger(this.configService, WAStartupService.name);
Expand All @@ -191,6 +204,7 @@ export class WAStartupService {
private readonly stateConnection: InstanceStateConnection = { state: 'close' };
private readonly databaseOptions: Database =
this.configService.get<Database>('DATABASE');
private readonly axiosInstance: AxiosInstance;

private endSession = false;
public client: WASocket;
Expand Down Expand Up @@ -297,7 +311,7 @@ export class WAStartupService {
try {
if (this.webhook?.enabled) {
if (this.webhook?.events && this.webhook?.events[event]) {
await axios.post(
await this.axiosInstance.post(
this.webhook.url,
{
event: eventDesc,
Expand All @@ -308,7 +322,7 @@ export class WAStartupService {
);
}
if (!this.webhook?.events) {
await axios.post(
await this.axiosInstance.post(
this.webhook.url,
{
event: eventDesc,
Expand Down Expand Up @@ -342,7 +356,7 @@ export class WAStartupService {
try {
const globalWebhook = this.configService.get<GlobalWebhook>('GLOBAL_WEBHOOK');
if (globalWebhook?.ENABLED && isURL(globalWebhook.URL)) {
await axios.post(
await this.axiosInstance.post(
globalWebhook.URL,
{
event: eventDesc,
Expand Down Expand Up @@ -1654,7 +1668,7 @@ export class WAStartupService {
const isURL = /http(s?):\/\//.test(mediaMessage.media as string);

if (isURL) {
const response = await axios.get(mediaMessage.media as string, {
const response = await this.axiosInstance.get(mediaMessage.media as string, {
responseType: 'arraybuffer',
});

Expand Down Expand Up @@ -1927,7 +1941,7 @@ export class WAStartupService {
jpegThumbnail: await (async () => {
if (data.linkMessage?.thumbnailUrl) {
try {
const response = await axios.get(data.linkMessage.thumbnailUrl, {
const response = await this.axiosInstance.get(data.linkMessage.thumbnailUrl, {
responseType: 'arraybuffer',
});
return new Uint8Array(response.data);
Expand Down Expand Up @@ -2417,7 +2431,7 @@ export class WAStartupService {
try {
let pic: WAMediaUpload;
if (isURL(picture.image)) {
pic = (await axios.get(picture.image, { responseType: 'arraybuffer' })).data;
pic = (await this.axiosInstance.get(picture.image, { responseType: 'arraybuffer' })).data;
} else if (isBase64(picture.image)) {
pic = Buffer.from(picture.image, 'base64');
} else {
Expand Down