lisichatbot 1.5.8 → 1.5.9

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 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.5.8",
3
+ "version": "1.5.9",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -2051,6 +2051,25 @@ async function handleNext() {
2051
2051
  });
2052
2052
  }
2053
2053
 
2054
+ // ✅ NEW: Check if onNext wants to jump to step by name
2055
+ if (result && typeof result === 'object' && result.goToStepName) {
2056
+ console.log(`🎯 onNext requested jump to step name: "${result.goToStepName}"`);
2057
+
2058
+ const stepName = result.goToStepName;
2059
+ const targetStepIndex = flowData.flow.findIndex(step => step.name === stepName);
2060
+
2061
+ if (targetStepIndex !== -1) {
2062
+ console.log(` ✅ Found step "${stepName}" at index ${targetStepIndex}`);
2063
+ chatState.step = targetStepIndex;
2064
+ chatState.currentSelection = null;
2065
+ disableNextButton();
2066
+ await showNextStep();
2067
+ return;
2068
+ } else {
2069
+ console.error(`❌ No step found with name: "${stepName}"`);
2070
+ }
2071
+ }
2072
+
2054
2073
  // ✅ NEW: Check if onNext wants to jump to a specific step
2055
2074
  if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
2056
2075
  console.log(`🎯 onNext requested jump to step ${result.goToStep}`);
@@ -2492,6 +2511,25 @@ async function showNextStep() {
2492
2511
  }
2493
2512
  }
2494
2513
 
2514
+ // ✅ NEW: Check if onStart wants to jump to step by name
2515
+ if (result && typeof result === 'object' && result.goToStepName) {
2516
+ console.log(`🎯 onStart requested jump to step name: "${result.goToStepName}"`);
2517
+
2518
+ const stepName = result.goToStepName;
2519
+ const targetStepIndex = flowData.flow.findIndex(step => step.name === stepName);
2520
+
2521
+ if (targetStepIndex !== -1) {
2522
+ console.log(` ✅ Found step "${stepName}" at index ${targetStepIndex}`);
2523
+ chatState.step = targetStepIndex;
2524
+ chatState.currentSelection = null;
2525
+ disableNextButton();
2526
+ await showNextStep();
2527
+ return;
2528
+ } else {
2529
+ console.error(`❌ No step found with name: "${stepName}"`);
2530
+ }
2531
+ }
2532
+
2495
2533
  // ✅ NEW: Check if onStart wants to jump to a specific step
2496
2534
  if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
2497
2535
  console.log(`🎯 onStart requested jump to step ${result.goToStep}`);
@@ -2549,7 +2587,33 @@ async function showNextStep() {
2549
2587
  });
2550
2588
 
2551
2589
  const hasInput = !!nextStep.input;
2552
- addMessage(nextStep.message, 'bot', hasInput, chatState.step);
2590
+
2591
+ // ✅ NEW: Support dynamic messages
2592
+ let messageToDisplay = nextStep.message;
2593
+
2594
+ if (typeof nextStep.message === 'function') {
2595
+ // ✅ Message as function: message: (data) => `Hello ${data.name}`
2596
+ try {
2597
+ messageToDisplay = nextStep.message(chatState.data);
2598
+ console.log(` 💬 Dynamic message (function): "${messageToDisplay}"`);
2599
+ } catch (error) {
2600
+ console.error('Error in message function:', error);
2601
+ messageToDisplay = 'Error loading message';
2602
+ }
2603
+ } else if (typeof nextStep.message === 'string' && nextStep.message.includes('${')) {
2604
+ // ✅ Message with template variables: message: "Hello ${name}"
2605
+ try {
2606
+ // Create function from template string
2607
+ const templateFunc = new Function('data', `return \`${nextStep.message}\`;`);
2608
+ messageToDisplay = templateFunc(chatState.data);
2609
+ console.log(` 💬 Dynamic message (template): "${messageToDisplay}"`);
2610
+ } catch (error) {
2611
+ console.error('Error parsing template message:', error);
2612
+ messageToDisplay = nextStep.message; // Fallback to original
2613
+ }
2614
+ }
2615
+
2616
+ addMessage(messageToDisplay, 'bot', hasInput, chatState.step);
2553
2617
 
2554
2618
  const inputRequired = nextStep.inputRequired === true;
2555
2619