Skip to main content

Overview

Returns an async function that sends a message to a conversation. An optimistic entry is inserted into Redux immediately — with a temporary ID — and replaced by the server-confirmed message on success. If the request fails, the optimistic message is flagged with sendFailed: true.
Requires ChatProvider in the component tree.

Usage Example

import { useSendMessage } from "@sublay/react-js";

function MessageInput({ conversationId }: { conversationId: string }) {
  const send = useSendMessage({ conversationId });
  const [text, setText] = useState("");

  const handleSend = async () => {
    if (!text.trim()) return;
    await send({ content: text });
    setText("");
  };

  return (
    <div>
      <input value={text} onChange={(e) => setText(e.target.value)} />
      <button onClick={handleSend}>Send</button>
    </div>
  );
}

Props

conversationId
string
required
The ID of the conversation to send the message to.

Parameters

The hook returns a function. That function accepts:
content
string
Plain text content of the message.
gif
GifData
GIF attachment data.
mentions
Mention[]
User mentions to embed in the message.
metadata
Record<string, any>
Arbitrary key-value data attached to the message.
quotedMessageId
string | null
ID of the message being quoted. Populates quotedMessage on the stored message.
parentMessageId
string | null
ID of the parent message when sending a thread reply.
files
File[]
File attachments. When provided, the request is sent as multipart/form-data.
spaceReputationId
string
Resolves the sender’s reputation into a spaceReputation number on the embedded user of the returned message. Accepts a space <uuid>, "none" (project-general bucket), or "context" (server-derived from the request context). Empty string, "general", and null are rejected. See Reputation.
spaceReputationDescendants
boolean
When true, spaceReputation is the subtree sum (the space plus all its descendants). Only honored when spaceReputationId is an explicit <uuid>.

Returns

ChatMessage
ChatMessage
The server-confirmed ChatMessage object. When spaceReputationId is set, its embedded sender carries an added spaceReputation number. See Reputation.

Notes

  • At least one of content, gif, files, or non-empty metadata should be provided for a meaningful message.
  • For integration guidance, see Chat: Messages.