Connect Horus Chat to Telegram (Horus)
This commit is contained in:
@@ -10,7 +10,7 @@ interface Message {
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
export default function VoiceChat() {
|
||||
export default function HorusChat() {
|
||||
const [input, setInput] = useState("");
|
||||
const [messages, setMessages] = useState<Message[]>([
|
||||
{
|
||||
@@ -27,6 +27,34 @@ export default function VoiceChat() {
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||
}, [messages]);
|
||||
|
||||
// Poll for responses from Horus (Telegram)
|
||||
useEffect(() => {
|
||||
let pollInterval: NodeJS.Timeout;
|
||||
|
||||
if (isProcessing) {
|
||||
pollInterval = setInterval(async () => {
|
||||
try {
|
||||
const res = await fetch("/api/horus-mc-response");
|
||||
const data = await res.json();
|
||||
|
||||
if (data.response) {
|
||||
setMessages(prev => [...prev, {
|
||||
id: `horus_${Date.now()}`,
|
||||
role: "assistant",
|
||||
content: data.response,
|
||||
timestamp: Date.now(),
|
||||
}]);
|
||||
setIsProcessing(false);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Poll error:", e);
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
return () => clearInterval(pollInterval);
|
||||
}, [isProcessing]);
|
||||
|
||||
const handleSend = async () => {
|
||||
if (!input.trim() || isProcessing) return;
|
||||
|
||||
@@ -42,35 +70,22 @@ export default function VoiceChat() {
|
||||
setIsProcessing(true);
|
||||
|
||||
try {
|
||||
// Send to SiteMente AI agent
|
||||
const res = await fetch("/api/chat/agent", {
|
||||
// Send to Horus via Telegram
|
||||
await fetch("/api/horus-mc-send", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
message: userMessage.content,
|
||||
locale: "es"
|
||||
}),
|
||||
body: JSON.stringify({ message: userMessage.content }),
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
const botMessage: Message = {
|
||||
id: `bot_${Date.now()}`,
|
||||
role: "assistant",
|
||||
content: data.response || "Entendido.",
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
|
||||
setMessages(prev => [...prev, botMessage]);
|
||||
// Will receive response via polling
|
||||
} catch (e) {
|
||||
console.error("Chat error:", e);
|
||||
console.error("Send error:", e);
|
||||
setMessages(prev => [...prev, {
|
||||
id: `error_${Date.now()}`,
|
||||
role: "assistant",
|
||||
content: "Error de conexión. Prueba en Telegram.",
|
||||
timestamp: Date.now(),
|
||||
}]);
|
||||
} finally {
|
||||
setIsProcessing(false);
|
||||
}
|
||||
};
|
||||
@@ -87,8 +102,8 @@ export default function VoiceChat() {
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between px-4 py-3 border-b border-white/10">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-lg">💬</span>
|
||||
<span className="font-semibold">Horus Chat</span>
|
||||
<span className="text-lg">👁️</span>
|
||||
<span className="font-semibold">Horus</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{isProcessing && (
|
||||
@@ -129,7 +144,7 @@ export default function VoiceChat() {
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
onKeyPress={handleKeyPress}
|
||||
placeholder="Escribe un mensaje..."
|
||||
placeholder="Escribe a Horus..."
|
||||
className="flex-1 bg-white/5 border border-white/10 rounded-lg px-4 py-2 text-sm text-white placeholder:text-white/40 focus:outline-none focus:border-brand-pink"
|
||||
disabled={isProcessing}
|
||||
/>
|
||||
@@ -142,7 +157,7 @@ export default function VoiceChat() {
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-xs text-white/40 mt-2 text-center">
|
||||
O chatea directamente en Telegram
|
||||
Respondo en Telegram - ¡Escríbeme ahí también!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user