Notification whatsapp : ps

This commit is contained in:
VE10-Sanjeev 2023-12-01 14:49:17 +05:30
parent b12197a9ce
commit 5fb9cc3686
5 changed files with 27 additions and 9 deletions

6
.env
View File

@ -142,3 +142,9 @@ CI_ENVIRONMENT = development
# curlrequest.shareOptions = true
APP_TIMEZONE = 'Asia/Kolkata'
#--------------------------------------------------------------------
# Whatsapp Access Token And Instance ID
#--------------------------------------------------------------------
WAAI_TOKEN = '6568739969f28'
WAAI_INSTANCE = '656876690A9FD'

View File

@ -115,8 +115,17 @@ define('order_column', ["invoice_id","wp_api_order_id","invoice_child_id"]);
define('order_child','invoiceitems');
define('order_child_column', ["invoice_id","wp_api_line_items_id","customer_id"]);
define('WAAI_TOKEN', '652548474f4e4');
define('WAAI_INSTANCE', '65254894E4A88');
// define('WAAI_TOKEN', '652548474f4e4');
// define('WAAI_INSTANCE', '65254894E4A88');
// UAT - for testing Purpose..
// define('WAAI_TOKEN', '65685e954bcf6');
// define('WAAI_INSTANCE', '656863C54F90C');
// LIVE - Vel given.30th Nov.
// define('WAAI_TOKEN', '6568739969f28');
// define('WAAI_INSTANCE', '656876690A9FD');
define('SEND_WAAI_URL', 'https://waai.in/api/send');
define('SEND_WAAI_GROUP_URL', 'https://waai.in/api/send_group');

View File

@ -35,9 +35,9 @@ class Notifications extends BaseController
if ($request->is('post')) {
$records = $request->getVar();
$params = (object) Null;
$this->logger->info("Whatsapp : sending message instance id = " . WAAI_INSTANCE);
$this->logger->info("Whatsapp : sending message instance id = " . $_ENV['WAAI_INSTANCE'] ." - ". $_ENV['WAAI_TOKEN']);
try {
$this->logger->info("Whatsapp : sending message instance id = " . WAAI_INSTANCE);
if ($records['categories'] == 'SEND_WAAI_GROUP_URL') {
if($records['group_id'] != ""){ $params->group_id = $records['group_id']; }
else{ throw new \Exception("Group Id Missing Please Try again.."); }
@ -54,9 +54,10 @@ class Notifications extends BaseController
$url = constant($records['categories']);
$params->type = $records['type'] == "" ? "text" : $records['type'];
$params->instance_id = WAAI_INSTANCE;
$params->access_token = WAAI_TOKEN;
$params->instance_id = $_ENV['WAAI_INSTANCE'];
$params->access_token = $_ENV['WAAI_TOKEN'];
$params->message = $records['description'];
$this->logger->info("Whatsapp : sending message request = " . json_encode($params));
$this->logger->info("Whatsapp : sending message request type b4 = " . gettype($params));
helper('notification');
$notification = new NotificationHelper();

View File

@ -77,13 +77,15 @@ class NotificationHelper
$this->logger->info('Helper : Whatsapp');
$curl = curl_init();
$headers = array('Content-Type:application/json');
$jsonencoded = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
curl_setopt( $curl,CURLOPT_URL, $url);
$this->logger->info('Helper : Whatsapp url = '.$url);
switch ($method) {
case "POST":
curl_setopt( $curl,CURLOPT_POST, true );
if ($data) {
curl_setopt( $curl,CURLOPT_POSTFIELDS, json_encode($data));
$this->logger->info('Helper : Whatsapp jsonencoded = '.$jsonencoded);
curl_setopt( $curl,CURLOPT_POSTFIELDS, $jsonencoded);
}
break;
case "PUT":
@ -123,4 +125,4 @@ class NotificationHelper
}
}
?>
?>

View File

@ -146,7 +146,7 @@
</div>
</div>
</div>
<div id="fields-for-mobile" style="display: none;">
<div id="fields-for-mobile">
<div class="form-group row">
<label for="mobile" class="col-4 col-form-label">Mobile Number</label>
<div class="col-7">