Merge branch 'main' of https://github.com/josedario87/conversation-layer
All checks were successful
Deploy conversation layer / deploy (push) Successful in 22s

This commit is contained in:
2025-06-05 14:05:59 -06:00
8 changed files with 320 additions and 157 deletions

View File

@@ -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 });
@@ -67,8 +76,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>