fix support issue
This commit is contained in:
@@ -21,13 +21,21 @@ class SupportChatNotifyController extends Controller
|
||||
public function notify(Request $request)
|
||||
{
|
||||
$secret = (string) self::Config('chat_webhook_secret');
|
||||
$incoming = (string) $request->header('X-Chat-Webhook-Secret', '');
|
||||
$secret = app(ChatWebhookService::class)->sanitizeSecret($secret);
|
||||
$incoming = app(ChatWebhookService::class)->sanitizeSecret(
|
||||
(string) $request->header('X-Chat-Webhook-Secret', '')
|
||||
);
|
||||
|
||||
if ($secret === '' || ! hash_equals($secret, $incoming)) {
|
||||
Log::warning('support chat notify unauthorized', [
|
||||
'has_secret' => $secret !== '',
|
||||
'has_header' => $incoming !== '',
|
||||
]);
|
||||
return response()->json(['message' => 'unauthorized'], 401);
|
||||
}
|
||||
|
||||
if (! self::isSmsNotifEnabled('sms_notif_support_admin')) {
|
||||
Log::info('support chat notify skipped: sms_notif_support_admin disabled');
|
||||
return response()->json(['ok' => true, 'skipped' => 'disabled']);
|
||||
}
|
||||
|
||||
@@ -37,6 +45,7 @@ class SupportChatNotifyController extends Controller
|
||||
}
|
||||
|
||||
if (Cache::has(self::FOCUS_CACHE_PREFIX.$roomId)) {
|
||||
Log::info('support chat notify skipped: admin focused', ['room_id' => $roomId]);
|
||||
return response()->json(['ok' => true, 'skipped' => 'admin_focused']);
|
||||
}
|
||||
|
||||
@@ -52,14 +61,33 @@ class SupportChatNotifyController extends Controller
|
||||
$name = 'مشتری';
|
||||
}
|
||||
|
||||
$message = 'شما از '.$name.' پیام دارید';
|
||||
$companyName = trim((string) self::Config('name_fa'));
|
||||
if ($companyName === '') {
|
||||
$companyName = trim((string) self::Config('name'));
|
||||
}
|
||||
if ($companyName === '') {
|
||||
$companyName = 'پشتیبانی';
|
||||
}
|
||||
|
||||
$message = 'شما از '.$name." پیام دارید\n".$companyName;
|
||||
|
||||
$admins = User::where('send_sms', 1)->get();
|
||||
if ($admins->isEmpty()) {
|
||||
Log::warning('support chat notify: no admins with send_sms=1', ['room_id' => $roomId]);
|
||||
}
|
||||
|
||||
try {
|
||||
User::where('send_sms', 1)->get()->each(function ($admin) use ($message) {
|
||||
$admins->each(function ($admin) use ($message) {
|
||||
if (! empty($admin->mobile)) {
|
||||
$this->send($admin->mobile, $message);
|
||||
}
|
||||
});
|
||||
Log::info('support chat notify SMS sent', [
|
||||
'room_id' => $roomId,
|
||||
'name' => $name,
|
||||
'company' => $companyName,
|
||||
'admin_count' => $admins->count(),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('support chat SMS notify failed', [
|
||||
'room_id' => $roomId,
|
||||
@@ -109,10 +137,12 @@ class SupportChatNotifyController extends Controller
|
||||
*/
|
||||
public function ensureWebhook()
|
||||
{
|
||||
$ok = app(ChatWebhookService::class)->ensureRegistered();
|
||||
$service = app(ChatWebhookService::class);
|
||||
$ok = $service->ensureRegistered();
|
||||
|
||||
return response()->json([
|
||||
'ok' => $ok,
|
||||
'webhook_url' => $service->webhookUrl(),
|
||||
'message' => $ok ? 'webhook registered' : 'webhook register skipped or failed',
|
||||
], $ok ? 200 : 422);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user