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 "@replyke/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.

Returns

ChatMessage
ChatMessage
The server-confirmed ChatMessage object.

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.