Update
This commit is contained in:
1 parent
b780bff850
commit
7b3ea37127
1752 files changed
+1341
-166
No files matched your search
+43
-2
@@ -4,6 +4,8 @@ import type { Server } from 'http';
|
||||
import type { Logger } from '../utils/logger.js';
|
||||
import type { PostsRepository, MessagesRepository, SuccessfulMessagesRepository } from '../database/repositories.js';
|
||||
import type { Config } from '../config/index.js';
|
||||
import type { ChatService, ActiveChat } from '../services/chat.js';
|
||||
import type { ResponseCheckerService } from '../services/response-checker.js';
|
||||
|
||||
export interface BotStats {
|
||||
isRunning: boolean;
|
||||
@@ -32,6 +34,8 @@ export class WebServer {
|
||||
private activityLog: ActivityItem[] = [];
|
||||
private botRunning = false; // Start stopped
|
||||
private messagesThisHour = 0;
|
||||
private chatService: ChatService | null = null;
|
||||
private responseChecker: ResponseCheckerService | null = null;
|
||||
|
||||
constructor(
|
||||
private port: number,
|
||||
@@ -44,7 +48,6 @@ export class WebServer {
|
||||
this.app = express();
|
||||
this.setupRoutes();
|
||||
}
|
||||
|
||||
private setupRoutes(): void {
|
||||
// Serve static files
|
||||
this.app.use(express.static(path.join(process.cwd(), 'public')));
|
||||
@@ -73,6 +76,21 @@ export class WebServer {
|
||||
res.json(successful);
|
||||
});
|
||||
|
||||
// API: Get active chats (last 48 hours)
|
||||
this.app.get('/api/chats', async (req, res) => {
|
||||
if (!this.chatService) {
|
||||
res.json([]);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const chats = await this.chatService.getActiveChats();
|
||||
res.json(chats);
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to fetch chats:', error);
|
||||
res.json([]);
|
||||
}
|
||||
});
|
||||
|
||||
// API: Start bot
|
||||
this.app.post('/api/start', (req, res) => {
|
||||
this.botRunning = true;
|
||||
@@ -89,16 +107,39 @@ export class WebServer {
|
||||
res.json({ success: true, running: false });
|
||||
});
|
||||
|
||||
// API: Debug check responses
|
||||
this.app.post('/api/debug/check-responses', async (req, res) => {
|
||||
if (!this.responseChecker) {
|
||||
res.status(500).json({ error: 'Response checker not initialized' });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.logger.info('Manual response check triggered via API');
|
||||
const results = await this.responseChecker.checkForResponses();
|
||||
res.json({ success: true, results });
|
||||
} catch (error) {
|
||||
this.logger.error('Manual response check failed:', error);
|
||||
res.status(500).json({ error: String(error) });
|
||||
}
|
||||
});
|
||||
|
||||
// Serve dashboard for all other routes
|
||||
this.app.get(/.*/, (req, res) => {
|
||||
res.sendFile(path.join(process.cwd(), 'public', 'index.html'));
|
||||
});
|
||||
}
|
||||
|
||||
isRunning(): boolean {
|
||||
return this.botRunning;
|
||||
}
|
||||
|
||||
setChatService(chatService: ChatService): void {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
setResponseChecker(responseChecker: ResponseCheckerService): void {
|
||||
this.responseChecker = responseChecker;
|
||||
}
|
||||
|
||||
private getStats(): BotStats {
|
||||
const messages = this.messagesRepo.getRecent(1000);
|
||||
const totalSent = messages.length;
|
||||
|
||||
Reference in new issue
Block a user