Create an Answer
Section titled “Create an Answer”Add an endpoint on your server to create an Answer.
POST /api/v1/conversations/answer
responds with an answer which includes:
- An
id
which you can use when attaching feedback to an answer. - A
conversationId
which you can optionally pass to the next call to continue the conversation.
See the response type reference here.
Return the answer in your response.
app.post("/create-answer", async (req, res) => { const { question, conversationId } = req.body;
// NOTE: Hardcoded placeholder context for sample data. // Fetch this from a trusted source in your application. const payload = { question, context: { organisationId: 1 } }
if (conversationId) { payload.conversationId = conversationId }
try { const response = await fetch("https://app.inconvo.ai/api/v1/conversations/answer", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${process.env.INCONVO_API_KEY}`, }, body: JSON.stringify(payload), }); const answer = await response.json(); res.json(answer); } catch (error) { console.error("Error from Inconvo:", error); res.status(500).json({ error: "Failed to get response from Inconvo" }); }});