1 parent
51ba5e3266
commit
28da9c34bb
7 files changed
+33
-12
No files matched your search
@@ -44,4 +44,8 @@ export class AppsDisabledService implements IAppsService {
|
||||
async beforeSessionStart(session: WhatsappSession, store: DataStore) {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterSessionStart(session: WhatsappSession, store: DataStore) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,17 @@ export class AppsEnabledService implements IAppsService {
|
||||
const apps = await repo.getEnabledBySession(session.name);
|
||||
for (const app of apps) {
|
||||
const service = this.getAppService(app);
|
||||
await service.beforeSessionStart(app, session);
|
||||
service.beforeSessionStart(app, session);
|
||||
}
|
||||
}
|
||||
|
||||
async afterSessionStart(session: WhatsappSession, store: DataStore) {
|
||||
const knex = store.getWAHADatabase();
|
||||
const repo = new AppRepository(knex);
|
||||
const apps = await repo.getEnabledBySession(session.name);
|
||||
for (const app of apps) {
|
||||
const service = this.getAppService(app);
|
||||
service.afterSessionStart(app, session);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,5 +23,7 @@ export interface IAppService {
|
||||
|
||||
beforeDeleted(app: App): Promise<void>;
|
||||
|
||||
beforeSessionStart(app: App, session: WhatsappSession): Promise<void>;
|
||||
beforeSessionStart(app: App, session: WhatsappSession): void;
|
||||
|
||||
afterSessionStart(app: App, session: WhatsappSession): void;
|
||||
}
|
||||
@@ -17,6 +17,8 @@ export interface IAppsService {
|
||||
|
||||
beforeSessionStart(session: WhatsappSession, store: DataStore): Promise<void>;
|
||||
|
||||
afterSessionStart(session: WhatsappSession, store: DataStore): Promise<void>;
|
||||
|
||||
migrate(knex: Knex): Promise<void>;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,12 +119,15 @@ export class ChatWootAppService implements IAppService {
|
||||
await conversation.incoming(updated);
|
||||
}
|
||||
|
||||
async beforeSessionStart(
|
||||
app: App<ChatWootAppConfig>,
|
||||
session: WhatsappSession,
|
||||
) {
|
||||
beforeSessionStart(app: App<ChatWootAppConfig>, session: WhatsappSession) {
|
||||
this.chatWootWAHAQueueService.listenEvents(app.id, session);
|
||||
await this.chatWootScheduleService.schedule(app.id, session.name);
|
||||
}
|
||||
|
||||
afterSessionStart(app: App<ChatWootAppConfig>, session: WhatsappSession) {
|
||||
this.chatWootScheduleService.schedule(app.id, session.name).catch((err) => {
|
||||
this.logger.error('Error scheduling session for ChatWoot');
|
||||
this.logger.error(err, err.stack);
|
||||
});
|
||||
}
|
||||
|
||||
private async setupCustomAttributes(app: App<ChatWootAppConfig>) {
|
||||
|
||||
@@ -104,10 +104,6 @@ export abstract class SessionManager
|
||||
);
|
||||
}
|
||||
|
||||
async configureApps(session: WhatsappSession) {
|
||||
await this.appsService.beforeSessionStart(session, this.store);
|
||||
}
|
||||
|
||||
//
|
||||
// API Methods
|
||||
//
|
||||
|
||||
@@ -218,11 +218,15 @@ export class SessionManagerCore extends SessionManager implements OnModuleInit {
|
||||
webhook.configure(session, webhooks);
|
||||
|
||||
// Apps
|
||||
await this.configureApps(session);
|
||||
await this.appsService.beforeSessionStart(session, this.store);
|
||||
|
||||
// start session
|
||||
await session.start();
|
||||
logger.info('Session has been started.');
|
||||
|
||||
// Apps
|
||||
await this.appsService.afterSessionStart(session, this.store);
|
||||
|
||||
return {
|
||||
name: session.name,
|
||||
status: session.status,
|
||||
|
||||
Reference in new issue
Block a user