composer.send(message)
- Method Name:
composer.send(message)
- Description
This method sends a message submits a message to the AI backend for processing, on the user's behalf. When called, it will fill the composer's input field with the provided message and submit it to the chatbot.
- Arguments:
Argument | Type | Description |
---|---|---|
message | string | The prompt to be submitted to the chatbot. |
- Usage:
import {AiChat, useAiChatApi} from 'nlux';
export default function App() {
// Create an instance of the AiChatApi using the useAiChatApi hook
const api = useAiChatApi();
// Call `api.composer.send(...)` to send a message to the chatbot
const onClick = useCallback(() => {
api.composer.send('Hello, World!'); // Sending message on click 🚀 🙌
}, [api]);
// When creating the AiChat component, pass the `api` object as a prop
return (
<div>
<AiChat api={api} adapter={adapter} />
<button onClick={onClick}>Send Message Programmatically</button>
</div>
);
}