#Help how to send message in a programmable way

1 messages · Page 1 of 1 (latest)

low cipher
#

I would like to know if there is a programmable way to send a message on rendering a certain CopilotChat.

white condor
glacial fable
#

Hi @low cipher !

You can give this a try!

import { useAgent } from "@copilotkit/react-core/v2"
const { agent } = useAgent()

const sendMessage = () => {
  agent.addMessage()
  agent.runAgent()
}
low cipher
# glacial fable Hi <@1445339747714334793> ! You can give this a try! ```tsx import { useAgent ...

i tried with your code as follows,bu it seems failed,while i can see the request was send to the server ,and the server respond corresponding content。but the streamable content fron the server not been rendered in the CopilotChat. herer is my test code(sorry it's my first time using discord,i don't kow how to format my code in a right way):export default function AMapChat() {
const { data: session } = useSession();
const { agent } = useAgent({ agentId: "amap" });
const consumePrompt = useInitPromptStore((s) => s.consumePrompt);//get a initial prompt from zustand store

useEffect(() => {
const run = async () => {
const initial = consumePrompt();
if (initial) {
agent.addMessage({
id: crypto.randomUUID(),
role: "user",
content: initial,
});
await agent.runAgent();
}
};
void run();
}, [consumePrompt, agent]);

return (
<div
className="flex flex-col h-full w-full"
style={
{
"--copilot-kit-primary-color": "var(--color-primary)",
} as CopilotKitCSSProperties
}
>
<CopilotChat

    threadId={`amap-${session?.user?.id}`}
    agentId={"amap"}
  />
</div>

);
}

regal idolBOT
#

Thanks for the additional context, @low cipher! The team will get back to you soon.

low cipher