Skip to content

Commit 5512067

Browse files
committed
feat: add autoSendInitialMessage config option for pre-populating chat
1 parent 482c837 commit 5512067

12 files changed

Lines changed: 20 additions & 6 deletions

File tree

dist/components/Bot.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export type BotProps = {
124124
closeBot?: () => void;
125125
hasCustomHeader?: boolean;
126126
dialogContainer?: HTMLElement;
127+
autoSendInitialMessage?: string;
127128
};
128129
export type LeadsConfig = {
129130
status: boolean;

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/features/bubble/components/Bubble.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/features/bubble/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export type ChatWindowTheme = {
7676
dateTimeToggle?: DateTimeToggleTheme;
7777
renderHTML?: boolean;
7878
headerHtml?: string;
79+
autoSendInitialMessage?: string;
7980
};
8081
export type ButtonTheme = {
8182
size?: 'small' | 'medium' | 'large' | number;

dist/features/bubble/types.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/features/full/components/Full.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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export type BotProps = {
188188
closeBot?: () => void;
189189
hasCustomHeader?: boolean;
190190
dialogContainer?: HTMLElement;
191+
autoSendInitialMessage?: string;
191192
};
192193

193194
export type LeadsConfig = {
@@ -553,6 +554,7 @@ export const Bot = (botProps: BotProps & { class?: string }) => {
553554
// TTS auto-scroll prevention refs
554555
let isTTSActionRef = false;
555556
let ttsTimeoutRef: ReturnType<typeof setTimeout> | null = null;
557+
let hasAutoSentInitialMessage = false;
556558

557559
createMemo(() => {
558560
const customerId = (props.chatflowConfig?.vars as any)?.customerId;
@@ -1630,6 +1632,13 @@ export const Bot = (botProps: BotProps & { class?: string }) => {
16301632
setIsTTSEnabled(!!chatbotConfig.isTTSEnabled);
16311633
}
16321634

1635+
// Auto-send initial message after config is fully loaded
1636+
if (props.autoSendInitialMessage && !hasAutoSentInitialMessage) {
1637+
hasAutoSentInitialMessage = true;
1638+
setUserInput(props.autoSendInitialMessage);
1639+
handleSubmit(props.autoSendInitialMessage);
1640+
}
1641+
16331642
// eslint-disable-next-line solid/reactivity
16341643
return () => {
16351644
setUserInput('');

src/features/bubble/components/Bubble.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export const Bubble = (props: BubbleProps) => {
212212
hasCustomHeader={!!bubbleProps.theme?.chatWindow?.headerHtml}
213213
closeBot={closeBot}
214214
dialogContainer={resolveDialogContainer(props.dialogContainer) ?? bubbleContainerRef()}
215+
autoSendInitialMessage={bubbleProps.theme?.chatWindow?.autoSendInitialMessage}
215216
/>
216217
</div>
217218
</Show>

0 commit comments

Comments
 (0)