Mohammed Foud commited on
Commit
1336397
·
1 Parent(s): de0a64f
Files changed (3) hide show
  1. src/bots/index.ts +1 -1
  2. src/controllers.ts +22 -0
  3. src/routes.ts +3 -1
src/bots/index.ts CHANGED
@@ -31,7 +31,7 @@ export const handleAddTelegrafBot = async (botId: string) => {
31
 
32
  // Check if bot is already running
33
  if (telegrafBots.has(botData.bot_token)) {
34
- return { status: 400, data: { error: "Bot is already running" } };
35
  }
36
 
37
  // Validate bot token format
 
31
 
32
  // Check if bot is already running
33
  if (telegrafBots.has(botData.bot_token)) {
34
+ return { status: 200, data: { error: "Bot is already running" } };
35
  }
36
 
37
  // Validate bot token format
src/controllers.ts CHANGED
@@ -18,6 +18,7 @@ import { handleAddTelegrafBot } from "./bots";
18
  import { getActiveClients as getClients, getActiveTasks as getTasks, sendResponse } from "./utils";
19
  import { supabase } from './db/supabase';
20
  import { loadCommandsAndMessages } from './config';
 
21
 
22
  import { telegrafBots } from "./models";
23
  export const submitCode = async (req: Request, res: Response) => {
@@ -382,4 +383,25 @@ export const startSpecificBotEndpoint = async (req: Request, res: Response) => {
382
  console.error('Error starting specific bot:', error);
383
  sendResponse(res, 500, { error: error.message });
384
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  };
 
18
  import { getActiveClients as getClients, getActiveTasks as getTasks, sendResponse } from "./utils";
19
  import { supabase } from './db/supabase';
20
  import { loadCommandsAndMessages } from './config';
21
+ import { stopBot } from './bots/botManager';
22
 
23
  import { telegrafBots } from "./models";
24
  export const submitCode = async (req: Request, res: Response) => {
 
383
  console.error('Error starting specific bot:', error);
384
  sendResponse(res, 500, { error: error.message });
385
  }
386
+ };
387
+
388
+ export const stopSpecificBotEndpoint = async (req: Request, res: Response) => {
389
+ try {
390
+ const { botId } = req.body;
391
+
392
+ if (!botId) {
393
+ return sendResponse(res, 400, { error: "Bot ID is required" });
394
+ }
395
+
396
+ const result = await stopBot(botId);
397
+
398
+ if (result.success) {
399
+ sendResponse(res, 200, { message: result.message });
400
+ } else {
401
+ sendResponse(res, 404, { error: result.message });
402
+ }
403
+ } catch (error: any) {
404
+ console.error('Error stopping specific bot:', error);
405
+ sendResponse(res, 500, { error: error.message });
406
+ }
407
  };
src/routes.ts CHANGED
@@ -24,7 +24,8 @@ import {
24
  updateMessage,
25
  deleteMessage,
26
  startTelegrafBotsEndpoint,
27
- startSpecificBotEndpoint
 
28
 
29
  } from "./controllers";
30
 
@@ -46,6 +47,7 @@ export const setupRoutes = (app: any) => {
46
  router.post("/bots/restart", restartBotsEndpoint as unknown as RequestHandler);
47
  router.post("/bots/telegraf/start", startTelegrafBotsEndpoint as unknown as RequestHandler);
48
  router.post("/bots/telegraf/start-specific", startSpecificBotEndpoint as unknown as RequestHandler);
 
49
 
50
  router.get("/bots/state", getBotsStateEndpoint as unknown as RequestHandler);
51
 
 
24
  updateMessage,
25
  deleteMessage,
26
  startTelegrafBotsEndpoint,
27
+ startSpecificBotEndpoint,
28
+ stopSpecificBotEndpoint
29
 
30
  } from "./controllers";
31
 
 
47
  router.post("/bots/restart", restartBotsEndpoint as unknown as RequestHandler);
48
  router.post("/bots/telegraf/start", startTelegrafBotsEndpoint as unknown as RequestHandler);
49
  router.post("/bots/telegraf/start-specific", startSpecificBotEndpoint as unknown as RequestHandler);
50
+ router.post("/bots/telegraf/stop-specific", stopSpecificBotEndpoint as unknown as RequestHandler);
51
 
52
  router.get("/bots/state", getBotsStateEndpoint as unknown as RequestHandler);
53