customer-dashboard-api/src/utils/adminDashboard.ts

34 lines
893 B
TypeScript

import axios from "axios";
import logger from "../logger/logger";
export async function telegramNotification(
type: Number,
message: String,
userIds?: String[]
) {
if (process.env.ADMIN_DASHBOARD_TELEGRAM_ENABLED !== "true") return;
axios({
url: `${process.env.ADMIN_DASHBOARD_TELEGRAM_NOTIFICATIONS_URL}`,
method: "post",
headers: {
"Content-Type": "application/json",
"X-Api-Key": process.env.ADMIN_DASHBOARD_TELEGRAM_NOTIFICATIONS_API_KEY,
},
data: {
type: type,
title: message,
userIds: userIds || [
"d2705d63-8668-4517-8b8b-e5396fb7e80b", // alex
"61660369-3ac9-4365-ab35-e96d58cdba2a", // jan
],
},
})
.then((response) => {
logger.info("Telegram notification response:", response.data);
})
.catch((error) => {
logger.error("Telegram notification error:", error);
});
}