feat: enhance messaging system to support multiple channels including email and inbox
This commit is contained in:
parent
43a92c5d3b
commit
bad0545be5
@ -46,7 +46,7 @@ class Message
|
||||
$txts = str_split($txt, 160);
|
||||
try {
|
||||
foreach ($txts as $txt) {
|
||||
self::sendSMS($config['sms_url'], $phone, $txt);
|
||||
self::sendSMS( $phone, $txt);
|
||||
self::logMessage('SMS', $phone, $txt, 'Success');
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
@ -396,9 +396,11 @@ class Message
|
||||
$v->body = nl2br($body);
|
||||
$v->save();
|
||||
self::logMessage("Inbox", $user->username, $body, "Success");
|
||||
return true;
|
||||
} catch (Throwable $e) {
|
||||
$errorMessage = Lang::T("Error adding message to inbox: " . $e->getMessage());
|
||||
self::logMessage('Inbox', $user->username, $body, 'Error', $errorMessage);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,6 +201,8 @@ EOT;
|
||||
['tbl_user_recharges.customer_id', 'customer_id'],
|
||||
['tbl_customers.fullname', 'fullname'],
|
||||
['tbl_customers.username', 'username'],
|
||||
['tbl_customers.email', 'email'],
|
||||
['tbl_customers.service_type','service_type'],
|
||||
]);
|
||||
$customers = $query->find_array();
|
||||
} else {
|
||||
@ -288,7 +290,13 @@ EOT;
|
||||
$totalSMSFailed = 0;
|
||||
$totalWhatsappSent = 0;
|
||||
$totalWhatsappFailed = 0;
|
||||
$totalEmailSent = 0;
|
||||
$totalEmailFailed = 0;
|
||||
$totalInboxSent = 0;
|
||||
$totalInboxFailed = 0;
|
||||
$batchStatus = [];
|
||||
$subject = Lang::T('Notification Message');
|
||||
$form = 'Admin';
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
$currentMessage = str_replace(
|
||||
@ -311,14 +319,14 @@ EOT;
|
||||
if ($test) {
|
||||
$batchStatus[] = [
|
||||
'name' => $customer['fullname'],
|
||||
'phone' => $customer['phonenumber'],
|
||||
'channel' => 'Test Channel',
|
||||
'status' => 'Test Mode',
|
||||
'message' => $currentMessage,
|
||||
'service' => $service,
|
||||
'router' => $routerName,
|
||||
];
|
||||
} else {
|
||||
if ($via == 'sms' || $via == 'both') {
|
||||
if ($via === 'sms' || $via === 'both' || $via === 'all') {
|
||||
if (Message::sendSMS($customer['phonenumber'], $currentMessage)) {
|
||||
$totalSMSSent++;
|
||||
$batchStatus[] = ['name' => $customer['fullname'], 'phone' => $customer['phonenumber'], 'status' => 'SMS Sent', 'message' => $currentMessage];
|
||||
@ -328,13 +336,33 @@ EOT;
|
||||
}
|
||||
}
|
||||
|
||||
if ($via == 'wa' || $via == 'both') {
|
||||
if ($via === 'wa' || $via == 'both' || $via === 'all') {
|
||||
if (Message::sendWhatsapp($customer['phonenumber'], $currentMessage)) {
|
||||
$totalWhatsappSent++;
|
||||
$batchStatus[] = ['name' => $customer['fullname'], 'phone' => $customer['phonenumber'], 'status' => 'WhatsApp Sent', 'message' => $currentMessage];
|
||||
$batchStatus[] = ['name' => $customer['fullname'], 'channel' => $customer['phonenumber'], 'status' => 'WhatsApp Sent', 'message' => $currentMessage];
|
||||
} else {
|
||||
$totalWhatsappFailed++;
|
||||
$batchStatus[] = ['name' => $customer['fullname'], 'phone' => $customer['phonenumber'], 'status' => 'WhatsApp Failed', 'message' => $currentMessage];
|
||||
$batchStatus[] = ['name' => $customer['fullname'], 'channel' => $customer['phonenumber'], 'status' => 'WhatsApp Failed', 'message' => $currentMessage];
|
||||
}
|
||||
}
|
||||
|
||||
if ($via === 'email' || $via === 'all') {
|
||||
if (Message::sendEmail($customer['email'], $subject, $currentMessage)) {
|
||||
$totalEmailSent++;
|
||||
$batchStatus[] = ['name' => $customer['fullname'], 'channel' => $customer['email'], 'status' => 'Email Sent', 'message' => $currentMessage];
|
||||
} else {
|
||||
$totalEmailFailed++;
|
||||
$batchStatus[] = ['name' => $customer['fullname'], 'channel' => $customer['email'], 'status' => 'Email Failed', 'message' => $currentMessage];
|
||||
}
|
||||
}
|
||||
|
||||
if ($via === 'inbox' || $via === 'all') {
|
||||
if (Message::addToInbox($customer['customer_id'], $subject, $currentMessage, $form)) {
|
||||
$totalInboxSent++;
|
||||
$batchStatus[] = ['name' => $customer['fullname'], 'channel' => 'Inbox', 'status' => 'Inbox Message Sent', 'message' => $currentMessage];
|
||||
} else {
|
||||
$totalInboxFailed++;
|
||||
$batchStatus[] = ['name' => $customer['fullname'], 'channel' => 'Inbox', 'status' => 'Inbox Message Failed', 'message' => $currentMessage];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -349,8 +377,8 @@ EOT;
|
||||
'page' => $page + 1,
|
||||
'batchStatus' => $batchStatus,
|
||||
'message' => $currentMessage,
|
||||
'totalSent' => $totalSMSSent + $totalWhatsappSent,
|
||||
'totalFailed' => $totalSMSFailed + $totalWhatsappFailed,
|
||||
'totalSent' => $totalSMSSent + $totalWhatsappSent + $totalEmailSent + $totalInboxSent,
|
||||
'totalFailed' => $totalSMSFailed + $totalWhatsappFailed + $totalEmailFailed + $totalInboxFailed,
|
||||
'hasMore' => $hasMore,
|
||||
'service' => $service,
|
||||
'router' => $routerName,
|
||||
|
@ -381,5 +381,9 @@
|
||||
"_Clear_old_logs_": " Clear old logs?",
|
||||
"Clean_up_Logs": "Clean up Logs",
|
||||
"ID": "ID",
|
||||
"Date_Sent": "Date Sent"
|
||||
"Date_Sent": "Date Sent",
|
||||
"Notification_Message": "Notification Message",
|
||||
"Share": "Share",
|
||||
"Previous": "Previous",
|
||||
"Email_not_sent__Mailer_Error__": "Email not sent, Mailer Error: "
|
||||
}
|
@ -50,6 +50,9 @@
|
||||
<label class="col-md-2 control-label">{Lang::T('Send Via')}</label>
|
||||
<div class="col-md-6">
|
||||
<select class="form-control" name="via" id="via">
|
||||
<option value="all" {if $via=='all' }selected{/if}>{Lang::T('All Channels')}</option>
|
||||
<option value="inbox" {if $via=='inbox' }selected{/if}>{Lang::T('Inbox')}</option>
|
||||
<option value="email" {if $via=='email' }selected{/if}>{Lang::T('Email')}</option>
|
||||
<option value="sms" {if $via=='sms' }selected{/if}>{Lang::T('SMS')}</option>
|
||||
<option value="wa" {if $via=='wa' }selected{/if}>{Lang::T('WhatsApp')}</option>
|
||||
<option value="both" {if $via=='both' }selected{/if}>{Lang::T('SMS and WhatsApp')}</option>
|
||||
@ -112,7 +115,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{Lang::T('Customer')}</th>
|
||||
<th>{Lang::T('Phone')}</th>
|
||||
<th>{Lang::T('Channel')}</th>
|
||||
<th>{Lang::T('Status')}</th>
|
||||
<th>{Lang::T('Message')}</th>
|
||||
<th>{Lang::T('Router')}</th>
|
||||
@ -186,7 +189,7 @@
|
||||
let statusClass = msg.status.includes('Failed') ? 'danger' : 'success';
|
||||
historyTable.row.add([
|
||||
msg.name,
|
||||
msg.phone,
|
||||
msg.channel,
|
||||
`<span class="text-${statusClass}">${msg.status}</span>`,
|
||||
msg.message || 'No message',
|
||||
msg.router ? msg.router : 'All Router',
|
||||
|
Loading…
x
Reference in New Issue
Block a user