lisichatbot 1.5.6 → 1.5.8
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 +137 -11
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1975,18 +1975,82 @@ async function handleNext() {
|
|
|
1975
1975
|
if (currentStep.onNext) {
|
|
1976
1976
|
try {
|
|
1977
1977
|
disableNextButton();
|
|
1978
|
+
|
|
1979
|
+
// ✅ NEW: Create showMessage helper function
|
|
1980
|
+
const showMessage = (message) => {
|
|
1981
|
+
console.log('💬 showMessage called:', message);
|
|
1982
|
+
addMessage(message, 'bot', false, null);
|
|
1983
|
+
scrollToBottom();
|
|
1984
|
+
};
|
|
1985
|
+
|
|
1986
|
+
// ✅ Pass showMessage as third parameter
|
|
1978
1987
|
const result = await currentStep.onNext(
|
|
1979
1988
|
chatState.currentSelection ? chatState.currentSelection.value : null,
|
|
1980
|
-
chatState.data
|
|
1989
|
+
chatState.data,
|
|
1990
|
+
showMessage // ✅ NEW: Third parameter
|
|
1981
1991
|
);
|
|
1982
1992
|
|
|
1983
|
-
// ✅
|
|
1993
|
+
// ✅ Still support showMessage in return object for backwards compatibility
|
|
1984
1994
|
if (result && typeof result === 'object' && result.showMessage) {
|
|
1985
|
-
console.log('💬 onNext displaying message:', result.showMessage);
|
|
1995
|
+
console.log('💬 onNext displaying message from return:', result.showMessage);
|
|
1986
1996
|
addMessage(result.showMessage, 'bot', false, null);
|
|
1987
1997
|
scrollToBottom();
|
|
1988
1998
|
}
|
|
1989
1999
|
|
|
2000
|
+
// ✅ NEW: Check if onNext wants to update steps by field name
|
|
2001
|
+
if (result && typeof result === 'object' && result.updateStepByField) {
|
|
2002
|
+
console.log('🎯 onNext returned data to update steps by field name:', result.updateStepByField);
|
|
2003
|
+
|
|
2004
|
+
// Iterate through all field updates
|
|
2005
|
+
Object.keys(result.updateStepByField).forEach(fieldName => {
|
|
2006
|
+
const updates = result.updateStepByField[fieldName];
|
|
2007
|
+
|
|
2008
|
+
// Find the step with this field name
|
|
2009
|
+
const targetStepIndex = flowData.flow.findIndex(step =>
|
|
2010
|
+
step.input && step.input.field === fieldName
|
|
2011
|
+
);
|
|
2012
|
+
|
|
2013
|
+
if (targetStepIndex !== -1) {
|
|
2014
|
+
const targetStep = flowData.flow[targetStepIndex];
|
|
2015
|
+
console.log(` ✅ Found step ${targetStepIndex} with field "${fieldName}"`);
|
|
2016
|
+
|
|
2017
|
+
// Update the step's input properties
|
|
2018
|
+
if (updates.options !== undefined) {
|
|
2019
|
+
targetStep.input.options = updates.options;
|
|
2020
|
+
console.log(` → Updated options (${updates.options.length} items)`);
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
if (updates.min !== undefined) {
|
|
2024
|
+
targetStep.input.min = updates.min;
|
|
2025
|
+
console.log(` → Updated min: ${updates.min}`);
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
if (updates.max !== undefined) {
|
|
2029
|
+
targetStep.input.max = updates.max;
|
|
2030
|
+
console.log(` → Updated max: ${updates.max}`);
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
if (updates.selectedInputValueType !== undefined) {
|
|
2034
|
+
targetStep.input.selectedInputValueType = updates.selectedInputValueType;
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
if (updates.selectedInputPrefix !== undefined) {
|
|
2038
|
+
targetStep.input.selectedInputPrefix = updates.selectedInputPrefix;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
if (updates.selectedInputSuffix !== undefined) {
|
|
2042
|
+
targetStep.input.selectedInputSuffix = updates.selectedInputSuffix;
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
if (updates.custom !== undefined) {
|
|
2046
|
+
targetStep.input.custom = updates.custom;
|
|
2047
|
+
}
|
|
2048
|
+
} else {
|
|
2049
|
+
console.warn(` ⚠️ No step found with field name "${fieldName}"`);
|
|
2050
|
+
}
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
|
|
1990
2054
|
// ✅ NEW: Check if onNext wants to jump to a specific step
|
|
1991
2055
|
if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
|
|
1992
2056
|
console.log(`🎯 onNext requested jump to step ${result.goToStep}`);
|
|
@@ -2263,7 +2327,76 @@ async function showNextStep() {
|
|
|
2263
2327
|
|
|
2264
2328
|
if (nextStep.onStart) {
|
|
2265
2329
|
try {
|
|
2266
|
-
|
|
2330
|
+
// ✅ NEW: Create showMessage helper function
|
|
2331
|
+
const showMessage = (message) => {
|
|
2332
|
+
console.log('💬 showMessage called:', message);
|
|
2333
|
+
addMessage(message, 'bot', false, null);
|
|
2334
|
+
scrollToBottom();
|
|
2335
|
+
};
|
|
2336
|
+
|
|
2337
|
+
// ✅ Pass showMessage as second parameter
|
|
2338
|
+
const result = await nextStep.onStart(chatState.data, showMessage);
|
|
2339
|
+
|
|
2340
|
+
// ✅ Still support showMessage in return object for backwards compatibility
|
|
2341
|
+
if (result && typeof result === 'object' && result.showMessage) {
|
|
2342
|
+
console.log('💬 onStart displaying message from return:', result.showMessage);
|
|
2343
|
+
addMessage(result.showMessage, 'bot', false, null);
|
|
2344
|
+
scrollToBottom();
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
// ✅ NEW: Check if onStart wants to update steps by field name
|
|
2348
|
+
if (result && typeof result === 'object' && result.updateStepByField) {
|
|
2349
|
+
console.log('🎯 onStart returned data to update steps by field name:', result.updateStepByField);
|
|
2350
|
+
|
|
2351
|
+
// Iterate through all field updates
|
|
2352
|
+
Object.keys(result.updateStepByField).forEach(fieldName => {
|
|
2353
|
+
const updates = result.updateStepByField[fieldName];
|
|
2354
|
+
|
|
2355
|
+
// Find the step with this field name
|
|
2356
|
+
const targetStepIndex = flowData.flow.findIndex(step =>
|
|
2357
|
+
step.input && step.input.field === fieldName
|
|
2358
|
+
);
|
|
2359
|
+
|
|
2360
|
+
if (targetStepIndex !== -1) {
|
|
2361
|
+
const targetStep = flowData.flow[targetStepIndex];
|
|
2362
|
+
console.log(` ✅ Found step ${targetStepIndex} with field "${fieldName}"`);
|
|
2363
|
+
|
|
2364
|
+
// Update the step's input properties
|
|
2365
|
+
if (updates.options !== undefined) {
|
|
2366
|
+
targetStep.input.options = updates.options;
|
|
2367
|
+
console.log(` → Updated options (${updates.options.length} items)`);
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
if (updates.min !== undefined) {
|
|
2371
|
+
targetStep.input.min = updates.min;
|
|
2372
|
+
console.log(` → Updated min: ${updates.min}`);
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
if (updates.max !== undefined) {
|
|
2376
|
+
targetStep.input.max = updates.max;
|
|
2377
|
+
console.log(` → Updated max: ${updates.max}`);
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
if (updates.selectedInputValueType !== undefined) {
|
|
2381
|
+
targetStep.input.selectedInputValueType = updates.selectedInputValueType;
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
if (updates.selectedInputPrefix !== undefined) {
|
|
2385
|
+
targetStep.input.selectedInputPrefix = updates.selectedInputPrefix;
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
if (updates.selectedInputSuffix !== undefined) {
|
|
2389
|
+
targetStep.input.selectedInputSuffix = updates.selectedInputSuffix;
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
if (updates.custom !== undefined) {
|
|
2393
|
+
targetStep.input.custom = updates.custom;
|
|
2394
|
+
}
|
|
2395
|
+
} else {
|
|
2396
|
+
console.warn(` ⚠️ No step found with field name "${fieldName}"`);
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2267
2400
|
|
|
2268
2401
|
// ✅ NEW: Check if onStart returned data to update current step
|
|
2269
2402
|
if (result && typeof result === 'object' && result.updateCurrentStep) {
|
|
@@ -2359,13 +2492,6 @@ async function showNextStep() {
|
|
|
2359
2492
|
}
|
|
2360
2493
|
}
|
|
2361
2494
|
|
|
2362
|
-
// ✅ NEW: Check if onStart wants to display a message in chat
|
|
2363
|
-
if (result && typeof result === 'object' && result.showMessage) {
|
|
2364
|
-
console.log('💬 onStart displaying message:', result.showMessage);
|
|
2365
|
-
addMessage(result.showMessage, 'bot', false, null);
|
|
2366
|
-
scrollToBottom();
|
|
2367
|
-
}
|
|
2368
|
-
|
|
2369
2495
|
// ✅ NEW: Check if onStart wants to jump to a specific step
|
|
2370
2496
|
if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
|
|
2371
2497
|
console.log(`🎯 onStart requested jump to step ${result.goToStep}`);
|