ArqadiushS
05/06/2024, 2:11 PMVapi Support
05/06/2024, 2:11 PMVapi Support
05/06/2024, 2:12 PMjson
{
"result": "Your custom message or data here"
}
In your case, after obtaining the availability
from your BookingApi
, you should ensure that this information is sent back to Vapi in the expected format. However, your current implementation only logs the availability to the console and returns the response object locally within the getAvailability
function. This local return does not communicate back to the assistant.
To effectively respond to the assistant with the function call result, you need to implement server-side logic that captures the function call from the assistant, processes it (just as you've done with getAvailability
), and then sends a HTTP response back with the desired result
payload.
Here's a simplified server-side example in Node.js, assuming you're using Express.js for handling HTTP requests:Vapi Support
05/06/2024, 2:12 PMjavascript
app.post('/your-function-endpoint', async (req, res) => {
const data = req.body; // Assuming your parameters are sent in the body
let api = new BookingApi();
let availability = await api.getAvailability(data);
res.json({"result": availability}); // Respond back to Vapi with the availability
});
This example assumes that you have a server endpoint (/your-function-endpoint
) that Vapi calls when the availability
function is triggered. The server then processes the request, retrieves the availability, and responds with the availability data in the format expected by Vapi.
Remember, the interaction between your assistant and your server relies on HTTP requests and responses. Ensure your assistant's function configuration points to the correct server URL where your logic for handling function calls is implemented.
For more detailed guidance on setting up your server to handle function calls and respond appropriately, please refer to Vapi's documentation on [Function Calling]().Sahil
05/06/2024, 6:33 PMArqadiushS
05/06/2024, 7:29 PMSahil
05/06/2024, 7:30 PM