SiteMente - AI-Powered Lead Generation Platform
Features: - Mission Control dashboard - HP Submissions tracking - AI Agents integration - Lead management CRM - Marketing email templates - Chrome extension support Tech: Next.js, TypeScript, Tailwind CSS, MySQL
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { text } = body;
|
||||
|
||||
const prompt = `You are Cleopatra, a professional Spanish-speaking sales agent. Keep responses SHORT (1-2 sentences), friendly, in Spanish.
|
||||
|
||||
User: ${text}
|
||||
|
||||
Response in Spanish:`;
|
||||
|
||||
const res = await fetch("http://127.0.0.1:11434/api/generate", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
signal: AbortSignal.timeout(60000),
|
||||
body: JSON.stringify({
|
||||
model: "phi3:mini",
|
||||
prompt: prompt,
|
||||
stream: false
|
||||
})
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
const reply = (data.response || "¡Hola! Estoy aquí.").substring(0, 200);
|
||||
|
||||
return NextResponse.json({ response: reply });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return NextResponse.json({
|
||||
response: "Tengo problemas para conectar. Intenta de nuevo."
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
// Get all Hookd items
|
||||
export async function GET(request: Request) {
|
||||
const url = new URL(request.url)
|
||||
const action = url.searchParams.get('action') || 'list'
|
||||
|
||||
try {
|
||||
const possiblePaths = [
|
||||
path.join(process.cwd(), '..', 'chrome-extensions', 'hookd', 'data.json'),
|
||||
'/var/www/hostpioneers.com/public_html/contacts.json',
|
||||
]
|
||||
|
||||
let data: any[] = []
|
||||
|
||||
// Try to read from Hookd storage
|
||||
for (const filePath of possiblePaths) {
|
||||
if (fs.existsSync(filePath)) {
|
||||
const content = fs.readFileSync(filePath, 'utf-8')
|
||||
data = JSON.parse(content)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (action === 'stats') {
|
||||
return NextResponse.json({
|
||||
total: data.length,
|
||||
byCategory: data.reduce((acc: any, item) => {
|
||||
const cat = item.category || 'Uncategorized'
|
||||
acc[cat] = (acc[cat] || 0) + 1
|
||||
return acc
|
||||
}, {}),
|
||||
aiProcessed: data.filter((i: any) => i.aiProcessed).length,
|
||||
saved: data.filter((i: any) => i.saved).length,
|
||||
recent: data.slice(0, 10)
|
||||
})
|
||||
}
|
||||
|
||||
return NextResponse.json({ items: data })
|
||||
} catch (error) {
|
||||
console.error('Hookd API error:', error)
|
||||
return NextResponse.json({ items: [], error: 'Failed to fetch' }, { status: 200 })
|
||||
}
|
||||
}
|
||||
|
||||
// Process items with AI
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { items, instruction } = body
|
||||
|
||||
// This would call MiniMax API to process items
|
||||
// For now, return mock AI analysis
|
||||
|
||||
const results = items.map((item: any) => ({
|
||||
id: item.id,
|
||||
category: guessCategory(item),
|
||||
score: guessScore(item),
|
||||
tags: guessTags(item),
|
||||
summary: item.content?.slice(0, 100) + '...'
|
||||
}))
|
||||
|
||||
return NextResponse.json({ results })
|
||||
} catch (error) {
|
||||
console.error('AI processing error:', error)
|
||||
return NextResponse.json({ error: 'Processing failed' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
function guessCategory(item: any): string {
|
||||
const content = (item.content || '').toLowerCase()
|
||||
const link = (item.link || '').toLowerCase()
|
||||
|
||||
if (content.includes('ai') || content.includes('gpt') || content.includes('claude') ||
|
||||
content.includes('openai') || content.includes('anthropic') ||
|
||||
link.includes('github.com') || link.includes('huggingface')) {
|
||||
return 'AI'
|
||||
}
|
||||
if (content.includes('news') || content.includes('breaking') || content.includes('just in')) {
|
||||
return 'News'
|
||||
}
|
||||
if (content.includes('idea') || content.includes('thought') || content.includes('what if')) {
|
||||
return 'Ideas'
|
||||
}
|
||||
if (content.includes('lol') || content.includes('meme') || content.includes('funny') || content.includes('😂')) {
|
||||
return 'Memes'
|
||||
}
|
||||
return 'Other'
|
||||
}
|
||||
|
||||
function guessScore(item: any): number {
|
||||
const content = (item.content || '').toLowerCase()
|
||||
let score = 5
|
||||
|
||||
if (item.link) score += 1
|
||||
if (content.length > 100) score += 1
|
||||
if (content.includes('github')) score += 1
|
||||
if (content.includes('ai') || content.includes('gpt')) score += 2
|
||||
|
||||
return Math.min(10, score)
|
||||
}
|
||||
|
||||
function guessTags(item: any): string[] {
|
||||
const tags: string[] = []
|
||||
const content = (item.content || '').toLowerCase()
|
||||
|
||||
if (content.includes('ai')) tags.push('AI')
|
||||
if (content.includes('tool')) tags.push('Tools')
|
||||
if (content.includes('news')) tags.push('News')
|
||||
if (content.includes('tutorial')) tags.push('Tutorial')
|
||||
if (content.includes('github')) tags.push('Code')
|
||||
|
||||
return tags
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
// Try multiple possible paths
|
||||
const possiblePaths = [
|
||||
path.join(process.cwd(), '..', 'hostpioneers.com', 'public_html', 'contacts.json'),
|
||||
path.join(process.cwd(), 'public', '..', 'contacts.json'),
|
||||
'/var/www/hostpioneers.com/public_html/contacts.json',
|
||||
]
|
||||
|
||||
let data = '[]'
|
||||
for (const filePath of possiblePaths) {
|
||||
if (fs.existsSync(filePath)) {
|
||||
data = fs.readFileSync(filePath, 'utf-8')
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const submissions = JSON.parse(data || '[]')
|
||||
return NextResponse.json({ submissions: submissions.reverse() })
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
return NextResponse.json({ submissions: [], error: 'Failed to fetch' }, { status: 200 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import mysql from 'mysql2/promise'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
async function getPool() {
|
||||
return mysql.createPool({
|
||||
host: 'localhost',
|
||||
user: 'sitemente',
|
||||
password: 'pa0ndoQRPDYBHzTXX3rbWd6E',
|
||||
database: 'sitemente',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10
|
||||
})
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const segment = searchParams.get('segment')
|
||||
const dormancy = searchParams.get('dormancy')
|
||||
const search = searchParams.get('search')
|
||||
const sortBy = searchParams.get('sortBy') || 'total_spent'
|
||||
const sortOrder = searchParams.get('sortOrder') || 'DESC'
|
||||
const page = parseInt(searchParams.get('page') || '1')
|
||||
const limit = parseInt(searchParams.get('limit') || '100')
|
||||
const offset = (page - 1) * limit
|
||||
|
||||
// Validate sortBy to prevent SQL injection
|
||||
const allowedSortColumns = ['firstname', 'lastname', 'email', 'company', 'country', 'total_spent', 'segment', 'dormancy_flag', 'id']
|
||||
const safeSortBy = allowedSortColumns.includes(sortBy) ? sortBy : 'total_spent'
|
||||
const safeSortOrder = sortOrder === 'ASC' ? 'ASC' : 'DESC'
|
||||
|
||||
try {
|
||||
const pool = await getPool()
|
||||
|
||||
let countQuery = 'SELECT COUNT(*) as total FROM hostpioneers_leads WHERE 1=1'
|
||||
let query = 'SELECT * FROM hostpioneers_leads WHERE 1=1'
|
||||
const params: any[] = []
|
||||
|
||||
if (segment && segment !== 'all') {
|
||||
countQuery += ' AND segment = ?'
|
||||
query += ' AND segment = ?'
|
||||
params.push(segment)
|
||||
}
|
||||
if (dormancy && dormancy !== 'all') {
|
||||
countQuery += ' AND dormancy_flag = ?'
|
||||
query += ' AND dormancy_flag = ?'
|
||||
params.push(dormancy)
|
||||
}
|
||||
if (search) {
|
||||
const searchClause = ' AND (firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR company LIKE ? OR phone LIKE ? OR country LIKE ?)'
|
||||
countQuery += searchClause
|
||||
query += searchClause
|
||||
const searchTerm = `%${search}%`
|
||||
params.push(searchTerm, searchTerm, searchTerm, searchTerm, searchTerm, searchTerm)
|
||||
}
|
||||
|
||||
const [countResult] = await pool.query(countQuery, params)
|
||||
const total = (countResult as any[])[0].total
|
||||
|
||||
query += ` ORDER BY ${safeSortBy} ${safeSortOrder} LIMIT ? OFFSET ?`
|
||||
const [rows] = await pool.query(query, [...params, limit, offset])
|
||||
|
||||
await pool.end()
|
||||
|
||||
return NextResponse.json({
|
||||
leads: rows,
|
||||
pagination: { page, limit, total, totalPages: Math.ceil(total / limit) }
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
return NextResponse.json({ error: 'Failed to fetch' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import mysql from 'mysql2/promise';
|
||||
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST || 'localhost',
|
||||
user: process.env.DB_USER || 'sitemente',
|
||||
password: process.env.DB_PASS || 'SiteMente2026!',
|
||||
database: process.env.DB_NAME || 'sitemente'
|
||||
};
|
||||
|
||||
export async function GET() {
|
||||
let conn;
|
||||
try {
|
||||
conn = await mysql.createConnection(dbConfig);
|
||||
const [rows] = await conn.execute('SELECT * FROM research ORDER BY created_at DESC');
|
||||
return NextResponse.json(rows);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return NextResponse.json([]);
|
||||
} finally {
|
||||
if (conn) conn.end();
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
let conn;
|
||||
try {
|
||||
const body = await request.json();
|
||||
conn = await mysql.createConnection(dbConfig);
|
||||
|
||||
await conn.execute(
|
||||
'INSERT INTO research (name, query, results_count, summary, results, created_at) VALUES (?, ?, ?, ?, ?, NOW())',
|
||||
[body.name, body.query, body.results_count || 0, body.summary || '', JSON.stringify(body.results || [])]
|
||||
);
|
||||
|
||||
const [rows] = await conn.execute('SELECT * FROM research ORDER BY created_at DESC');
|
||||
return NextResponse.json(rows);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return NextResponse.json({ error: 'Failed to save research' }, { status: 500 });
|
||||
} finally {
|
||||
if (conn) conn.end();
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request) {
|
||||
let conn;
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get('id');
|
||||
|
||||
if (!id) return NextResponse.json({ error: 'Missing id' }, { status: 400 });
|
||||
|
||||
conn = await mysql.createConnection(dbConfig);
|
||||
await conn.execute('DELETE FROM research WHERE id = ?', [id]);
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return NextResponse.json({ error: 'Failed to delete' }, { status: 500 });
|
||||
} finally {
|
||||
if (conn) conn.end();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user