diff --git a/.hta_slug/edit-lead.php b/.hta_slug/edit-lead.php index acc6f9e..f9ea7bd 100644 --- a/.hta_slug/edit-lead.php +++ b/.hta_slug/edit-lead.php @@ -51,6 +51,7 @@ $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // var_dump($rows); foreach($rows as $row){ + $usersEmailForSendMessage = $row['email']; $usersNameforSendMessage = $row['name']; $usersNumberforSendMessage = $row['phone']; $nameParts = explode(" ", $row['name']); @@ -272,6 +273,130 @@ + [ + [ + "email" => $usersEmailForSendMessage, + "name" => $usersNameforSendMessage + ] + ], + "templateId" => (int)$_GET['send-email-id'], // Ensure this is an integer + "batchId" => "5c6cfa04-eed9-42c2-8b5c-6d470d978e9d" + ]; + $jsonData = json_encode($data); + + $options = [ + 'http' => [ + 'header' => "Content-Type: application/json\r\n" . + "api-key: $apiKey\r\n", + 'method' => 'POST', + 'content' => $jsonData, + ], + ]; + + $context = stream_context_create($options); + $fp = @fopen($url, 'r', false, $context); // Suppress warnings to handle them manually + + if ($fp === FALSE) { + $error = error_get_last(); + echo 'Error occurred: ' . $error['message']; + } else { + $response = stream_get_contents($fp); + $http_response_header = $http_response_header ?? []; + $response_code = (int)substr($http_response_header[0], 9, 3); + + if ($response === FALSE || $response_code >= 400) { + echo 'Error reading response: ' . $response; + } else { + $templateName = $_GET['send-email-id']; + $messageMethod = 'Email'; + try { + $stmt = $conn->prepare("INSERT INTO communication (leadid, useremail, username, templateid, method) VALUES (:leadid, :useremail, :username, :templateid, :method)"); + $stmt->bindParam(':leadid', $_GET['id']); + $stmt->bindParam(':useremail', $_SESSION['email']); + $stmt->bindParam(':username', $_SESSION['name']); + $stmt->bindParam(':templateid', $templateName); + $stmt->bindParam(':method', $messageMethod); + $stmt->execute(); + $sendSuccessMessage = "Email Sent successfully"; + echo ''; + } catch (PDOException $e) { + echo "Error: " . $e->getMessage(); + } + } + // Close the file pointer + fclose($fp); + } + } elseif (isset($_GET['send-whatsapp-id']) && $_GET['send-whatsapp-id']) { + $url = "https://api.interakt.ai/v1/public/message/"; + $apiKey = 'Basic {{OTgyajd4bHFUSXItSW9PN1BTdzhOenNDaS0ya0NQeXByRE0tMnRyQ3FrUTo=}}'; + $data = [ + "fullPhoneNumber" => $usersNumberforSendMessage, + "callbackData" => "some text here", + "type" => "Template", + "template" => [ + "name" => "boost_conversion", + "languageCode" => "en", + "headerValues" => [ + "header_variable_value" + ], + "bodyValues" => [ + $usersNameforSendMessage + ] + ] + ]; + $jsonData = json_encode($data); + + $options = [ + 'http' => [ + 'header' => "Content-Type: application/json\r\n" . + "Authorization: $apiKey\r\n" . + "Content-Length: " . strlen($jsonData) . "\r\n", + 'method' => 'POST', + 'content' => $jsonData, + ], + ]; + + $context = stream_context_create($options); + $fp = fopen($url, 'r', false, $context); + if ($fp === FALSE) { + echo 'Error occurred'; + } else { + $response = stream_get_contents($fp); + + if ($response === FALSE) { + echo 'Error reading response'; + } else { + if(isset($_GET['send-whatsapp-id'])){ + $templateName = $_GET['send-whatsapp-id']; + } elseif(isset($_GET['send-email-id'])){ + $templateName = $_GET['send-email-id']; + } + $messageMethod = 'WhatsApp'; + try { + $stmt = $conn->prepare("INSERT INTO communication (leadid, useremail, username, templateid, method) VALUES (:leadid, :useremail, :username, :templateid, :method)"); + $stmt->bindParam(':leadid', $_GET['id']); + $stmt->bindParam(':useremail', $_SESSION['email']); + $stmt->bindParam(':username', $_SESSION['name']); + $stmt->bindParam(':templateid', $templateName); + $stmt->bindParam(':method', $messageMethod); + $stmt->execute(); + $sendSuccessMessage = "WhatsApp Sent successfully"; + echo ''; + } catch(PDOException $e) { + echo "Error: " . $e->getMessage(); + } + // echo ''; + // echo $response; + } + fclose($fp); + } + } + ?>
Mail Send by
+Send by