import express from "express";
import cors from "cors";
// const express = require("express");
import sendTemplateMessage from "./SendMessage.js";
// const sendTemplateMessage = require("./SendMessage.js");
const app = express();
app.use(express.json());
app.use(
  cors({
    origin: "*",
  })
);

app.post("/send-message", async (req, res) => {
  const { name, body } = req.body;
  try {
    await sendTemplateMessage(name, body);
    res
      .status(200)
      .json({ success: true, message: "Message sent successfully" });
  } catch (error) {
    console.error(error);
    res.status(500).json({ success: true, message: "Failed to send message" });
  }
});

app.get("/test-api", async (req, res) => {
  res.status(200).send("working fine...");
});

app.listen(3000, () => console.log("Server running on http://localhost:3000"));
