index.tsx


Overview

index.tsx defines the EmbedModal React functional component, which provides a user interface for embedding a chat or agent flow widget into an external site via an iframe. The modal allows users to customize the embedded widget's appearance and locale settings, generates the corresponding iframe embed code, and facilitates easy copying of this code.

The modal supports three tabs (only the first tab is fully implemented):

Additionally, the modal displays the embed token (an identifier) with copy functionality and provides links to relevant documentation based on the context (agent or chat).


Detailed Explanation

Component: EmbedModal

const EmbedModal = ({
  visible,
  hideModal,
  token = '',
  form,
  beta = '',
  isAgent,
}: IModalProps<any> & {
  token: string;
  form: SharedFrom;
  beta: string;
  isAgent: boolean;
}) => { ... }

Purpose

EmbedModal is a modal dialog component that lets users configure and generate iframe embed codes for chat or agent flows. It supports customization of avatar visibility and locale, and provides tabs for different embedding modes.

Props

Prop

Type

Description

visible

boolean

Controls the visibility of the modal.

hideModal

() => void

Callback function to close/hide the modal.

token

string

Unique identifier for the shared chat or flow session, used to generate the iframe URL.

form

SharedFrom

Enum/string representing the source/form of the shared content (e.g., chat or flow).

beta

string

Beta authentication or feature flag token appended to the iframe URL.

isAgent

boolean

Flag indicating whether the embed is for an agent flow (true) or a chat session (false).

Internal State

State

Type

Description

visibleAvatar

boolean

Tracks if the avatar should be shown in the embedded iframe.

locale

string

Selected locale/language abbreviation for the embedded iframe.

Hooks Used

Key Functions

JSX Structure


Usage Example

import React, { useState } from 'react';
import EmbedModal from './index';

const ExampleUsage = () => {
  const [modalVisible, setModalVisible] = useState(true);

  return (
    <EmbedModal
      visible={modalVisible}
      hideModal={() => setModalVisible(false)}
      token="abc123xyz"
      form="chat"
      beta="beta-key"
      isAgent={false}
    />
  );
};

Implementation Details & Algorithms


Interaction with Other System Parts


Visual Diagram

componentDiagram
    direction TB
    EmbedModal --|> Modal : uses
    EmbedModal --|> Tabs : contains
    Tabs --> Tab1[Full Screen]
    Tabs --> Tab2[Partial (coming soon)]
    Tabs --> Tab3[Extension (coming soon)]
    Tab1 --> Card : displays options & code
    Card --> Form : contains Checkbox & Select
    Form --> Checkbox : avatar visibility
    Form --> Select : locale selection
    Card --> CopyToClipboard : copy iframe code
    Card --> HightLightMarkdown : show iframe code
    EmbedModal --> Typography : shows token & link
    EmbedModal --> useTranslate : for i18n
    EmbedModal --> useIsDarkTheme : for theming
    EmbedModal --> useMemo : memoize language options

Summary

The index.tsx file implements the EmbedModal component, a configurable modal dialog for generating iframe embed codes for chat or agent flow sessions. It supports avatar visibility and localization options, utilizes Ant Design components for UI, and integrates internationalization and theming hooks. The component is designed to be extensible with placeholders for additional embed modes and provides users with easy copy functionality and links to relevant documentation.

This file is central to the embedding feature of the chat/agent sharing system, bridging user configuration input with the generation of fully-formed embed code ready for integration into external websites.