UNPKG

klu-whatsapp

Version:

API to notify KL University canteen owners via WhatsApp

39 lines (34 loc) 1.13 kB
import axios from "axios"; import dotenv from "dotenv"; dotenv.config(); const API_URL = ``; export async function message(order) { const payload = { messaging_product: "whatsapp", to: process.env.OWNER_NUMBER, type: "template", template: { name: "new_order_KLU", language: { code: "en_US" }, components: [ { type: "body", parameters: [ { type: "text", text: order.studentName }, { type: "text", text: order.rollNo }, { type: "text", text: order.orderId }, { type: "text", text: order.itemsSummary }, { type: "text", text: `₹${order.total}` }, { type: "text", text: order.time } ] } ] } }; const headers = { Authorization:`Bearer ${WHATSAPP_TOKEN}`, "Content-Type": "application/json" }; const res = await axios.post(API_URL,payload,{headers}); return res.data; }