Skip to main content

Overview

Returns a function to send messages to the conversation on behalf of the user. The message appears as a user message and triggers the AI to respond.

Import

import { useSendMessage } from 'sunpeak';

Signature

function useSendMessage(): (params: SendMessageParams) => Promise<void>

SendMessageParams

role
'user'
required
Message role.
content
MessageContent[]
required
Array of message content parts.

MessageContent

type
'text'
required
Content type.
text
string
required
Message text content.

Returns

sendMessage
(params: SendMessageParams) => Promise<void>
Function to send a message to the conversation.

Usage

import { useSendMessage } from 'sunpeak';

function MyResource() {
  const sendMessage = useSendMessage();

  const handleFollowUp = async () => {
    await sendMessage({
      role: 'user',
      content: [{ type: 'text', text: 'Show me more details' }],
    });
  };

  return <button onClick={handleFollowUp}>Ask for Details</button>;
}