Update handlers to receive conversation objects
This commit is contained in:
@@ -6,6 +6,14 @@ import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
interface Conversation {
|
||||
chatId: string;
|
||||
messages: { text: string }[];
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
messageCount: number;
|
||||
}
|
||||
|
||||
const PORT = Number(process.env.PORT) || 8001;
|
||||
const API_KEY = process.env.GEMINI_API_KEY || '';
|
||||
console.log(`Using Gemini API key: ${API_KEY}`);
|
||||
@@ -34,8 +42,9 @@ const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
app.post('/', async (req, res) => {
|
||||
const message = req.body?.message as string | undefined;
|
||||
if (!message) return res.status(400).json({ error: 'Missing message' });
|
||||
const conversation = req.body?.conversation as Conversation | undefined;
|
||||
if (!conversation) return res.status(400).json({ error: 'Missing conversation' });
|
||||
const message = conversation.messages[conversation.messages.length - 1]?.text || '';
|
||||
|
||||
if (!genAI) {
|
||||
return res.json({ reply: repoInfo });
|
||||
@@ -66,8 +75,8 @@ app.get('/', (req, res) => {
|
||||
res.send(`
|
||||
<h1>Conversation Layer Agent</h1>
|
||||
<p>This service answers questions about the repository.</p>
|
||||
<p>Send a POST request to / with a JSON body containing {"message": "your question"}</p>
|
||||
<p>Example: {"message": "What is this repository about?"}</p>
|
||||
<p>Send a POST request to / with a JSON body containing {"conversation": {...}}</p>
|
||||
<p>Example: {"conversation": {"chatId": "123@c.us", "messages": [{"text": "hello"}]}}</p>
|
||||
<p>It will respond with a JSON object containing {"reply": "the answer"}</p>
|
||||
|
||||
<p>Repository info: ${repoInfo}</p>
|
||||
|
||||
Reference in New Issue
Block a user