completed the send SMS which uses the first client App API key
This commit is contained in:
@@ -53,7 +53,6 @@ class ClientsTrafficController extends Controller
|
|||||||
public function indexTabulator(Request $request){
|
public function indexTabulator(Request $request){
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
|
|
||||||
// Construct the URL with pagination parameters from the request
|
|
||||||
$page = $request->input('page', 0); // Note: This API seems 0-indexed
|
$page = $request->input('page', 0); // Note: This API seems 0-indexed
|
||||||
$size = $request->input('size', 20);
|
$size = $request->input('size', 20);
|
||||||
/*
|
/*
|
||||||
@@ -71,7 +70,7 @@ class ClientsTrafficController extends Controller
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
$client_id = session('current_user.org_id');
|
$client_id = session('current_user.org_id');
|
||||||
$clients_url = "messages/client/1?page=0&size=20&sort=createdAt,desc";
|
$clients_url = "messages/client/$client_id?page=0&size=20&sort=createdAt,desc";
|
||||||
$result = ApiCalls::CurlGet($clients_url);
|
$result = ApiCalls::CurlGet($clients_url);
|
||||||
// $content_only = collect($result['content'])->toArray();
|
// $content_only = collect($result['content'])->toArray();
|
||||||
$data = json_decode($result, true);
|
$data = json_decode($result, true);
|
||||||
@@ -86,8 +85,8 @@ class ClientsTrafficController extends Controller
|
|||||||
// ]);
|
// ]);
|
||||||
}
|
}
|
||||||
public function getClientApps(){
|
public function getClientApps(){
|
||||||
//dump(session('current_user'));
|
|
||||||
$client_id = session('current_user.org_id');
|
$client_id = session('current_user.org_id');
|
||||||
|
|
||||||
$apps_url = "applications/client/$client_id?page=0&size=20&sort=createdAt,desc";
|
$apps_url = "applications/client/$client_id?page=0&size=20&sort=createdAt,desc";
|
||||||
$result = ApiCalls::CurlGet($apps_url);
|
$result = ApiCalls::CurlGet($apps_url);
|
||||||
$result_arr = json_decode($result);
|
$result_arr = json_decode($result);
|
||||||
@@ -109,28 +108,19 @@ class ClientsTrafficController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
public function store(Request $request){
|
public function store(Request $request){
|
||||||
|
//233244982690,233553175995,233204040805
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'message' => 'required',
|
'message' => 'required',
|
||||||
'sender_id' => 'required|max:11',
|
'sender_id' => 'required|max:11',
|
||||||
'recipients_file'=> 'mimes:csv,txt|max:4096',
|
'recipients_file'=> 'mimes:csv,txt|max:4096',
|
||||||
'pasted' => 'sometimes',
|
'pasted' => 'sometimes',
|
||||||
// 'status' => 'required',
|
|
||||||
]);
|
]);
|
||||||
$recipients_arr = [];
|
$recipients_arr = [];
|
||||||
// $create_client_url = "clients";
|
|
||||||
// $result = ApiCalls::CurlPost(json_encode($client_arr), $create_client_url);
|
|
||||||
|
|
||||||
if ($request->recipient_file && $request->pasted) {
|
|
||||||
// code...
|
|
||||||
}
|
|
||||||
if ($request->filled('pasted')) {
|
if ($request->filled('pasted')) {
|
||||||
// code...
|
$pasted_arr = explode(",", $request->pasted);
|
||||||
$pasted_arr = explode(", ", $request->pasted);
|
|
||||||
foreach ($pasted_arr as $value) {
|
foreach ($pasted_arr as $value) {
|
||||||
// code...
|
|
||||||
if (ctype_digit($value) && (strlen($value) == 11 || strlen($value) == 12)) {
|
if (ctype_digit($value) && (strlen($value) == 11 || strlen($value) == 12)) {
|
||||||
// Valid
|
|
||||||
$recipients_arr[] = trim($value);
|
$recipients_arr[] = trim($value);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -148,21 +138,21 @@ class ClientsTrafficController extends Controller
|
|||||||
fclose($file);
|
fclose($file);
|
||||||
}
|
}
|
||||||
$recipients_arr = array_unique($recipients_arr);
|
$recipients_arr = array_unique($recipients_arr);
|
||||||
|
|
||||||
|
$client_id = session('current_user.org_id');
|
||||||
|
|
||||||
foreach ($recipients_arr as $phone) {
|
foreach ($recipients_arr as $phone) {
|
||||||
$payload = [
|
$payload = [
|
||||||
'from' => $request->sender_id,
|
'from' => $request->sender_id,
|
||||||
'to' => $phone,
|
'to' => $phone,
|
||||||
'refId' => uniqid(),
|
'refId' => uniqid('cmlportal_'),
|
||||||
'message' => $request->message
|
'message' => $request->message
|
||||||
];
|
];
|
||||||
\Log::info('Payload details ' . json_encode($payload));
|
\Log::info('Payload details ' . json_encode($payload));
|
||||||
$send_sms_url = "sms/send";
|
$send_sms_url = "sms/send";
|
||||||
#$result = ApiCalls::CurlPost($send_sms_url, $payload);
|
$result = ApiCalls::CurlPost(json_encode($payload), $send_sms_url);
|
||||||
#\Log::info('Message Successfully submitted ' . $result);
|
\Log::info('Message Successfully submitted ' . $result);
|
||||||
}
|
}
|
||||||
// $result_arr = json_decode($result);
|
|
||||||
|
|
||||||
|
|
||||||
Session::flash('success_message', 'Message successfully submitted for delivery!');
|
Session::flash('success_message', 'Message successfully submitted for delivery!');
|
||||||
return redirect("send-sms");
|
return redirect("send-sms");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,16 @@ class ApiCalls
|
|||||||
}
|
}
|
||||||
public static function CurlPost($data, $url){
|
public static function CurlPost($data, $url){
|
||||||
$post_url = env('APIBASEURL') . $url;
|
$post_url = env('APIBASEURL') . $url;
|
||||||
|
$header_part = '';
|
||||||
|
$client_id = session('current_user.org_id');
|
||||||
|
if ($url == 'sms/send') {
|
||||||
|
// code...
|
||||||
|
$apps_url = "applications/client/$client_id?page=0&size=20&sort=createdAt,desc";
|
||||||
|
$result = static::CurlGet($apps_url);
|
||||||
|
$result_arr = json_decode($result);
|
||||||
|
$api_key = $result_arr->content[0]->apiKey;
|
||||||
|
$header_part = "Authorization: Bearer " . $api_key;
|
||||||
|
}
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
curl_setopt_array($curl, array(
|
curl_setopt_array($curl, array(
|
||||||
CURLOPT_URL => $post_url,
|
CURLOPT_URL => $post_url,
|
||||||
@@ -43,7 +53,7 @@ class ApiCalls
|
|||||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||||
CURLOPT_POSTFIELDS => $data,
|
CURLOPT_POSTFIELDS => $data,
|
||||||
CURLOPT_HTTPHEADER => array(
|
CURLOPT_HTTPHEADER => array(
|
||||||
'Content-Type: application/json'
|
'Content-Type: application/json', $header_part
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
$response = curl_exec($curl);
|
$response = curl_exec($curl);
|
||||||
@@ -53,6 +63,8 @@ class ApiCalls
|
|||||||
|
|
||||||
public static function CurlPatch($data, $url){
|
public static function CurlPatch($data, $url){
|
||||||
$patch_url = env('APIBASEURL') . $url;
|
$patch_url = env('APIBASEURL') . $url;
|
||||||
|
$header_part = '';
|
||||||
|
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
|
|
||||||
curl_setopt_array($curl, array(
|
curl_setopt_array($curl, array(
|
||||||
@@ -66,7 +78,7 @@ class ApiCalls
|
|||||||
CURLOPT_CUSTOMREQUEST => 'PATCH',
|
CURLOPT_CUSTOMREQUEST => 'PATCH',
|
||||||
CURLOPT_POSTFIELDS => $data,
|
CURLOPT_POSTFIELDS => $data,
|
||||||
CURLOPT_HTTPHEADER => array(
|
CURLOPT_HTTPHEADER => array(
|
||||||
'Content-Type: application/json'
|
'Content-Type: application/json', $header_part
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="fw-semibold">{{ $row->name}}</td>
|
<td class="fw-semibold">{{ $row->name}}</td>
|
||||||
<td class="recipient-cellss">
|
<td class="recipient-cellss">
|
||||||
<div class="fw-semibold">{{ $row->type}}</div>
|
<div class="fw-semibold">{{ $row->type }}</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-wrap text-break apiKeyCell" style="max-width: 100px;">
|
<td class="text-wrap text-break apiKeyCell" style="max-width: 100px;">
|
||||||
<i class="bi bi-eye viewApiKeyIcon"></i>
|
<i class="bi bi-eye viewApiKeyIcon"></i>
|
||||||
|
|||||||
@@ -57,34 +57,37 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
||||||
<script src="{{ url('public/libs/jquery-3.2.1.min.js') }}"></script>
|
<script src="{{ url('public/libs/jquery-3.2.1.min.js') }}"></script>
|
||||||
<script src="{{ url('public/libs/jquery-confirm/jquery-confirm.min.js') }}"></script>
|
<script src="{{ url('public/libs/jquery-confirm/jquery-confirm.min.js') }}"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||||
|
|
||||||
@yield('page-js')
|
@yield('page-js')
|
||||||
<script>
|
<script>
|
||||||
const myForm = document.getElementById('clientNewAppForm');
|
const myForm = document.getElementById('clientNewAppForm');
|
||||||
|
|
||||||
myForm.addEventListener('submit', function(e) {
|
myForm.addEventListener('submit', function(e) {
|
||||||
// 2. Stop the page reload
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// 3. Extract data from the form
|
|
||||||
const formData = new FormData(this);
|
const formData = new FormData(this);
|
||||||
const formAction = $(this).attr("action");
|
const formAction = $(this).attr("action");
|
||||||
// Convert to JSON if your API requires it (common for modern backends)
|
|
||||||
const data = Object.fromEntries(formData.entries());
|
const data = Object.fromEntries(formData.entries());
|
||||||
|
|
||||||
// 4. Execute the AJAX (Fetch) request
|
// 4. Execute the AJAX (Fetch) request
|
||||||
fetch(formAction, {
|
fetch(formAction, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json', // Inform server of JSON content
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json' // Expect JSON response
|
'Accept': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
console.log('Success:', result);
|
console.log('Success:', result);
|
||||||
// 5. Optional: Close modal or show success message
|
// $.alert('Data submitted successfully!');
|
||||||
alert('Data submitted successfully!');
|
Swal.fire({
|
||||||
|
title: "Sucess",
|
||||||
|
text: "New App successfully created",
|
||||||
|
icon: "success"
|
||||||
|
});
|
||||||
|
this.reset();
|
||||||
|
setTimeout(() => { location.reload(); }, 2000);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user