lisichatbot 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +48 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1895,6 +1895,23 @@ async function handleNext() {
|
|
|
1895
1895
|
scrollToBottom();
|
|
1896
1896
|
}
|
|
1897
1897
|
|
|
1898
|
+
// ✅ NEW: Check if onNext wants to jump to a specific step
|
|
1899
|
+
if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
|
|
1900
|
+
console.log(`🎯 onNext requested jump to step ${result.goToStep}`);
|
|
1901
|
+
|
|
1902
|
+
const targetStep = result.goToStep;
|
|
1903
|
+
|
|
1904
|
+
if (targetStep >= 0 && targetStep < flowData.flow.length) {
|
|
1905
|
+
chatState.step = targetStep;
|
|
1906
|
+
chatState.currentSelection = null;
|
|
1907
|
+
disableNextButton();
|
|
1908
|
+
await showNextStep();
|
|
1909
|
+
return;
|
|
1910
|
+
} else {
|
|
1911
|
+
console.error(`Invalid step number: ${targetStep}`);
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1898
1915
|
// ✅ NEW: Check if onNext returned data to update next step
|
|
1899
1916
|
if (result && typeof result === 'object' && result.updateNextStep) {
|
|
1900
1917
|
console.log('📝 onNext returned data to update next step:', result);
|
|
@@ -2283,6 +2300,23 @@ async function showNextStep() {
|
|
|
2283
2300
|
scrollToBottom();
|
|
2284
2301
|
}
|
|
2285
2302
|
|
|
2303
|
+
// ✅ NEW: Check if onStart wants to jump to a specific step
|
|
2304
|
+
if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
|
|
2305
|
+
console.log(`🎯 onStart requested jump to step ${result.goToStep}`);
|
|
2306
|
+
|
|
2307
|
+
const targetStep = result.goToStep;
|
|
2308
|
+
|
|
2309
|
+
if (targetStep >= 0 && targetStep < flowData.flow.length) {
|
|
2310
|
+
chatState.step = targetStep;
|
|
2311
|
+
chatState.currentSelection = null;
|
|
2312
|
+
disableNextButton();
|
|
2313
|
+
await showNextStep();
|
|
2314
|
+
return;
|
|
2315
|
+
} else {
|
|
2316
|
+
console.error(`Invalid step number: ${targetStep}`);
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2286
2320
|
// ✅ NEW: Check if onStart wants to block this step and skip to next
|
|
2287
2321
|
if (result && typeof result === 'object' && result.blockStep === true) {
|
|
2288
2322
|
console.log('⏭️ Step blocked by onStart - skipping to next step');
|
|
@@ -2736,10 +2770,23 @@ if (typeof document !== 'undefined') {
|
|
|
2736
2770
|
// EXPORTS
|
|
2737
2771
|
// =============================================================================
|
|
2738
2772
|
|
|
2773
|
+
// ✅ NEW: Helper function to display messages in chat from callbacks
|
|
2774
|
+
function displayMessage(message) {
|
|
2775
|
+
if (!elements.messages) {
|
|
2776
|
+
console.error('Cannot display message - chat not initialized');
|
|
2777
|
+
return;
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2780
|
+
addMessage(message, 'bot', false, null);
|
|
2781
|
+
scrollToBottom();
|
|
2782
|
+
console.log('💬 Message displayed:', message);
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2739
2785
|
module.exports = {
|
|
2740
2786
|
init,
|
|
2741
2787
|
getState,
|
|
2742
2788
|
reset,
|
|
2743
2789
|
goToStep,
|
|
2744
|
-
editStep
|
|
2790
|
+
editStep,
|
|
2791
|
+
displayMessage // ✅ NEW: Export helper function
|
|
2745
2792
|
};
|