feat: add autoSendInitialMessage config option for pre-populating chat#373
Open
SyncWithRaj wants to merge 5 commits intoFlowiseAI:mainfrom
Open
feat: add autoSendInitialMessage config option for pre-populating chat#373SyncWithRaj wants to merge 5 commits intoFlowiseAI:mainfrom
SyncWithRaj wants to merge 5 commits intoFlowiseAI:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the autoSendInitialMessage feature, enabling the chatbot to automatically send a message upon initialization. The implementation includes updates to the Bot component, theme types, and the bubble/full-page features. Review feedback points out that the auto-send logic incorrectly triggers on page refreshes even with existing history and should be moved inside the configuration loading block to prevent race conditions. Additionally, the state flag tracking the auto-send status should be reset when the chatflowid changes to support component reuse in single-page applications.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was the problem?
Previously, if a developer wanted to pre-populate and send an initial message when the chat widget loads, they had to mutate the DOM directly via JavaScript (e.g., setting the input field's value and clicking the send button programmatically). This doesn't work well with Solid.js because the internal reactive state stays empty, leaving the Send button disabled.
Closes #343
What was built?
A new config option called
autoSendInitialMessage. This allows developers to pass any custom message string via the embed config. The widget will automatically type it into the input field and submit it as soon as the chat loads using Solid.js's reactive state system.It uses a
hasAutoSentInitialMessageflag to ensure the automatic message only fires exactly once upon initialization.How end-users use it:
Technical Changes:
src/features/bubble/types.ts: Added autoSendInitialMessage?: string to ChatWindowTheme interface.
src/components/Bot.tsx: Added the prop to BotProps. Added logic inside the config-loading createEffect to set the reactive input value and trigger handleSubmit() once the config is fully fetched.
src/features/bubble/components/Bubble.tsx & src/features/full/components/Full.tsx: Passed the new config property down to the Bot component.
src/window.ts & src/constants.ts: Cleaned up the prop flow so it routes cleanly through the theme object.
Testing:
yarn build) compiles successfully without TS errors.