Skip to content

Commit 04ff415

Browse files
committed
fix: resolve auto-send race condition, refresh spam, and lead capture bypass
1 parent 3673d73 commit 04ff415

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

dist/components/Bot.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Bot.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,13 @@ export const Bot = (botProps: BotProps & { class?: string }) => {
556556
let ttsTimeoutRef: ReturnType<typeof setTimeout> | null = null;
557557
let hasAutoSentInitialMessage = false;
558558

559+
createEffect(() => {
560+
// Reset the auto-send flag when the chatflow ID changes (for SPA routing)
561+
props.chatflowid;
562+
hasAutoSentInitialMessage = false;
563+
});
564+
565+
559566
createMemo(() => {
560567
const customerId = (props.chatflowConfig?.vars as any)?.customerId;
561568
setChatId(customerId ? `${customerId.toString()}+${uuidv4()}` : uuidv4());
@@ -1630,14 +1637,14 @@ export const Bot = (botProps: BotProps & { class?: string }) => {
16301637
}
16311638
}
16321639
setIsTTSEnabled(!!chatbotConfig.isTTSEnabled);
1633-
}
1634-
1635-
// Auto-send initial message after config is fully loaded
1636-
const leadCaptureRequired = leadsConfig()?.status && !getLocalStorageChatflow(props.chatflowid)?.lead;
1637-
if (props.autoSendInitialMessage && !hasAutoSentInitialMessage && !leadCaptureRequired) {
1638-
hasAutoSentInitialMessage = true;
1639-
setUserInput(props.autoSendInitialMessage);
1640-
handleSubmit(props.autoSendInitialMessage);
1640+
1641+
// Auto-send initial message after config is fully loaded
1642+
const leadCaptureRequired = leadsConfig()?.status && !getLocalStorageChatflow(props.chatflowid)?.lead;
1643+
if (props.autoSendInitialMessage && !hasAutoSentInitialMessage && !leadCaptureRequired && messages().length === 1) {
1644+
hasAutoSentInitialMessage = true;
1645+
setUserInput(props.autoSendInitialMessage);
1646+
handleSubmit(props.autoSendInitialMessage);
1647+
}
16411648
}
16421649

16431650
// eslint-disable-next-line solid/reactivity

0 commit comments

Comments
 (0)