import { Flex, Stack, Heading, Text, Button, VStack } from '@chakra-ui/react' import { ArrowRight } from 'assets/icons/ArrowRight' import { TypebotViewer } from 'bot-engine' import { NextChakraLink } from 'components/common/nextChakraAdapters/NextChakraLink' import { PublicTypebot, Typebot } from 'models' import React, { useEffect, useRef, useState } from 'react' import { sendRequest } from 'utils' export const RealTimeResults = () => { const iframeRef = useRef(null) const [typebot, setTypebot] = useState() const fetchTemplate = async () => { const { data, error } = await sendRequest( `/typebots/realtime-airtable.json` ) if (error) return const typebot = data as Typebot setTypebot({ ...typebot, typebotId: typebot.id } as PublicTypebot) } useEffect(() => { fetchTemplate() window.addEventListener('message', processMessage) const interval = setInterval(refreshIframeContent, 30000) return () => { clearInterval(interval) window.removeEventListener('message', processMessage) } // eslint-disable-next-line react-hooks/exhaustive-deps }, []) const processMessage = (event: MessageEvent) => { if (event.data.from === 'typebot') refreshIframeContent() } const refreshIframeContent = () => { if (!iframeRef.current) return iframeRef.current.src += '' } return ( Collect results in real-time One of the main advantage of a chat application is that you collect the user's responses on each question.{' '} You won't loose any valuable data. {typebot && ( )}