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,
|
subscriberContext: SubscriberContext,
|
||||||
fallback = false,
|
fallback = false,
|
||||||
conversationId?: string,
|
conversationId?: string,
|
||||||
) {
|
): Promise<StdOutgoingEnvelope> {
|
||||||
const settings = await this.settingService.getSettings();
|
const settings = await this.settingService.getSettings();
|
||||||
const blockMessage: BlockMessage =
|
const blockMessage: BlockMessage =
|
||||||
fallback && block.options?.fallback
|
fallback && block.options?.fallback
|
||||||
@ -592,13 +592,18 @@ export class BlockService extends BaseService<
|
|||||||
);
|
);
|
||||||
// Process custom plugin block
|
// Process custom plugin block
|
||||||
try {
|
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) {
|
} catch (e) {
|
||||||
this.logger.error('Plugin was unable to load/process ', e);
|
this.logger.error('Plugin was unable to load/process ', e);
|
||||||
throw new Error(`Unknown plugin - ${JSON.stringify(blockMessage)}`);
|
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,
|
getDefaultConversationContext,
|
||||||
} from '../schemas/conversation.schema';
|
} from '../schemas/conversation.schema';
|
||||||
import { Context } from '../schemas/types/context';
|
import { Context } from '../schemas/types/context';
|
||||||
import {
|
import { IncomingMessageType } from '../schemas/types/message';
|
||||||
IncomingMessageType,
|
|
||||||
StdOutgoingEnvelope,
|
|
||||||
} from '../schemas/types/message';
|
|
||||||
import { SubscriberContext } from '../schemas/types/subscriberContext';
|
import { SubscriberContext } from '../schemas/types/subscriberContext';
|
||||||
|
|
||||||
import { BlockService } from './block.service';
|
import { BlockService } from './block.service';
|
||||||
@ -71,13 +68,13 @@ export class BotService {
|
|||||||
);
|
);
|
||||||
// Process message : Replace tokens with context data and then send the message
|
// Process message : Replace tokens with context data and then send the message
|
||||||
const recipient = event.getSender();
|
const recipient = event.getSender();
|
||||||
const envelope = (await this.blockService.processMessage(
|
const envelope = await this.blockService.processMessage(
|
||||||
block,
|
block,
|
||||||
context,
|
context,
|
||||||
recipient?.context as SubscriberContext,
|
recipient?.context as SubscriberContext,
|
||||||
fallback,
|
fallback,
|
||||||
conservationId,
|
conservationId,
|
||||||
)) as StdOutgoingEnvelope;
|
);
|
||||||
// Send message through the right channel
|
// Send message through the right channel
|
||||||
|
|
||||||
const response = await event
|
const response = await event
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user