use-send-shared-message.ts


Overview

This file provides React hooks and utility logic to facilitate sending messages in a shared chat context, particularly when interacting with external agents (such as chatbots or agentbots). It primarily handles message sending workflows that depend on URL query parameters, external input fetching, and supports different dialogue modes including task-oriented interactions.

The key responsibilities include:

This file plays a critical role in the messaging flow of a shared chat interface, ensuring messages are correctly composed, sent, and that UI states (like dialogs) are properly handled.


Detailed Documentation

1. useSendButtonDisabled(value: string): boolean

Purpose:
Determines whether the send button should be disabled based on the input message string.

Parameters:

Returns:

Usage Example:

const isDisabled = useSendButtonDisabled(inputValue);
<button disabled={isDisabled}>Send</button>

Details:
Uses lodash trim to remove whitespace and checks if the resulting string is empty.


2. useGetSharedChatSearchParams(): { from: SharedFrom; sharedId: string | null; locale: string | null; data: Record<string, string>; visibleAvatar: boolean }

Purpose:
Extracts and parses relevant shared chat parameters from the URL query string.

Returns:
An object containing:

Usage Example:

const { from, sharedId, locale, data, visibleAvatar } = useGetSharedChatSearchParams();

Details:
Uses useSearchParams hook from umi to access query parameters. Filters keys starting with data_ and strips the prefix for the returned data object.


3. useSendNextSharedMessage(addEventList: (data: IEventList, messageId: string) => void)

Purpose:
Manages the process of sending the next message in a shared chat, supporting both normal chat and task modes.

Parameters:

Returns:
An object with properties and methods:

Usage Example:

const {
  sendMessage,
  parameterDialogVisible,
  showParameterDialog,
  hideParameterDialog,
  ok,
  isTaskMode,
} = useSendNextSharedMessage(addEventList);

if (!parameterDialogVisible) {
  showParameterDialog();
}

// When parameters are ready:
ok(someParams);

Implementation Details:

This hook acts as a bridge between UI components and backend APIs for sending shared messages, handling both interactive and automated task flows.


Important Implementation Details & Algorithms


Interaction with Other Modules

This file acts as a layer combining these utilities/hooks to implement the shared message sending logic.


Visual Diagram

flowchart TD
    A[useSendNextSharedMessage] --> B[useGetSharedChatSearchParams]
    A --> C[useFetchExternalAgentInputs]
    A --> D[useSetModalState]
    A --> E[useSendAgentMessage]
    B --> F{Parse URL search params}
    D --> G[Modal visible state]
    E --> H[Send message to API]
    A --> I[State: params, sendedTaskMessage]
    A --> J[Callbacks: ok(), runTask()]
    J --> E
    subgraph Modal Control
        D
        G
    end
    subgraph Message Sending Flow
        I
        J
        E
    end

Diagram Explanation:


Summary

use-send-shared-message.ts is a specialized utility file that provides React hooks to manage sending messages in a shared chat setting, supporting both user-driven and automated task modes. It interfaces with URL parameters, external input fetching, modal dialogs, and message sending APIs to orchestrate the message flow reliably and flexibly.

This file is an essential part of the shared chat feature, abstracting complex state and side-effect management, and enabling reusable, clean integration in UI components responsible for shared conversations.