import { NextRequest, NextResponse } from "next/server"; import { Service } from "./service"; import { Facebook } from "./facebook"; const services: Record = { facebook: Facebook, none: NextResponse.error() as any, }; const getService = (req: NextRequest): Service => { const service = req.nextUrl.searchParams.get("service") ?? "none"; return services[service]; }; export const getAllBots = async (req: NextRequest): Promise => getService(req)?.getAllBots(req); export const getOneBot = async (req: NextRequest): Promise => getService(req)?.getOneBot(req); export const sendMessage = async (req: NextRequest): Promise => getService(req)?.sendMessage(req); export const receiveMessages = async ( req: NextRequest, ): Promise => getService(req)?.receiveMessages(req); export const registerBot = async (req: NextRequest): Promise => getService(req)?.registerBot(req); export const resetBot = async (req: NextRequest): Promise => getService(req)?.resetBot(req); export const requestCode = async (req: NextRequest): Promise => getService(req)?.requestCode(req); export const unverifyBot = async (req: NextRequest): Promise => getService(req)?.unverifyBot(req); export const refreshBot = async (req: NextRequest): Promise => getService(req)?.refreshBot(req); export const createBot = async (req: NextRequest): Promise => getService(req)?.createBot(req); export const deleteBot = async (req: NextRequest): Promise => getService(req)?.deleteBot(req); export const handleWebhook = async (req: NextRequest): Promise => getService(req)?.handleWebhook(req);