lisichatbot 1.5.0 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +65 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
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,12 +2300,44 @@ async function showNextStep() {
2283
2300
  scrollToBottom();
2284
2301
  }
2285
2302
 
2286
- // Check if onStart blocked the step
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
+
2320
+ // ✅ NEW: Check if onStart wants to block this step and skip to next
2321
+ if (result && typeof result === 'object' && result.blockStep === true) {
2322
+ console.log('⏭️ Step blocked by onStart - skipping to next step');
2323
+ chatState.step++;
2324
+
2325
+ if (chatState.step >= flowData.flow.length) {
2326
+ handleCompletion();
2327
+ return;
2328
+ }
2329
+
2330
+ // Recursively show next step
2331
+ await showNextStep();
2332
+ return;
2333
+ }
2334
+
2335
+ // Check if onStart blocked the step (old behavior - stops flow)
2287
2336
  const canStart = result === undefined || result === true ||
2288
2337
  (typeof result === 'object' && result.canStart !== false);
2289
2338
 
2290
2339
  if (!canStart) {
2291
- console.log('Step blocked by onStart');
2340
+ console.log('Step blocked by onStart - flow stopped');
2292
2341
  return;
2293
2342
  }
2294
2343
  } catch (error) {
@@ -2721,10 +2770,23 @@ if (typeof document !== 'undefined') {
2721
2770
  // EXPORTS
2722
2771
  // =============================================================================
2723
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
+
2724
2785
  module.exports = {
2725
2786
  init,
2726
2787
  getState,
2727
2788
  reset,
2728
2789
  goToStep,
2729
- editStep
2790
+ editStep,
2791
+ displayMessage // ✅ NEW: Export helper function
2730
2792
  };