Download src/controllers.ts from mfoud444/replay: direct link, hf CLI and curl.
- Browser
- Download file 3.32 kB
-
https://huggingface.co/spaces/mfoud444/replay/resolve/main/src/controllers.ts
- Command line
-
hf download hf://spaces/mfoud444/replay/src/controllers.ts
-
curl -L -o controllers.ts https://huggingface.co/spaces/mfoud444/replay/resolve/main/src/controllers.ts
3.32 kB
| import { Request, Response } from "express"; | |
| import { | |
| handleSubmitCode, | |
| handleLoginWithSession, | |
| handleRequestCode, | |
| handleAddTelegrafBot, | |
| handleCreateTask, | |
| handleCancelTask, | |
| handleSendMessage, | |
| startBots, | |
| stopBots, | |
| restartBots, | |
| getBotsState, | |
| } from "./services"; | |
| import { getActiveClients as getClients, getActiveTasks as getTasks, sendResponse } from "./utils"; | |
| export const submitCode = async (req: Request, res: Response) => { | |
| const { phoneNumber, code } = req.body; | |
| const result = await handleSubmitCode(phoneNumber, code); | |
| sendResponse(res, result.status, result.data); | |
| }; | |
| export const loginWithSession = async (req: Request, res: Response) => { | |
| const { apiKey, hash, session, phoneNumber } = req.body; | |
| const result = await handleLoginWithSession(apiKey, hash, session, phoneNumber); | |
| sendResponse(res, result.status, result.data); | |
| }; | |
| export const getActiveClients = (req: Request, res: Response) => { | |
| const result = getClients(); | |
| sendResponse(res, 200, result); | |
| }; | |
| export const requestCode = async (req: Request, res: Response) => { | |
| const { apiKey, hash, phoneNumber } = req.body; | |
| const result = await handleRequestCode(apiKey, hash, phoneNumber); | |
| sendResponse(res, result.status, result.data); | |
| }; | |
| export const addTelegrafBot = async (req: Request, res: Response) => { | |
| const { botToken } = req.body; | |
| const result = await handleAddTelegrafBot(botToken); | |
| sendResponse(res, result.status, result.data); | |
| }; | |
| export const createTask = async (req: Request, res: Response) => { | |
| const { phoneNumber, taskType, taskData } = req.body; | |
| const result = await handleCreateTask(phoneNumber,taskType, taskData); | |
| sendResponse(res, result.status, result.data); | |
| }; | |
| export const cancelTask = async (req: Request, res: Response) => { | |
| const { taskId } = req.params; | |
| const result = await handleCancelTask(taskId); | |
| sendResponse(res, result.status, result.data); | |
| }; | |
| export const getActiveTasks = (req: Request, res: Response) => { | |
| const result = getTasks(); | |
| sendResponse(res, 200, result); | |
| }; | |
| export const sendMessage = async (req: Request, res: Response) => { | |
| const { botToken, chatId, text } = req.body; | |
| const result = await handleSendMessage(botToken, chatId, text); | |
| sendResponse(res, result.status, result.data); | |
| }; | |
| export const startBotsEndpoint = async (req: Request, res: Response) => { | |
| try { | |
| await startBots(); | |
| sendResponse(res, 200, { message: "Bots started successfully" }); | |
| } catch (error: any) { | |
| sendResponse(res, 500, { error: error.message }); | |
| } | |
| }; | |
| export const stopBotsEndpoint = async (req: Request, res: Response) => { | |
| try { | |
| await stopBots(); | |
| sendResponse(res, 200, { message: "Bots stopped successfully" }); | |
| } catch (error: any) { | |
| sendResponse(res, 500, { error: error.message }); | |
| } | |
| }; | |
| export const restartBotsEndpoint = async (req: Request, res: Response) => { | |
| try { | |
| await restartBots(); | |
| sendResponse(res, 200, { message: "Bots restarted successfully" }); | |
| } catch (error: any) { | |
| sendResponse(res, 500, { error: error.message }); | |
| } | |
| }; | |
| export const getBotsStateEndpoint = async (req: Request, res: Response) => { | |
| try { | |
| const state = await getBotsState(); | |
| sendResponse(res, 200, state); | |
| } catch (error: any) { | |
| sendResponse(res, 500, { error: error.message }); | |
| } | |
| }; |