Vapi
08/29/2024, 3:27 PMjavascript
const express = require('express');
const app = express();
app.use(express.json());
app.post('/your-function-endpoint', (req, res) => {
// Perform your function logic here
const success = true; // or false based on your function's execution
if (success) {
// If the function call was successful
res.json({ result: "The operation was successful." });
} else {
// If the function call failed
res.json({ result: "The operation failed." });
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
In this example, when the endpoint /your-function-endpoint
is hit with a POST request, the server will process the request and return a JSON response indicating whether the operation was successful or not. The res.json()
method is used to send a JSON response back to the client, which in this case is the assistant.Vapi
08/29/2024, 3:27 PM