mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: update bot service processMessage method
This commit is contained in:
parent
2a48974336
commit
a11ee925a6
@ -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.');
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user