UNPKG

whatsapp-api-js

Version:

A TypeScript server agnostic Whatsapp's Official API framework

3 lines (2 loc) 782 B
import{WhatsAppAPIMiddleware}from"./globals.js";import{isInteger}from"../utils.js";class WhatsAppAPI extends WhatsAppAPIMiddleware{async handle_post(req){async function parseBody(readable){const chunks=[];for await(const chunk of readable)chunks.push(typeof chunk=="string"?Buffer.from(chunk):chunk);return Buffer.concat(chunks).toString("utf-8")}try{const body=await parseBody(req),signature=req.headers["x-hub-signature-256"];if(typeof signature!="string")throw 400;return this.post(JSON.parse(body||"{}"),body,signature)}catch(e){return isInteger(e)?e:500}}handle_get(req){try{return this.get(Object.fromEntries(new URL(req.url,`http://${req.headers.host}`).searchParams))}catch(e){throw isInteger(e)?e:500}}}export{WhatsAppAPI as default}; //# sourceMappingURL=node-http.js.map