diff --git a/packages/manager/apps/container/src/container/livechat/ChatDialog.component.tsx b/packages/manager/apps/container/src/container/livechat/ChatDialog.component.tsx index 2c5f8ebc6cd1..f5e1441b47c7 100644 --- a/packages/manager/apps/container/src/container/livechat/ChatDialog.component.tsx +++ b/packages/manager/apps/container/src/container/livechat/ChatDialog.component.tsx @@ -10,6 +10,7 @@ type ChatDialogProps = { url: string; visible: boolean; title: string; + chatIFrame: React.MutableRefObject; showHeader?: boolean; }; @@ -20,10 +21,10 @@ export default function ChatDialog({ url, visible, title, + chatIFrame, showHeader = true, }: Readonly): JSX.Element { const chatDialog = useRef(null); - const chatIFrame = useRef(null); useEffect(() => { if (chatDialog.current) { diff --git a/packages/manager/apps/container/src/container/livechat/LiveChat.component.tsx b/packages/manager/apps/container/src/container/livechat/LiveChat.component.tsx index 16f0f3187afe..48356570d286 100644 --- a/packages/manager/apps/container/src/container/livechat/LiveChat.component.tsx +++ b/packages/manager/apps/container/src/container/livechat/LiveChat.component.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { v6 } from '@ovh-ux/manager-core-api'; import { Environment } from '@ovh-ux/manager-config'; import { OsdsButton, OsdsText, OsdsIcon } from '@ovhcloud/ods-components/react'; @@ -20,6 +20,7 @@ import { LiveChatType, LiveChatState, ApiV6AuthToken, + SnowChatContext } from '@/types/live-chat.type'; import { ADRIELLY_CHAT_URL_TEMPLATE, @@ -45,18 +46,6 @@ const fetchAuthToken = async (): Promise => { } }; -export type SnowChatContext = { - skip_load_history?: string; - live_agent_only?: string; - language?: string; - region?: string; - queue: string; - branding_key?: string; - session_id: string; - interface_type?: string; - interface_name?: string; -}; - export default function LiveChat({ closeLiveChat, }: Readonly): JSX.Element { @@ -74,6 +63,7 @@ export default function LiveChat({ const region = environment.getRegion(); const language = environment.getUserLanguage(); const { ovhSubsidiary, supportLevel } = environment.getUser(); + const chatIFrame = useRef(null); const [ snowChatQueue, @@ -100,6 +90,13 @@ export default function LiveChat({ const handleCloseChat = () => { setChatbotReduced(false); + if (chatType === 'SNOW' && chatIFrame.current) { + chatIFrame.current.contentWindow?.postMessage( + { action: 'endConversation' }, + '*', + ); + } + clearSnowChatQueue(); clearChatType(); clearChatState(); @@ -177,6 +174,7 @@ export default function LiveChat({ {chatType === 'Adrielly' && (