Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): execute fallback message when no Global Fallback #552

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/chat/repositories/block.repository.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
Expand Down
3 changes: 1 addition & 2 deletions api/src/chat/repositories/block.repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
Expand Down Expand Up @@ -95,7 +95,6 @@ export class BlockRepository extends BaseRepository<
| UpdateQuery<Document<Block, any, any>>,
): Promise<void> {
const update: BlockUpdateDto = updates?.['$set'];

if (update?.category) {
const movedBlock: Block = await this.findOne(criteria);

Expand Down
22 changes: 19 additions & 3 deletions api/src/chat/services/bot.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
Expand Down Expand Up @@ -454,7 +454,8 @@ export class BotService {
this.logger.debug('No message blocks available!');
if (
settings.chatbot_settings &&
settings.chatbot_settings.global_fallback
settings.chatbot_settings.global_fallback &&
settings.chatbot_settings.fallback_block
) {
this.eventEmitter.emit('hook:analytics:fallback-global', event);
this.logger.debug('Sending global fallback message ...');
Expand Down Expand Up @@ -485,7 +486,22 @@ export class BotService {
} as any as BlockFull);
}
}
// Do nothing ...
this.sendMessageToSubscriber(event, {
id: 'global-fallback',
name: 'Global Fallback',
message: settings.chatbot_settings.fallback_message,
options: {},
patterns: [],
assign_labels: [],
starts_conversation: false,
position: { x: 0, y: 0 },
capture_vars: [],
builtin: true,
createdAt: new Date(),
updatedAt: new Date(),
attachedBlock: null,
} as any as BlockFull);

Comment on lines +489 to +504
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on this implementation! I think it would be even better if you could refactor the code to avoid duplication in the catch block. By using a finally statement to send the message to the subscriber instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm not sure where to include the finally statement but I noticed that if we remove the sendMessageToSubscriber from the catch block it works because if there is an error, the catch block doesn't return anything to close the function.

return;
}

Expand Down