How to pass function call response to assistant
Hi
I am based on the git example https://github.com/VapiAI/client-side-example-javascript-react
and I'm trying to handle the response to my custom function call.
I hit an endpoint on my server, I get a response and I have to deal with it and pass it on to the assistant.
I can display the response to the console log, but nothing else.
It was suggested to me to add the json return below. But it didn't work.
Any tips are welcome
useEffect(() => {
const onMessageUpdate = (message: Message) => {
if (message.type !== MessageTypeEnum.FUNCTION_CALL)
return;
if (message.functionCall.name === "availability") {
const params = message.functionCall.parameters;
getAvailability(params);
}
};
const getAvailability = async (data: AvailabilityDto) => {
let api: BookingApi = new BookingApi();
let availability: string = await api.getAvailability(data);
console.log("availability", availability);
return {
"result": availability
};
}
vapi.on("message", onMessageUpdate);
return () => {
vapi.off("message", onMessageUpdate);
};
}, []);
I am based on the git example https://github.com/VapiAI/client-side-example-javascript-react
and I'm trying to handle the response to my custom function call.
I hit an endpoint on my server, I get a response and I have to deal with it and pass it on to the assistant.
I can display the response to the console log, but nothing else.
It was suggested to me to add the json return below. But it didn't work.
Any tips are welcome
useEffect(() => {
const onMessageUpdate = (message: Message) => {
if (message.type !== MessageTypeEnum.FUNCTION_CALL)
return;
if (message.functionCall.name === "availability") {
const params = message.functionCall.parameters;
getAvailability(params);
}
};
const getAvailability = async (data: AvailabilityDto) => {
let api: BookingApi = new BookingApi();
let availability: string = await api.getAvailability(data);
console.log("availability", availability);
return {
"result": availability
};
}
vapi.on("message", onMessageUpdate);
return () => {
vapi.off("message", onMessageUpdate);
};
}, []);
GitHub
Contribute to VapiAI/client-side-example-javascript-react development by creating an account on GitHub.