update marketing
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 5m14s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 17s
Build, Push and Deploy / deploy-staging (push) Successful in 41s
Build, Push and Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-05-14 11:55:22 +07:00
parent f80fcc4c1b
commit 05fd3230b8
448 changed files with 17545 additions and 5128 deletions

View File

@@ -0,0 +1,64 @@
<?php
namespace Modules\MarketingAddon\App\Services;
use Modules\MarketingAddon\App\Models\Template;
use Modules\MarketingAddon\App\Models\MessageReport;
use Modules\MarketingAddon\App\Jobs\SendNotificationJob;
class NotifyService
{
public function send(string $event, array $data, string $businessId)
{
$settings = get_option('notification_settings_' . $businessId);
if (!isset($settings[$event])) {
return;
}
$array = [];
foreach (['sms', 'whatsapp', 'email'] as $channel) {
// Check enabled in settings
if (empty($settings[$event][$channel]['enabled'])) {
continue;
}
// Check required data per channel
if (in_array($channel, ['sms', 'whatsapp']) && empty($data['phone'])) {
continue;
}
if ($channel === 'email' && empty($data['email'])) {
continue;
}
$array[] = $channel;
$template = Template::where('business_id', $businessId)->where('title', $event)->where('type', $channel)->first();
if (empty($template)) {
continue;
}
$notification = MessageReport::create([
'title' => $event,
'channel' => $channel,
'business_id' => $businessId,
'template_id' => $template->id,
'message' => $template->message,
]);
// Dispatch job
SendNotificationJob::dispatch(
data: $data,
channel: $channel,
template: $template,
businessId: $businessId,
notificationId: $notification->id,
)->onQueue('high');
}
return $array;
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Modules\MarketingAddon\App\Services;
use Exception;
use Modules\MarketingAddon\App\Models\Smsgateway;
class SmsService
{
public function send(string $phone, $template, array $data)
{
$gateways = Smsgateway::where('status', 1)->where('channel', 'sms')->where('business_id', $template->business_id)->get();
if (empty($gateways)) {
throw new \Exception('No active SMS gateway found for this business.');
}
$response = [
'status' => false,
'message' => 'Something went wrong, Please try again.'
];
$contents = $this->buildContent($template, $data);
foreach ($gateways as $gateway) {
$response = $gateway->namespace::send_message($gateway, $phone, $contents);
if (($response['status'] ?? false) === true) {
return;
}
}
throw new Exception('All SMS gateways failed');
}
protected function buildContent($template, array $data)
{
$message = $template->message;
foreach ($data as $key => $value) {
$message = str_replace('[' . $key . ']', $value, $message);
}
return $message;
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Modules\MarketingAddon\App\Services;
use Modules\MarketingAddon\App\Models\Smsgateway;
class WhatsAppService
{
/**
* Send WhatsApp campaign via AiSensy
*/
public function send(
string $phone,
object $template,
int $businessId,
string $name,
array $data = [],
) {
$gateways = Smsgateway::where('channel', 'whatsapp')
->where('business_id', $businessId)
->where('status', 1)
->get();
if (empty($gateways)) {
throw new \Exception('No active WhatsApp gateway found for this business.');
}
foreach ($gateways as $gateway) {
$gateway->namespace::send_message($gateway, $phone, $template, $name, $data);
}
}
}