1 parent
1431e8c0f1
commit
2fc2caed85
5 files changed
+52
-24
No files matched your search
@@ -34,19 +34,26 @@ import { isJidBroadcast, isJidGroup, toCusFormat } from '@waha/core/utils/jids';
|
||||
import { EngineHelper } from '@waha/apps/chatwoot/waha';
|
||||
import { EnsureSeconds } from '@waha/utils/timehelper';
|
||||
import { CHATWOOT_MESSAGE_CALENDAR_THRESHOLD_SECONDS } from '@waha/apps/chatwoot/env';
|
||||
import {
|
||||
ChatWootAppConfig,
|
||||
ChatWootConfig,
|
||||
} from '@waha/apps/chatwoot/dto/config.dto';
|
||||
|
||||
export function ListenEventsForChatWoot() {
|
||||
return [
|
||||
export function ListenEventsForChatWoot(config: ChatWootConfig) {
|
||||
const events = [
|
||||
WAHAEvents.MESSAGE_ANY,
|
||||
WAHAEvents.MESSAGE_REACTION,
|
||||
WAHAEvents.MESSAGE_EDITED,
|
||||
WAHAEvents.MESSAGE_REVOKED,
|
||||
WAHAEvents.MESSAGE_ACK,
|
||||
WAHAEvents.SESSION_STATUS,
|
||||
WAHAEvents.CALL_RECEIVED,
|
||||
WAHAEvents.CALL_ACCEPTED,
|
||||
WAHAEvents.CALL_REJECTED,
|
||||
];
|
||||
if (config.conversations.markAsRead) {
|
||||
events.push(WAHAEvents.MESSAGE_ACK);
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -207,18 +207,28 @@ export class DIContainer {
|
||||
|
||||
@CacheSync()
|
||||
public ChatWootConfig(): ChatWootConfig {
|
||||
const defaults: ChatWootConfig = {
|
||||
templates: {},
|
||||
linkPreview: LinkPreview.OFF,
|
||||
commands: {
|
||||
server: true,
|
||||
queue: false,
|
||||
},
|
||||
conversations: {
|
||||
sort: ConversationSort.created_newest,
|
||||
status: null,
|
||||
},
|
||||
};
|
||||
return lodash.defaults({}, this.config, defaults);
|
||||
return ChatWootConfigDefaults(this.config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies default values to the ChatWoot configuration
|
||||
*/
|
||||
export function ChatWootConfigDefaults(
|
||||
config: ChatWootAppConfig,
|
||||
): ChatWootConfig {
|
||||
const defaults: ChatWootConfig = {
|
||||
templates: {},
|
||||
linkPreview: LinkPreview.OFF,
|
||||
commands: {
|
||||
server: true,
|
||||
queue: false,
|
||||
},
|
||||
conversations: {
|
||||
sort: ConversationSort.created_newest,
|
||||
status: null,
|
||||
markAsRead: true,
|
||||
},
|
||||
};
|
||||
return lodash.defaultsDeep({}, config, defaults);
|
||||
}
|
||||
@@ -7,12 +7,10 @@ import {
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsDynamicObject } from '@waha/nestjs/validation/IsDynamicObject';
|
||||
import {
|
||||
ConversationSelectorConfig,
|
||||
ConversationSort,
|
||||
} from '@waha/apps/chatwoot/services/ConversationSelector';
|
||||
import { ConversationSort } from '@waha/apps/chatwoot/services/ConversationSelector';
|
||||
import { ConversationStatus } from '@waha/apps/chatwoot/client/types';
|
||||
|
||||
export const DEFAULT_LOCALE = 'en-US';
|
||||
@@ -39,6 +37,15 @@ export class ChatWootConversationsConfig {
|
||||
@IsOptional()
|
||||
@IsEnum(ConversationStatus, { each: true })
|
||||
status: Array<ConversationStatus> | null;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description:
|
||||
'Process message.ack events to mark ChatWoot conversations as read. Enabled by default.',
|
||||
default: true,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
markAsRead?: boolean = true;
|
||||
}
|
||||
|
||||
export interface ChatWootConfig {
|
||||
|
||||
@@ -120,7 +120,7 @@ export class ChatWootAppService implements IAppService {
|
||||
}
|
||||
|
||||
beforeSessionStart(app: App<ChatWootAppConfig>, session: WhatsappSession) {
|
||||
this.chatWootWAHAQueueService.listenEvents(app.id, session);
|
||||
this.chatWootWAHAQueueService.listenEvents(app, session);
|
||||
}
|
||||
|
||||
afterSessionStart(app: App<ChatWootAppConfig>, session: WhatsappSession) {
|
||||
|
||||
@@ -7,6 +7,9 @@ import { Queue } from 'bullmq';
|
||||
|
||||
import { QueueName } from '../consumers/QueueName';
|
||||
import { QueueRegistry } from './QueueRegistry';
|
||||
import { App } from '@waha/apps/app_sdk/dto/app.dto';
|
||||
import { ChatWootAppConfig } from '@waha/apps/chatwoot/dto/config.dto';
|
||||
import { ChatWootConfigDefaults } from '@waha/apps/chatwoot/di/DIContainer';
|
||||
|
||||
/**
|
||||
* Service for managing ChatWoot queues for WAHA events
|
||||
@@ -63,13 +66,14 @@ export class ChatWootWAHAQueueService {
|
||||
/**
|
||||
* Configure ChatWoot event handling for a session
|
||||
*/
|
||||
listenEvents(appId: string, session: WhatsappSession): void {
|
||||
const events = ListenEventsForChatWoot();
|
||||
listenEvents(app: App<ChatWootAppConfig>, session: WhatsappSession): void {
|
||||
const config = ChatWootConfigDefaults(app.config);
|
||||
const events = ListenEventsForChatWoot(config);
|
||||
for (const event of events) {
|
||||
const obs$ = session.getEventObservable(event);
|
||||
obs$.subscribe(async (payload) => {
|
||||
const data = populateSessionInfo(event, session)(payload);
|
||||
await this.addJobToQueue(event, data, appId);
|
||||
await this.addJobToQueue(event, data, app.id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user