From 73b62a4b295cb2318a2e190fd29e468503ddae27 Mon Sep 17 00:00:00 2001 From: Mayur Virendra Date: Tue, 16 Apr 2024 23:25:42 +0530 Subject: [PATCH] Added whatsapp message --- controllers/Agent.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/controllers/Agent.js b/controllers/Agent.js index 3cbd2d4..65701d9 100644 --- a/controllers/Agent.js +++ b/controllers/Agent.js @@ -1,13 +1,17 @@ import AI from '../services/AI.js'; import DBService from '../services/DBService.js' import MapService from '../services/MapService.js' +import Actions from '../services/Actions.js'; import { EMPTY_SESSION } from '../config/constants.js'; const db = new DBService(); +const actionsService = new Actions(); async function getResponse(req, res) { const { From, Body, raw_yn } = req.body + const format = (req?.headers && req.headers['content-type']) || 'text/xml'; + if(!From || !Body){ res.status(400).send("Bad Request") @@ -50,9 +54,15 @@ async function getResponse(req, res) { // save session await db.update_session(From, session) - res.send(responseBody) - } - + // Send response + if(format!='application/json'){ + await actionsService.send_message(From, responseBody, []); + res.send("Message sent!") + } + else{ + res.send(responseBody) + } + } }