Skip to content

Commit

Permalink
fix: autostart (CT-000) (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
DecathectZero committed Feb 23, 2024
1 parent d28b43d commit cb7ad34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseRequest } from '@voiceflow/base-types';
import { isTextRequest } from '@voiceflow/base-types/build/cjs/request';
import { ActionType, Trace, TraceDeclaration } from '@voiceflow/sdk-runtime';
import cuid from 'cuid';
import { useEffect, useState } from 'react';
import { useState } from 'react';

import { SendMessage, SessionOptions, SessionStatus } from '@/common';
import { DEFAULT_MESSAGE_DELAY } from '@/components/SystemResponse/constants';
Expand Down Expand Up @@ -137,10 +137,6 @@ export const useRuntimeState = ({ assistant, config }: Settings) => {
setOpen(false);
};

useEffect(() => {
if (config.autostart) launch?.();
}, []);

return {
state: {
session,
Expand Down
9 changes: 7 additions & 2 deletions packages/react-chat/src/views/ChatEmbed/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext } from 'react';
import { useContext, useEffect } from 'react';

import { RuntimeStateAPIContext } from '@/contexts';
import { useChatAPI, useTheme } from '@/hooks';
Expand All @@ -13,7 +13,7 @@ interface ChatEmbedProps extends React.PropsWithChildren {
}

const ChatEmbed: React.FC<ChatEmbedProps> = ({ shadowRoot, chatAPI, ready }) => {
const { assistant, interact } = useContext(RuntimeStateAPIContext);
const { assistant, interact, open } = useContext(RuntimeStateAPIContext);
const theme = useTheme(assistant);

const isStyleSheetResolved = useResolveAssistantStyleSheet(assistant, shadowRoot);
Expand All @@ -28,6 +28,11 @@ const ChatEmbed: React.FC<ChatEmbedProps> = ({ shadowRoot, chatAPI, ready }) =>
ready
);

useEffect(() => {
// "open" the embedded chat window to trigger launch
open();
}, []);

if (!isStyleSheetResolved) return null;
return <ChatWindow className={theme} />;
};
Expand Down

0 comments on commit cb7ad34

Please sign in to comment.