From 0962c60844ead55de2abe2d9e5142fc2d290d15b Mon Sep 17 00:00:00 2001 From: devlikepro Date: Mon, 12 Aug 2024 10:55:21 +0700 Subject: [PATCH] [core] DELETE /api/sessions/{session}/ --- src/api/sessions.controller.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/api/sessions.controller.ts b/src/api/sessions.controller.ts index a2ed1f04..9a7df0cb 100644 --- a/src/api/sessions.controller.ts +++ b/src/api/sessions.controller.ts @@ -1,6 +1,7 @@ import { Body, Controller, + Delete, Get, NotFoundException, Param, @@ -22,6 +23,7 @@ import { SessionStopDeprecatedRequest, } from '@waha/structures/sessions.deprecated.dto'; import { generatePrefixedId } from '@waha/utils/ids'; +import { sleep } from '@waha/utils/promiseTimeout'; import { SessionManager } from '../core/abc/manager.abc'; import { WhatsappSession } from '../core/abc/session.abc'; @@ -128,6 +130,23 @@ class SessionsController { await this.manager.stop(name, false); return await this.manager.getSessionInfo(name); } + + @Delete(':session/') + @SessionApiParam + @ApiOperation({ + summary: 'Delete the session', + description: + 'Delete the session with the given name. Stop and logout if required. Idempotent operation.', + }) + @UsePipes(new WAHAValidationPipe()) + async delete(@Param('session') name: string): Promise { + if (this.manager.isRunning(name)) { + await this.stop(name); + await sleep(2000); + } + await this.manager.logout(name); + await this.manager.delete(name); + } } @ApiSecurity('api_key')