41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
import express from "express";
|
|
import {
|
|
getVendorChats,
|
|
getChatMessages,
|
|
sendVendorMessage,
|
|
processTelegramMessage,
|
|
getVendorUnreadCounts,
|
|
createChat,
|
|
createTelegramChat,
|
|
markMessagesAsRead
|
|
} from "../controllers/chat.controller.js";
|
|
import { protectVendor as vendorAuth } from "../middleware/vendorAuthMiddleware.js";
|
|
import { protectTelegramApi } from "../middleware/telegramAuthMiddleware.js";
|
|
|
|
const router = express.Router();
|
|
|
|
// Routes that require vendor authentication
|
|
router.get("/vendor/:vendorId", vendorAuth, getVendorChats);
|
|
router.get("/vendor/:vendorId/unread", vendorAuth, getVendorUnreadCounts);
|
|
router.get("/:chatId", vendorAuth, getChatMessages);
|
|
router.post("/:chatId/message", vendorAuth, sendVendorMessage);
|
|
router.post("/:chatId/mark-read", vendorAuth, markMessagesAsRead);
|
|
router.post("/create", vendorAuth, createChat);
|
|
|
|
// Routes for Telegram client (secured with API key)
|
|
router.post("/telegram/message", protectTelegramApi, processTelegramMessage);
|
|
router.post("/telegram/create", protectTelegramApi, createTelegramChat);
|
|
|
|
// Test route for Telegram API auth
|
|
router.get("/telegram/test-auth", protectTelegramApi, (req, res) => {
|
|
res.status(200).json({
|
|
success: true,
|
|
message: "Authentication successful",
|
|
headers: {
|
|
authHeader: req.headers.authorization ? req.headers.authorization.substring(0, 10) + "..." : "undefined",
|
|
xApiKey: req.headers['x-api-key'] ? req.headers['x-api-key'].substring(0, 10) + "..." : "undefined"
|
|
}
|
|
});
|
|
});
|
|
|
|
export default router;
|