Compare commits

...
30 Commits
Author SHA1 Message Date
devlikepro 6346433d45 [core] wait 10 seconds and stop
Release / amd64 - chrome - chrome (push) Waiting to run
Release / amd64 - chromium - latest (push) Waiting to run
Release / linux/arm64 - chromium - arm (push) Waiting to run
Release / amd64 - none - noweb (push) Waiting to run
Release / linux/arm64 - none - noweb-arm (push) Waiting to run
2024-10-08 18:04:44 +07:00
devlikepro 44e63e00c3 [core] always 2024-10-08 17:55:36 +07:00
devlikepro 8648b44583 [core] stop all jobs before saving creds 2024-10-08 17:49:50 +07:00
devlikepro 086d540ee2 [core] 2024.10.4 2024-10-08 17:46:22 +07:00
devlikepro adf6836ee5 [core] no get app anymore 2024-10-08 17:46:03 +07:00
devlikepro 62f4406c51 [core] send SIGTERM 2024-10-08 17:46:03 +07:00
devlikepro e4c201e105 [core] exec node dist/main 2024-10-08 17:46:03 +07:00
devlikepro b6b0b1e7b3 [core] enable hooks before start listening 2024-10-08 17:46:03 +07:00
devlikepro 9d857d015f [core] Log signals 2024-10-08 17:46:03 +07:00
devlikepro 2055c595bb [core] NOWEB - save creds before stopping the session 2024-10-08 17:46:03 +07:00
devlikepro 00e33ceac7 [core] NOWEB - reuse store 2024-10-08 17:46:02 +07:00
devlikepro 77ef1ecebf [core] Update NOWEB
fix #567
2024-10-08 17:45:56 +07:00
devlikepro 57672a2a9c [core] 2024.10.3
Release / amd64 - chrome - chrome (push) Waiting to run
Release / amd64 - chromium - latest (push) Waiting to run
Release / linux/arm64 - chromium - arm (push) Waiting to run
Release / amd64 - none - noweb (push) Waiting to run
Release / linux/arm64 - none - noweb-arm (push) Waiting to run
2024-10-03 14:50:52 +07:00
devlikepro 0ae594b198 [core] Add more logging in WEBJS 2024-10-03 14:50:27 +07:00
devlikepro 14a7e1c72d .env.example 2024-10-01 18:35:46 +07:00
devlikepro e570cbef12 [core] Up dashboard
Release / amd64 - chrome - chrome (push) Waiting to run
Release / amd64 - chromium - latest (push) Waiting to run
Release / linux/arm64 - chromium - arm (push) Waiting to run
Release / amd64 - none - noweb (push) Waiting to run
Release / linux/arm64 - none - noweb-arm (push) Waiting to run
2024-10-01 10:51:25 +07:00
devlikepro c6d732a723 [core] 2024.10.2 2024-10-01 10:50:36 +07:00
devlikepro 9cb0131a37 [core] Close store properly at the end 2024-10-01 10:50:19 +07:00
devlikepro d72b665cfe [core] update mongodb driver 2024-10-01 10:50:18 +07:00
devlikepro d6b87585f7 [core] log errors during periodic and one time jobs 2024-10-01 10:50:18 +07:00
devlikepro 2e01692e92 [core] comment mongo and minio 2024-09-29 18:20:22 +07:00
devlikepro 78ad79c08f [core] comment mongo and minio 2024-09-29 18:16:44 +07:00
devlikepro 725446a022 [core] fix .env 2024-09-29 17:48:23 +07:00
devlikepro 3bd7594b7f [core] no ssl 2024-09-29 17:41:14 +07:00
devlikepro 2bd314732a [core] Do not expose by default 2024-09-29 17:22:48 +07:00
devlikepro f4d7776bca [core] Adjust .env 2024-09-29 16:53:09 +07:00
devlikepro 80e13beb2b [core] Split .env 2024-09-29 16:51:22 +07:00
devlikepro 5c37826710 [core] protected 2024-09-29 16:35:24 +07:00
devlikepro 693a288839 [core] Move lock to SessionManager 2024-09-29 16:00:09 +07:00
devlikepro ecc0e1b60d [core] Allow to stop sessions even with no config 2024-09-29 15:43:52 +07:00
17 changed files with 323 additions and 306 deletions

No files matched your search

+165
View File
@@ -0,0 +1,165 @@
# WAHA Configuration
# https://waha.devlike.pro/docs/how-to/config/
#
# Common
#
# If you know the right URL, you can use it here.
# Use any port in WHATSAPP_API_PORT and domain in WHATSAPP_API_HOSTNAME
# https://waha.devlike.pro/docs/how-to/config/#common
#WHATSAPP_API_SCHEMA=http
#WHATSAPP_API_PORT=3000
#WHATSAPP_API_HOSTNAME=localhost
#WAHA_BASE_URL=http://localhost:3000
#
# Set your timezone to see the right time on screenshots
# Find your timezone name in the list
# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
#TZ=Europe/Dublin
#
# Security
#
# https://waha.devlike.pro/docs/how-to/security/
#
WHATSAPP_API_KEY=321
WAHA_DASHBOARD_USERNAME=waha
WAHA_DASHBOARD_PASSWORD=waha
#WHATSAPP_SWAGGER_USERNAME=admin
#WHATSAPP_SWAGGER_PASSWORD=admin
#
# Dashboard
#
# https://waha.devlike.pro/docs/how-to/waha-dashboard/#configuration
# Enabled by default
#WAHA_DASHBOARD_ENABLED=true
#WAHA_DASHBOARD_USERNAME=waha
#WAHA_DASHBOARD_PASSWORD=waha
#
# Logging
# https://waha.devlike.pro/docs/how-to/observability/#logging
#
# Set log format to JSON if you consume logs with log management systems
WAHA_LOG_FORMAT=JSON
WAHA_LOG_LEVEL=info
# WAHA_LOG_FORMAT=PRETTY
# If you want to see more logs, you can set the log level to debug
#WAHA_LOG_LEVEL=debug
# DEBUG=1 # shortcut for setting log level to debug
#
# Engine
# https://waha.devlike.pro/docs/how-to/engines/
#
# Choose the right engine for your needs (WEBJS by default)
WHATSAPP_DEFAULT_ENGINE=WEBJS
# Use NOWEB engine for the fastest performance
#WHATSAPP_DEFAULT_ENGINE=NOWEB
#
# Sessions
# https://waha.devlike.pro/docs/how-to/config/#sessions
#
# Restart all sessions when container starts
WHATSAPP_RESTART_ALL_SESSIONS=True
# Do not print QR codes in logs
WAHA_PRINT_QR=False
#
# OR you can specify sessions by name, if you have handful amount of sessions
#WHATSAPP_START_SESSION=session1,session2
# Do not use both WHATSAPP_RESTART_ALL_SESSIONS and WHATSAPP_START_SESSION parameters
#
#
# Swagger
# https://waha.devlike.pro/docs/how-to/swagger/
#
WHATSAPP_SWAGGER_USERNAME=admin
WHATSAPP_SWAGGER_PASSWORD=admin
# Disable Swagger
#WHATSAPP_SWAGGER_ENABLED=false
# Enable advanced Swagger configuration
#WHATSAPP_SWAGGER_CONFIG_ADVANCED=true
#
# Swagger White Label customization
# https://waha.devlike.pro/docs/how-to/swagger/#white-label
#WHATSAPP_SWAGGER_TITLE=WAHA API
#
#
# Global Proxy Settings
# https://waha.devlike.pro/docs/how-to/config/#global-proxy-configuration
#
# You can also set proxy settings for each session later when starting it
# https://waha.devlike.pro/docs/how-to/sessions/#configure-proxy
#WHATSAPP_PROXY_SERVER=proxy.example.com:3128
#WHATSAPP_PROXY_SERVER_USERNAME=user
#WHATSAPP_PROXY_SERVER_PASSWORD=pass
#
#
# HTTPS Configuration
# https://waha.devlike.pro/docs/how-to/config/#https
#
# Consider using certbot for HTTPS
# https://waha.devlike.pro/blog/setting-up-https-for-waha/#lets-encrypt-certbot--waha
#
#WAHA_HTTPS_ENABLED=true
#WAHA_HTTPS_PATH_KEY=/etc/letsencrypt/live/waha.example.pro/privkey.pem
#WAHA_HTTPS_PATH_CERT=/etc/letsencrypt/live/waha.example.pro/cert.pem \
#WAHA_HTTPS_PATH_CA=/etc/letsencrypt/live/waha.example.pro/chain.pem
#WHATSAPP_API_SCHEMA=https
#WHATSAPP_API_PORT=3000
#WHATSAPP_API_HOSTNAME=waha.example.pro
#
#
# Media Configuration
#
# https://waha.devlike.pro/docs/how-to/config/#files
#
# Disable media (images, videos, files) download for incoming messages
#WHATSAPP_DOWNLOAD_MEDIA=false
#
# Download only specific media types
#WHATSAPP_FILES_MIMETYPES=image/jpeg,image/png
#
# Media - Local Storage
# https://waha.devlike.pro/docs/how-to/storages/#media---local
#
# Set to 0 to keep media files forever
# https://waha.devlike.pro/docs/how-to/storages/#save-media-files-between-the-container-restarts
WAHA_MEDIA_STORAGE=LOCAL
WHATSAPP_FILES_LIFETIME=0
WHATSAPP_FILES_FOLDER=/app/.media
# Keep media files for 180 seconds (3 minutes)
#WHATSAPP_FILES_LIFETIME=180
#
# Media - S3 Storage
# https://waha.devlike.pro/docs/how-to/storages/#media---s3
#WAHA_MEDIA_STORAGE=S3
#WAHA_S3_REGION=eu-west-2
#WAHA_S3_BUCKET=waha
#WAHA_S3_ACCESS_KEY_ID=minioadmin
#WAHA_S3_SECRET_ACCESS_KEY=minioadmin
#WAHA_S3_ENDPOINT=http://minio:9000 # Not required if you're using AWS S3
#WAHA_S3_FORCE_PATH_STYLE=True # Required for Minio
#WAHA_S3_PROXY_FILES=True # Required for docker-compose setup
#
# Global Webhooks
#
# https://waha.devlike.pro/docs/how-to/config/#webhooks
# https://waha.devlike.pro/docs/how-to/webhooks/
#WHATSAPP_HOOK_URL=https://webhook.site/11111111-1111-1111-1111-11111111
#WHATSAPP_HOOK_EVENTS=session.status,message,message.reaction
#
#
# MongoDB Configuration
# https://waha.devlike.pro/docs/how-to/storages/#sessions---mongodb
#WHATSAPP_SESSIONS_MONGO_URL=mongodb://mongodb:27017
#
+1
View File
@@ -1,3 +1,4 @@
.env
*.heapsnapshot
.yarn
example.ts
+1 -1
View File
@@ -26,7 +26,7 @@ RUN yarn build && find ./dist -name "*.d.ts" -delete
FROM node:${NODE_VERSION} AS dashboard
# Download WAHA Dashboard
ENV WAHA_DASHBOARD_SHA 10f010e25b95c383460e1197133c212a98ee3611
ENV WAHA_DASHBOARD_SHA a3e3e31850af55161ca58cd8edb7dc9562707d14
RUN \
wget https://github.com/devlikeapro/dashboard/archive/${WAHA_DASHBOARD_SHA}.zip \
&& unzip ${WAHA_DASHBOARD_SHA}.zip -d /tmp/dashboard \
+1 -1
View File
@@ -32,7 +32,7 @@ for-swagger:
WHATSAPP_SWAGGER_CONFIG_ADVANCED=true . ${NVM_DIR}/nvm.sh && nvm exec yarn start
up-noweb:
. ${NVM_DIR}/nvm.sh && nvm exec yarn up @adiwajshing/baileys@github:devlikeapro/Baileys#fork-master-channels-2
. ${NVM_DIR}/nvm.sh && nvm exec yarn up @adiwajshing/baileys@github:devlikeapro/Baileys#fork-master-channels-678
up-webjs:
. ${NVM_DIR}/nvm.sh && nvm exec yarn up whatsapp-web.js@github:devlikeapro/whatsapp-web.js#fork-main-channels
+33 -223
View File
@@ -1,246 +1,56 @@
#
# https://waha.devlike.pro/docs/how-to/install/
# Here's we provide a simple example of how to install WAHA using Docker Compose.
#
# We're assuming you have Docker and Docker Compose installed.
# If you don't have Docker Compose installed, you can follow the official guide:
# https://docs.docker.com/compose/install/
#
services:
waha:
# Always restart the container on failure
restart: always
#
# Image
#
image: devlikeapro/waha-plus:latest # or devlikeapro/waha:latest if you're using WAHA Core
#
# We strongly recommend using the pinned version of WAHA
# https://waha.devlike.pro/docs/how-to/engines/#versions
# image: devlikeapro/waha-plus:latest-2024.7.6 # 'latest' is not mistaken here
#
# Multiple images are available
# https://waha.devlike.pro/docs/how-to/engines/#docker-images
# image: devlikeapro/waha-plus:chrome
#
# https://portal.devlike.pro/docker-image
image: devlikeapro/waha-plus:latest
# WAHA Core
# image: devlikeapro/waha:latest
# The first port can be any free port you want
# The second port must be the same as WHATSAPP_API_PORT or 3000 by default
# Consider using the same port for simplicity
ports:
- '3000:3000/tcp'
# NOTE: if you're using HTTP, you can use the following port mapping
#- '80:3000/tcp'
# NOTE: if you're using HTTPS, you can use the following port mapping
#- '443:3000/tcp'
- '127.0.0.1:3000:3000/tcp'
volumes:
# Store sessions in the .sessions folder (comment it if you're using MongoDB)
# Doesn't work with WAHA Core
- './.sessions:/app/.sessions'
# Save media files
# https://waha.devlike.pro/docs/how-to/storages/#save-media-files-between-the-container-restarts
- './.media:/app/.media'
# If you're using certbot for HTTPS, you can use the following volume mapping
# https://waha.devlike.pro/blog/setting-up-https-for-waha/#lets-encrypt-certbot--waha
# - '/etc/letsencrypt:/etc/letsencrypt'
# WAHA Configuration
# https://waha.devlike.pro/docs/how-to/config/
environment:
#
# Common
#
# If you know the right URL, you can use it here.
# Use any port in WHATSAPP_API_PORT and domain in WHATSAPP_API_HOSTNAME
# https://waha.devlike.pro/docs/how-to/config/#common
#- WHATSAPP_API_SCHEMA=http
#- WHATSAPP_API_PORT=3000
#- WHATSAPP_API_HOSTNAME=localhost
#
# Set your timezone to see the right time on screenshots
# Find your timezone name in the list
# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
#- TZ=Europe/Dublin
#
# Security
#
# https://waha.devlike.pro/docs/how-to/security/
#
- WHATSAPP_API_KEY=321
- WAHA_DASHBOARD_USERNAME=waha
- WAHA_DASHBOARD_PASSWORD=waha
#- WHATSAPP_SWAGGER_USERNAME=admin
#- WHATSAPP_SWAGGER_PASSWORD=admin
#
# Dashboard
#
# https://waha.devlike.pro/docs/how-to/waha-dashboard/#configuration
# Enabled by default
#- WAHA_DASHBOARD_ENABLED=true
#- WAHA_DASHBOARD_USERNAME=waha
#- WAHA_DASHBOARD_PASSWORD=waha
#
# Logging
# https://waha.devlike.pro/docs/how-to/observability/#logging
#
# Set log format to JSON if you consume logs with log management systems
- WAHA_LOG_FORMAT=JSON
- WAHA_LOG_LEVEL=info
# - WAHA_LOG_FORMAT=PRETTY
# If you want to see more logs, you can set the log level to debug
#- WAHA_LOG_LEVEL=debug
# DEBUG=1 # shortcut for setting log level to debug
#
# Engine
#
# Choose the right engine for your needs (WEBJS by default)
# https://waha.devlike.pro/docs/how-to/engines/
- WHATSAPP_DEFAULT_ENGINE=WEBJS
# Use NOWEB engine for the fastest performance
#- WHATSAPP_DEFAULT_ENGINE=NOWEB
#
# Sessions
#
# https://waha.devlike.pro/docs/how-to/config/#sessions
# Restart all sessions when container starts
- WHATSAPP_RESTART_ALL_SESSIONS=True
# Do not print QR codes in logs
- WAHA_PRINT_QR=False
#
# OR you can specify sessions by name, if you have handful amount of sessions
#- WHATSAPP_START_SESSION=session1,session2
# Do not use both WHATSAPP_RESTART_ALL_SESSIONS and WHATSAPP_START_SESSION parameters
#
#
# Swagger
#
# https://waha.devlike.pro/docs/how-to/swagger/
#- WHATSAPP_SWAGGER_USERNAME=admin
#- WHATSAPP_SWAGGER_PASSWORD=admin
# Disable Swagger
#- WHATSAPP_SWAGGER_ENABLED=false
# Enable advanced Swagger configuration
#- WHATSAPP_SWAGGER_CONFIG_ADVANCED=true
#
# Swagger White Label customization
# https://waha.devlike.pro/docs/how-to/swagger/#white-label
#- WHATSAPP_SWAGGER_TITLE=WAHA API
#
#
# Global Proxy Settings
# https://waha.devlike.pro/docs/how-to/config/#global-proxy-configuration
# You can also set proxy settings for each session later when starting it
# https://waha.devlike.pro/docs/how-to/sessions/#configure-proxy
#- WHATSAPP_PROXY_SERVER=proxy.example.com:3128
#-WHATSAPP_PROXY_SERVER_USERNAME=user
#-WHATSAPP_PROXY_SERVER_PASSWORD=pass
#
#
# HTTPS Configuration
#
# https://waha.devlike.pro/docs/how-to/config/#https
# Consider using certbot for HTTPS
# https://waha.devlike.pro/blog/setting-up-https-for-waha/#lets-encrypt-certbot--waha
#- WAHA_HTTPS_ENABLED=true
#- WAHA_HTTPS_PATH_KEY=/etc/letsencrypt/live/waha.example.pro/privkey.pem
#- WAHA_HTTPS_PATH_CERT=/etc/letsencrypt/live/waha.example.pro/cert.pem \
#- WAHA_HTTPS_PATH_CA=/etc/letsencrypt/live/waha.example.pro/chain.pem
#- WHATSAPP_API_SCHEMA=https
#- WHATSAPP_API_PORT=3000
#- WHATSAPP_API_HOSTNAME=waha.example.pro
#
#
# Media Configuration
#
# https://waha.devlike.pro/docs/how-to/config/#files
#
# Disable media (images, videos, files) download for incoming messages
#- WHATSAPP_DOWNLOAD_MEDIA=false
#
# Download only specific media types
#- WHATSAPP_FILES_MIMETYPES=image/jpeg,image/png
#
# Media - Local Storage
# https://waha.devlike.pro/docs/how-to/storages/#media---local
#
# Set to 0 to keep media files forever
# https://waha.devlike.pro/docs/how-to/storages/#save-media-files-between-the-container-restarts
- WAHA_MEDIA_STORAGE=LOCAL
- WHATSAPP_FILES_LIFETIME=0
- WHATSAPP_FILES_FOLDER=/app/.media
# Keep media files for 180 seconds (3 minutes)
#- WHATSAPP_FILES_LIFETIME=180
#
# Media - S3 Storage
# https://waha.devlike.pro/docs/how-to/storages/#media---s3
#- WAHA_MEDIA_STORAGE=S3
#- WAHA_S3_REGION=eu-west-2
#- WAHA_S3_BUCKET=waha
#- WAHA_S3_ACCESS_KEY_ID=minioadmin
#- WAHA_S3_SECRET_ACCESS_KEY=minioadmin
#- WAHA_S3_ENDPOINT=http://minio:9000 # Not required if you're using AWS S3
#- WAHA_S3_FORCE_PATH_STYLE=True # Required for Minio
#- WAHA_S3_PROXY_FILES=True # Required for docker-compose setup
#
# Global Webhooks
#
# https://waha.devlike.pro/docs/how-to/config/#webhooks
# https://waha.devlike.pro/docs/how-to/webhooks/
#- WHATSAPP_HOOK_URL=https://webhook.site/11111111-1111-1111-1111-11111111
#- WHATSAPP_HOOK_EVENTS=session.status,message,message.reaction
#
#
# MongoDB Configuration
# https://waha.devlike.pro/docs/how-to/storages/#sessions---mongodb
#- WHATSAPP_SESSIONS_MONGO_URL=mongodb://mongodb:27017
#
env_file:
- .env
# NOTE: Only if you're using MongoDB
# https://waha.devlike.pro/docs/how-to/storages/#sessions---mongodb
# Comment this block if you're using MongoDB
mongodb:
image: mongo
container_name: mongodb
ports:
- '27017:27017/tcp'
volumes:
- mongodb_data:/data/db
restart: always
# mongodb:
# image: mongo
# container_name: mongodb
# ports:
# - '127.0.0.1:27017:27017/tcp'
# volumes:
# - mongodb_data:/data/db
# restart: always
# NOTE: Only if you're using S3 to save media files
# https://waha.devlike.pro/docs/how-to/storages/#media---s3
# Comment this block if you're using AWS S3
minio:
image: quay.io/minio/minio
container_name: minio
restart: always
ports:
- '9000:9000'
- '9001:9001'
environment:
MINIO_REGION: 'eu-west-2'
MINIO_ROOT_USER: 'minioadmin'
MINIO_ROOT_PASSWORD: 'minioadmin'
volumes:
- minio_data:/data
command: server /data --console-address ":9001"
# NOTE: Only if you're using S3 to save media files
# https://waha.devlike.pro/docs/how-to/storages/#media---s3
# Comment this block if you're using AWS S3
# minio:
# image: quay.io/minio/minio
# container_name: minio
# restart: always
# ports:
# - '127.0.0.1:9000:9000'
# - '127.0.0.1:9001:9001'
# environment:
# MINIO_REGION: 'eu-west-2'
# MINIO_ROOT_USER: 'minioadmin'
# MINIO_ROOT_PASSWORD: 'minioadmin'
# volumes:
# - minio_data:/data
# command: server /data --console-address ":9001"
volumes:
# NOTE: Only if you're using MongoDB
+1 -1
View File
@@ -8,4 +8,4 @@ uv_threadpool_size=$(($cpus * 2))
export UV_THREADPOOL_SIZE="${UV_THREADPOOL_SIZE:-$uv_threadpool_size}"
# Start your application using yarn
node dist/main
exec node dist/main
+2 -2
View File
@@ -23,7 +23,7 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@adiwajshing/baileys": "github:devlikeapro/Baileys#fork-master-channels-2",
"@adiwajshing/baileys": "github:devlikeapro/Baileys#fork-master-channels-678",
"@adiwajshing/keyed-db": "^0.2.4",
"@aws-sdk/client-s3": "^3.633.0",
"@aws-sdk/s3-request-presigner": "^3.633.0",
@@ -62,7 +62,7 @@
"link-preview-js": "^3.0.4",
"lodash": "^4.17.21",
"mime-types": "^2.1.27",
"mongodb": "^6.3.0",
"mongodb": "6.9.0",
"nestjs-pino": "^4.1.0",
"passport": "^0.6.0",
"passport-headerapikey": "^1.2.2",
+4 -8
View File
@@ -9,14 +9,11 @@ import {
NotFoundException,
Post,
Query,
Res,
StreamableFile,
UseInterceptors,
UsePipes,
} from '@nestjs/common';
import { ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger';
import { WhatsappConfigService } from '@waha/config.service';
import { getApp } from '@waha/main';
import { WAHAValidationPipe } from '@waha/nestjs/pipes/WAHAValidationPipe';
import { WAHAEnvironment } from '@waha/structures/environment.dto';
import {
@@ -25,6 +22,7 @@ import {
StopRequest,
StopResponse,
} from '@waha/structures/server.dto';
import { sleep } from '@waha/utils/promiseTimeout';
import { VERSION } from '@waha/version';
import * as lodash from 'lodash';
@@ -97,16 +95,14 @@ export class ServerController {
setTimeout(() => {
this.logger.log('Force stopping the server');
process.kill(process.pid, 'SIGKILL');
process.exit(0);
}, timeout);
} else {
this.logger.log(`Gracefully stopping the server in ${timeout}ms`);
setTimeout(async () => {
this.logger.log('Gracefully closing the application...');
const app = getApp();
if (app) {
await app.close();
}
this.logger.log('Application closed');
process.kill(process.pid, 'SIGTERM');
await sleep(10_000);
process.exit(0);
}, timeout);
}
+2 -13
View File
@@ -35,21 +35,14 @@ import {
SessionUpdateRequest,
} from '../structures/sessions.dto';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const AsyncLock = require('async-lock');
@ApiSecurity('api_key')
@Controller('api/sessions')
@ApiTags('🖥️ Sessions')
class SessionsController {
private lock: any;
constructor(private manager: SessionManager) {
this.lock = new AsyncLock({ maxPending: Infinity });
}
constructor(private manager: SessionManager) {}
private withLock(name: string, fn: () => any) {
return this.lock.acquire(name, fn);
return this.manager.withLock(name, fn);
}
@Get('/')
@@ -177,10 +170,6 @@ class SessionsController {
@UsePipes(new WAHAValidationPipe())
async stop(@Param('session') name: string): Promise<SessionDTO> {
await this.withLock(name, async () => {
const exists = await this.manager.exists(name);
if (!exists) {
throw new NotFoundException('Session not found');
}
await this.manager.stop(name, false);
});
return await this.manager.getSessionInfo(name);
+14 -1
View File
@@ -24,15 +24,28 @@ import { ISessionConfigRepository } from '../storage/ISessionConfigRepository';
import { WhatsappSession } from './session.abc';
import { WebhookConductor } from './webhooks.abc';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const AsyncLock = require('async-lock');
export abstract class SessionManager implements BeforeApplicationShutdown {
public store: any;
public sessionAuthRepository: ISessionAuthRepository;
public sessionConfigRepository: ISessionConfigRepository;
protected sessionMeRepository: ISessionMeRepository;
public events: EventEmitter;
private lock: any;
WAIT_STATUS_INTERVAL = 500;
WAIT_STATUS_TIMEOUT = 5_000;
protected constructor() {
this.lock = new AsyncLock({ maxPending: Infinity });
}
public withLock(name: string, fn: () => any) {
return this.lock.acquire(name, fn);
}
protected abstract getEngine(engine: WAHAEngine): typeof WhatsappSession;
protected abstract get EngineClass(): typeof WhatsappSession;
@@ -65,7 +78,7 @@ export abstract class SessionManager implements BeforeApplicationShutdown {
abstract getSessions(all: boolean): Promise<SessionInfo[]>;
handleSessionEvent(event: WAHAEvents, session: WhatsappSession) {
protected handleSessionEvent(event: WAHAEvents, session: WhatsappSession) {
return (payload: any) => {
const me = session.getSessionMeInfo();
const data: WAHAWebhook = {
+24 -7
View File
@@ -2,6 +2,7 @@ import makeWASocket, {
Browsers,
Contact,
DisconnectReason,
downloadMediaMessage,
extractMessageContent,
getAggregateVotesInPollMessage,
getContentType,
@@ -19,7 +20,6 @@ import makeWASocket, {
WAMessageContent,
WAMessageKey,
} from '@adiwajshing/baileys';
import { downloadMediaMessage } from '@adiwajshing/baileys';
import { WACallEvent } from '@adiwajshing/baileys/lib/Types/Call';
import { Label as NOWEBLabel } from '@adiwajshing/baileys/lib/Types/Label';
import { LabelAssociationType } from '@adiwajshing/baileys/lib/Types/LabelAssociation';
@@ -163,6 +163,8 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
private msgRetryCounterCache: NodeCache;
protected engineLogger: BaileysLogger;
private authNOWEBStore: any;
get listenConnectionEventsFromTheStart() {
return true;
}
@@ -202,6 +204,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
delay * SECOND,
this.logger,
);
this.authNOWEBStore = null;
}
async start() {
@@ -240,10 +243,13 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
}
async makeSocket(): Promise<any> {
const { state, saveCreds } = await this.authFactory.buildAuth(
this.sessionStore,
this.name,
);
if (!this.authNOWEBStore) {
this.authNOWEBStore = await this.authFactory.buildAuth(
this.sessionStore,
this.name,
);
}
const { state, saveCreds } = this.authNOWEBStore;
const agent = this.makeAgent();
const socketConfig = this.getSocketConfig(agent, state);
const sock = makeWASocket(socketConfig);
@@ -277,6 +283,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
this.logger.error(`Failed to initialize storage or store: ${err}`);
this.status = WAHASessionStatus.FAILED;
this.end();
this.store?.close();
throw err;
});
} else {
@@ -403,10 +410,21 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
async stop() {
this.shouldRestart = false;
this.startDelayedJob.cancel();
this.autoRestartJob.stop();
if (this.authNOWEBStore && this.status == WAHASessionStatus.WORKING) {
this.logger.info('Saving creds before stopping...');
await this.authNOWEBStore.saveCreds().catch((e) => {
this.logger.error('Failed to save creds');
this.logger.error(e, e.stack);
});
this.logger.info('Creds saved');
this.authNOWEBStore = null;
}
this.status = WAHASessionStatus.STOPPED;
this.events.removeAllListeners();
this.startDelayedJob.cancel();
await this.end();
await this.store?.close();
return;
}
@@ -473,7 +491,6 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
// @ts-ignore
this.sock?.ev?.removeAllListeners();
this.sock?.ws?.removeAllListeners();
await this.store?.close();
// wait until connection is not connecting to avoid error:
// "WebSocket was closed before the connection was established"
await waitUntil(async () => !this.sock?.ws?.isConnecting, 1_000, 10_000);
+7 -7
View File
@@ -305,29 +305,29 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
this.logger.info(`Session '${this.name}' is ready!`);
});
this.whatsapp.on(Events.AUTHENTICATED, () => {
this.whatsapp.on(Events.AUTHENTICATED, (args) => {
this.status = WAHASessionStatus.WORKING;
this.qr.save('');
this.logger.info(`Session '${this.name}' has been authenticated!`);
this.logger.info({ args: args }, `Session has been authenticated!`);
});
this.whatsapp.on(Events.AUTHENTICATION_FAILURE, () => {
this.whatsapp.on(Events.AUTHENTICATION_FAILURE, (args) => {
this.status = WAHASessionStatus.FAILED;
this.qr.save('');
this.logger.info(`Session '${this.name}' has been disconnected!`);
this.logger.info({ args: args }, `Session has failed to authenticate!`);
});
this.whatsapp.on(Events.DISCONNECTED, () => {
this.whatsapp.on(Events.DISCONNECTED, (args) => {
this.status = WAHASessionStatus.FAILED;
this.qr.save('');
this.logger.info(`Session '${this.name}' has been disconnected!`);
this.logger.info({ args: args }, `Session has been disconnected!`);
});
this.whatsapp.on(Events.STATE_CHANGED, (state: WAState) => {
const badStates = [WAState.OPENING, WAState.TIMEOUT];
const log = this.logger.child({ state: state, event: 'change_state' });
log.debug('Session engine state changed');
log.info('Session engine state changed');
if (!badStates.includes(state)) {
return;
}
+9 -8
View File
@@ -29,6 +29,13 @@ process.on('unhandledRejection', (reason, promise) => {
// @ts-ignore
logger.error(reason.stack);
});
process.on('SIGINT', () => {
logger.info('SIGINT received');
});
process.on('SIGTERM', () => {
logger.info('SIGTERM received');
});
async function loadModules(): Promise<
[typeof AppModuleCore, typeof SwaggerConfiguratorCore]
@@ -51,18 +58,12 @@ async function loadModules(): Promise<
return [AppModulePlus, SwaggerConfiguratorPlus];
}
let app = undefined;
export function getApp() {
return app;
}
async function bootstrap() {
const version = getWAHAVersion();
logger.info(`WAHA (WhatsApp HTTP API) - Running ${version} version...`);
const [AppModule, SwaggerModule] = await loadModules();
const httpsOptions = AppModule.getHttpsOptions(logger);
app = await NestFactory.create(AppModule, {
const app = await NestFactory.create(AppModule, {
logger: getNestJSLogLevels(),
httpsOptions: httpsOptions,
bufferLogs: true,
@@ -73,7 +74,6 @@ async function bootstrap() {
// https://github.com/iamolegga/nestjs-pino?tab=readme-ov-file#expose-stack-trace-and-error-class-in-err-property
app.useGlobalInterceptors(new LoggerErrorInterceptor());
app.enableShutdownHooks();
app.useGlobalFilters(new AllExceptionsFilter());
app.enableCors();
// Ideally, we should apply it globally.
@@ -90,6 +90,7 @@ async function bootstrap() {
swaggerConfigurator.configure(WAHA_WEBHOOKS);
AppModule.appReady(app, logger);
app.enableShutdownHooks();
const config = app.get(WhatsappConfigService);
await app.listen(config.port);
logger.info(`WhatsApp HTTP API is running on: ${await app.getUrl()}`);
+9 -4
View File
@@ -35,10 +35,15 @@ export class SingleDelayedJobRunner {
this.timeout = setTimeout(() => {
this.logger.debug(`Running job...`);
fn().finally(() => {
this.timeout = null;
this.logger.debug(`Job finished`);
});
fn()
.catch((error) => {
this.logger.error(`Job failed: ${error}`);
this.logger.error(error.stack);
})
.finally(() => {
this.timeout = null;
this.logger.debug(`Job finished`);
});
}, this.timeoutMs);
this.logger.info(`Job scheduled with timeout ${this.timeoutMs} ms`);
return true;
+9 -4
View File
@@ -40,10 +40,15 @@ export class SinglePeriodicJobRunner {
this.isWorking = true;
this.logger.debug('Running job...');
fn().finally(() => {
this.isWorking = false;
this.logger.debug(`Job finished`);
});
fn()
.catch((error) => {
this.logger.error(`Job failed: ${error}`);
this.logger.error(error.stack);
})
.finally(() => {
this.isWorking = false;
this.logger.debug(`Job finished`);
});
}, this.intervalMs);
this.logger.info(`Job started with interval ${this.intervalMs} ms`);
return true;
+1 -1
View File
@@ -33,7 +33,7 @@ export function getEngineName(): string {
}
export const VERSION: WAHAEnvironment = {
version: '2024.10.1',
version: '2024.10.4',
engine: getEngineName(),
tier: getWAHAVersion(),
browser: getBrowserExecutablePath(),
+40 -25
View File
@@ -5,16 +5,16 @@ __metadata:
version: 6
cacheKey: 8
"@adiwajshing/baileys@github:devlikeapro/Baileys#fork-master-channels-2":
version: 6.7.7
resolution: "@adiwajshing/baileys@https://github.com/devlikeapro/Baileys.git#commit=ffc61c22bea5143051ea6704fcf39d8d4bb52892"
"@adiwajshing/baileys@github:devlikeapro/Baileys#fork-master-channels-678":
version: 6.7.8
resolution: "@adiwajshing/baileys@https://github.com/devlikeapro/Baileys.git#commit=d0323b92eb8365e6f32a61e41dd00010602d07f1"
dependencies:
"@adiwajshing/keyed-db": ^0.2.4
"@hapi/boom": ^9.1.3
async-lock: ^1.4.1
audio-decode: ^2.1.3
axios: ^1.6.0
cache-manager: 4.0.1
cache-manager: ^5.7.6
futoin-hkdf: ^1.5.1
libphonenumber-js: ^1.10.20
libsignal: "github:WhiskeySockets/libsignal-node"
@@ -39,7 +39,7 @@ __metadata:
optional: true
sharp:
optional: true
checksum: 7254ddc761ab8235b645ad69ff998240df5636a4cdec97cefb26d7d43721839835d05663d57c95bd013318f9c7378a2a4882721c51a2cc055f9e1a92eaaa696c
checksum: a3b461006443713074401a17c3481aef571301e83f1fba193d06e7f9ea4c47359b5c973d0b3804e34d4e48c35bdc1a64d8c3e59a0a744e5bc9bcca591d180901
languageName: node
linkType: hard
@@ -4132,13 +4132,6 @@ __metadata:
languageName: node
linkType: hard
"async@npm:3.2.3":
version: 3.2.3
resolution: "async@npm:3.2.3"
checksum: c4bee57ab2249af3dc83ca3ef9acfa8e822c0d5e5aa41bae3eaf7f673648343cd64ecd7d26091ffd357f3f044428b17b5f00098494b6cf8b6b3e9681f0636ca1
languageName: node
linkType: hard
"async@npm:>=0.2.9, async@npm:^3.2.4":
version: 3.2.5
resolution: "async@npm:3.2.5"
@@ -4642,14 +4635,15 @@ __metadata:
languageName: node
linkType: hard
"cache-manager@npm:4.0.1":
version: 4.0.1
resolution: "cache-manager@npm:4.0.1"
"cache-manager@npm:^5.7.6":
version: 5.7.6
resolution: "cache-manager@npm:5.7.6"
dependencies:
async: 3.2.3
eventemitter3: ^5.0.1
lodash.clonedeep: ^4.5.0
lru-cache: ^7.10.1
checksum: 8ca25b1e603111f033d1a3f1463b2a9203e9ea61a0706265a4d4f63d54a8be95f9e79efb04fc43103219becb4903a5db747a346e009e7102767a47e5677219b2
lru-cache: ^10.2.2
promise-coalesce: ^1.1.2
checksum: c61d30e2824f99f04af8e14a2e98c2274daa276cce82f64f0ac4c4bd59cf30e1ad9dec4028148206ad729196b242940476602e2f12496366d6f3f4b9da7c24c5
languageName: node
linkType: hard
@@ -6247,6 +6241,13 @@ __metadata:
languageName: node
linkType: hard
"eventemitter3@npm:^5.0.1":
version: 5.0.1
resolution: "eventemitter3@npm:5.0.1"
checksum: 543d6c858ab699303c3c32e0f0f47fc64d360bf73c3daf0ac0b5079710e340d6fe9f15487f94e66c629f5f82cd1a8678d692f3dbb6f6fcd1190e1b97fcad36f8
languageName: node
linkType: hard
"events@npm:^3.2.0, events@npm:^3.3.0":
version: 3.3.0
resolution: "events@npm:3.3.0"
@@ -8581,6 +8582,13 @@ __metadata:
languageName: node
linkType: hard
"lru-cache@npm:^10.2.2":
version: 10.4.3
resolution: "lru-cache@npm:10.4.3"
checksum: 6476138d2125387a6d20f100608c2583d415a4f64a0fecf30c9e2dda976614f09cad4baa0842447bd37dd459a7bd27f57d9d8f8ce558805abd487c583f3d774a
languageName: node
linkType: hard
"lru-cache@npm:^5.1.1":
version: 5.1.1
resolution: "lru-cache@npm:5.1.1"
@@ -8590,7 +8598,7 @@ __metadata:
languageName: node
linkType: hard
"lru-cache@npm:^7.10.1, lru-cache@npm:^7.14.1":
"lru-cache@npm:^7.14.1":
version: 7.18.3
resolution: "lru-cache@npm:7.18.3"
checksum: e550d772384709deea3f141af34b6d4fa392e2e418c1498c078de0ee63670f1f46f5eee746e8ef7e69e1c895af0d4224e62ee33e66a543a14763b0f2e74c1356
@@ -8962,9 +8970,9 @@ __metadata:
languageName: node
linkType: hard
"mongodb@npm:^6.3.0":
version: 6.7.0
resolution: "mongodb@npm:6.7.0"
"mongodb@npm:6.9.0":
version: 6.9.0
resolution: "mongodb@npm:6.9.0"
dependencies:
"@mongodb-js/saslprep": ^1.1.5
bson: ^6.7.0
@@ -8992,7 +9000,7 @@ __metadata:
optional: true
socks:
optional: true
checksum: 11677b416ba2bd8c8835663445b89db7f32faca763c5c3ce6d9de246826b4796ec628c35e84d1dc0b3c11be9623a1ebd6ecdb8eb90a40eededb8bc4fd75e4693
checksum: 754beb9acf605bbb4d55383fd1df1915ec25043f1e6ad0226d34a5d32b85ad822f784cf77d2751592696f5af72b5dc62a01514c4eb5fc0c7c0f495bf5764555a
languageName: node
linkType: hard
@@ -9955,6 +9963,13 @@ __metadata:
languageName: node
linkType: hard
"promise-coalesce@npm:^1.1.2":
version: 1.1.2
resolution: "promise-coalesce@npm:1.1.2"
checksum: 6f951b5db40ca78d09ad0f72adea0a2e9c5bdb0fc5b3ef218c611e2191c6ce2e9f752f815630fd07875dd1c9f04cc7327d6bada04b662dce986ce86ab88c2d5e
languageName: node
linkType: hard
"promise-retry@npm:^2.0.1":
version: 2.0.1
resolution: "promise-retry@npm:2.0.1"
@@ -12141,7 +12156,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "waha@workspace:."
dependencies:
"@adiwajshing/baileys": "github:devlikeapro/Baileys#fork-master-channels-2"
"@adiwajshing/baileys": "github:devlikeapro/Baileys#fork-master-channels-678"
"@adiwajshing/keyed-db": ^0.2.4
"@aws-sdk/client-s3": ^3.633.0
"@aws-sdk/s3-request-presigner": ^3.633.0
@@ -12194,7 +12209,7 @@ __metadata:
link-preview-js: ^3.0.4
lodash: ^4.17.21
mime-types: ^2.1.27
mongodb: ^6.3.0
mongodb: 6.9.0
nestjs-pino: ^4.1.0
passport: ^0.6.0
passport-headerapikey: ^1.2.2