fix: update bot service processMessage method

This commit is contained in:
yassinedorbozgithub 2025-01-15 09:15:45 +01:00
parent 2a48974336
commit a11ee925a6
2 changed files with 12 additions and 10 deletions

View File

@ -440,7 +440,7 @@ export class BlockService extends BaseService<
subscriberContext: SubscriberContext,
fallback = false,
conversationId?: string,
) {
): Promise<StdOutgoingEnvelope> {
const settings = await this.settingService.getSettings();
const blockMessage: BlockMessage =
fallback && block.options?.fallback
@ -592,13 +592,18 @@ export class BlockService extends BaseService<
);
// Process custom plugin block
try {
return await plugin?.process(block, context, conversationId);
const envelope = await plugin?.process(block, context, conversationId);
if (!envelope) {
throw new Error('Unable to find envelope');
}
return envelope;
} catch (e) {
this.logger.error('Plugin was unable to load/process ', e);
throw new Error(`Unknown plugin - ${JSON.stringify(blockMessage)}`);
}
} else {
throw new Error('Invalid message format.');
}
throw new Error('Invalid message format.');
}
}

View File

@ -21,10 +21,7 @@ import {
getDefaultConversationContext,
} from '../schemas/conversation.schema';
import { Context } from '../schemas/types/context';
import {
IncomingMessageType,
StdOutgoingEnvelope,
} from '../schemas/types/message';
import { IncomingMessageType } from '../schemas/types/message';
import { SubscriberContext } from '../schemas/types/subscriberContext';
import { BlockService } from './block.service';
@ -71,13 +68,13 @@ export class BotService {
);
// Process message : Replace tokens with context data and then send the message
const recipient = event.getSender();
const envelope = (await this.blockService.processMessage(
const envelope = await this.blockService.processMessage(
block,
context,
recipient?.context as SubscriberContext,
fallback,
conservationId,
)) as StdOutgoingEnvelope;
);
// Send message through the right channel
const response = await event