<?php

    include "db_connect.php";

    $msg= $_GET['msg'];
    $logUserid= $_GET['logUserid'];
    $chatBot = 1100;

    $createToday = new DateTime('now', new DateTimeZone('Asia/Colombo'));
	$date= $createToday->format('Y-m-d');
	$time= $createToday->format('H:i:s');

    $datetime = $date." ". $time;

$str = str_replace(' ', '%', $msg);
$requestingURL='http://127.0.0.1:5000/'.$str;

            $curl = curl_init();

            curl_setopt_array($curl, array(
            CURLOPT_URL => $requestingURL,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'GET',
            CURLOPT_HTTPHEADER => array(
                'Content-Type: application/json'
            ),
            ));


            

            $response = curl_exec($curl);
            $msg = $response;

            $sql2 = "INSERT INTO `chat_details`(`logUserid`, `chatBot`, `msg`, `type`, `date`, `time`, `datetime`) VALUES ('$logUserid', '$chatBot', '$msg', 'r',  '$date', '$time', '$datetime')";
            $result2 = mysqli_query($con,$sql1);

            $sql1 = "INSERT INTO `chat_details`(`logUserid`, `chatBot`, `msg`, `type`, `date`, `time`, `datetime`) VALUES ('$logUserid', '$chatBot', '$msg', 'r',  '$date', '$time', '$datetime')";
            $result1 = mysqli_query($con,$sql1);
          
?>