Files
Synapsis/src/app/api/bots/[id]/mentions/route.ts
T
AskIt 8ad3b97b7e feat(bots): Implement comprehensive bot system with autonomous posting, content management, and API endpoints
- Add bot management system with creation, suspension, and reinstatement functionality
- Implement autonomous bot posting with scheduling, rate limiting, and content generation
- Add content fetching system supporting RSS feeds and multiple content sources
- Implement LLM-based content generation with customizable bot personalities
- Add mention handling and automated response system for bot interactions
- Implement API key management with encryption using AUTH_SECRET for simplified deployment
- Add comprehensive bot logging system for activity tracking and error monitoring
- Create bot administration pages and settings UI for managing bot configurations
- Add database migrations for bot system schema including users, sources, and content items
- Implement cron job system for automated bot operations and scheduled tasks
- Add extensive test coverage with unit and property-based tests for core bot modules
- Simplify encryption by deriving keys from AUTH_SECRET instead of separate environment variable
- Implement automatic content fetching on post trigger with retry logic
- Add Reddit-specific link preview handling using oEmbed API for reliable metadata extraction
- Create utility scripts for bot inspection and cleanup operations
- Add comprehensive bot system documentation and improvement tracking
2026-01-25 16:22:41 +01:00

86 lines
2.1 KiB
TypeScript

/**
* Bot Mentions API Routes
*
* GET /api/bots/[id]/mentions - Get pending mentions for a bot
*
* Requirements: 7.1
*/
import { NextRequest, NextResponse } from 'next/server';
import { getSession } from '@/lib/auth';
import { db, bots } from '@/db';
import { eq } from 'drizzle-orm';
import { getUnprocessedMentions, getAllMentions } from '@/lib/bots/mentionHandler';
/**
* GET /api/bots/[id]/mentions
*
* Get mentions for a bot. Returns unprocessed mentions by default,
* or all mentions if ?all=true is provided.
*
* Query Parameters:
* - all: boolean - If true, return all mentions (processed and unprocessed)
*
* Validates: Requirements 7.1
*/
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
// Check authentication
const session = await getSession();
if (!session?.user?.id) {
return NextResponse.json(
{ error: 'Authentication required' },
{ status: 401 }
);
}
const { id: botId } = await params;
// Verify bot exists and user owns it
const bot = await db.query.bots.findFirst({
where: eq(bots.id, botId),
columns: {
id: true,
userId: true,
},
});
if (!bot) {
return NextResponse.json(
{ error: 'Bot not found' },
{ status: 404 }
);
}
if (bot.userId !== session.user.id) {
return NextResponse.json(
{ error: 'Not authorized to access this bot' },
{ status: 403 }
);
}
// Get mentions based on query parameter
const { searchParams } = new URL(request.url);
const showAll = searchParams.get('all') === 'true';
const mentions = showAll
? await getAllMentions(botId)
: await getUnprocessedMentions(botId);
return NextResponse.json({
mentions,
count: mentions.length,
unprocessedOnly: !showAll,
});
} catch (error) {
console.error('Error fetching bot mentions:', error);
return NextResponse.json(
{ error: 'Failed to fetch mentions' },
{ status: 500 }
);
}
}