Skip to content

Commit a8a7edf

Browse files
committed
feat: add the ability to stop the execution of feature after the prehandle method
1 parent 62b6a2d commit a8a7edf

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/feature/assistant-feature.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class AssistantFeature {
136136

137137
preHandle(message, context) {
138138
this.resetTtl();
139+
return true;
139140
}
140141

141142
handle(message, context) {

src/virtual-assistant.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ class VirtualAssistant {
113113

114114
if(featureCacheId && AssistantFeature.getCache().get(featureCacheId)) {
115115
let feature = AssistantFeature.getCache().get(featureCacheId);
116-
feature.preHandle(message, context);
117-
feature.handle(message, context);
116+
let result = feature.preHandle(message, context);
117+
if(result) {
118+
feature.handle(message, context);
119+
}
118120
}
119121
else {
120122
let foundItems = this._getFeatureHandling(message);
@@ -124,8 +126,10 @@ class VirtualAssistant {
124126
let foundFeature = foundItems[0],
125127
featureId = this._getCacheId(foundFeature.getScope(), context.channelId, context.userId);
126128
let newFeature = new foundFeature(fromInterface, context, featureId);
127-
newFeature.preHandle(message, context);
128-
newFeature.handle(message, context);
129+
let result = newFeature.preHandle(message, context);
130+
if(result) {
131+
newFeature.handle(message, context);
132+
}
129133
}
130134
else {
131135
console.error('Multiple features matching text ', message);

0 commit comments

Comments
 (0)