Merge branch 'main' of https://github.com/josedario87/conversation-layer
All checks were successful
Deploy conversation layer / deploy (push) Successful in 22s
All checks were successful
Deploy conversation layer / deploy (push) Successful in 22s
This commit is contained in:
@@ -6,12 +6,37 @@ import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
interface Participant {
|
||||
id: string;
|
||||
name: string;
|
||||
isMe: boolean;
|
||||
isAdmin?: boolean;
|
||||
}
|
||||
|
||||
interface Msg {
|
||||
id: string;
|
||||
from: string;
|
||||
to: string;
|
||||
ts: number;
|
||||
type: 'chat' | 'image' | 'audio' | 'sticker' | 'doc';
|
||||
text?: string;
|
||||
mediaUrl?: string;
|
||||
mentions?: string[];
|
||||
meta: {
|
||||
ack: number;
|
||||
hasReaction: boolean;
|
||||
isQuoted: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface Conversation {
|
||||
chatId: string;
|
||||
messages: { text: string }[];
|
||||
title: string;
|
||||
isGroup: boolean;
|
||||
unreadCount: number;
|
||||
participants: Participant[];
|
||||
messages: Msg[];
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
messageCount: number;
|
||||
}
|
||||
|
||||
const PORT = Number(process.env.PORT) || 8001;
|
||||
@@ -44,14 +69,25 @@ app.use(express.json());
|
||||
app.post('/', async (req, res) => {
|
||||
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 || '';
|
||||
const lastMsg = conversation.messages[conversation.messages.length - 1];
|
||||
const message = lastMsg?.text || '';
|
||||
|
||||
const context = conversation.messages
|
||||
.slice(-10)
|
||||
.map((m) => {
|
||||
const sender =
|
||||
conversation.participants.find((p) => p.id === m.from)?.name || m.from;
|
||||
const content = m.text || `[${m.type}]`;
|
||||
return `${sender}: ${content}`;
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
if (!genAI) {
|
||||
return res.json({ reply: repoInfo });
|
||||
}
|
||||
|
||||
try {
|
||||
const contents = `Repo information: ${repoInfo}\nUser message: ${message}`;
|
||||
const contents = `Repo information: ${repoInfo}\nConversation:\n${context}\n`;
|
||||
const config: any = {};
|
||||
// if (message.toLowerCase().includes('/planilla')) {
|
||||
if (true) {
|
||||
@@ -77,7 +113,7 @@ app.get('/', (req, res) => {
|
||||
<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 {"conversation": {...}}</p>
|
||||
<p>Example: {"conversation": {"chatId": "123@c.us", "messages": [{"text": "hello"}]}}</p>
|
||||
<p>Example: {"conversation": {"chatId": "123@c.us", "title": "Chat", "isGroup": false, "unreadCount": 0, "participants": [{"id": "123@c.us", "name": "Alice", "isMe": false}], "messages": [{"id": "m1", "from": "123@c.us", "to": "me@c.us", "ts": 0, "type": "chat", "text": "hello", "meta": {"ack":0,"hasReaction":false,"isQuoted":false}}]}}</p>
|
||||
<p>It will respond with a JSON object containing {"reply": "the answer"}</p>
|
||||
|
||||
<p>Repository info: ${repoInfo}</p>
|
||||
@@ -87,4 +123,4 @@ app.get('/', (req, res) => {
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`conversation-layer-agent listening on ${PORT}`);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user