feat: send internal notification to discord
This commit is contained in:
parent
d15e1bcc7d
commit
3ab38e69fc
@ -29,6 +29,7 @@ public function handle(): void
|
|||||||
try {
|
try {
|
||||||
$this->cleanup_waitlist();
|
$this->cleanup_waitlist();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
send_internal_notification('CleanupInstanceStuffsJob failed with error: ' . $e->getMessage());
|
||||||
ray($e->getMessage());
|
ray($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ public function handle()
|
|||||||
->html((string) $mail->render())
|
->html((string) $mail->render())
|
||||||
);
|
);
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
|
send_internal_notification('SendConfirmationForWaitlistJob failed with error: ' . $th->getMessage());
|
||||||
ray($th->getMessage());
|
ray($th->getMessage());
|
||||||
throw $th;
|
throw $th;
|
||||||
}
|
}
|
||||||
|
27
app/Notifications/Internal/GeneralNotification.php
Normal file
27
app/Notifications/Internal/GeneralNotification.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications\Internal;
|
||||||
|
|
||||||
|
use App\Notifications\Channels\DiscordChannel;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
|
class GeneralNotification extends Notification implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
public function __construct(public string $message)
|
||||||
|
{}
|
||||||
|
|
||||||
|
public function via(object $notifiable): array
|
||||||
|
{
|
||||||
|
$channels[] = DiscordChannel::class;
|
||||||
|
return $channels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toDiscord(): string
|
||||||
|
{
|
||||||
|
return $this->message;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\InstanceSettings;
|
use App\Models\InstanceSettings;
|
||||||
|
use App\Models\Team;
|
||||||
|
use App\Notifications\Internal\GeneralNotification;
|
||||||
|
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
@ -8,7 +11,6 @@
|
|||||||
use Nubs\RandomNameGenerator\All;
|
use Nubs\RandomNameGenerator\All;
|
||||||
use Poliander\Cron\CronExpression;
|
use Poliander\Cron\CronExpression;
|
||||||
use Visus\Cuid2\Cuid2;
|
use Visus\Cuid2\Cuid2;
|
||||||
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
|
|
||||||
|
|
||||||
function application_configuration_dir(): string
|
function application_configuration_dir(): string
|
||||||
{
|
{
|
||||||
@ -194,3 +196,12 @@ function validate_cron_expression($expression_to_validate): bool
|
|||||||
}
|
}
|
||||||
return $isValid;
|
return $isValid;
|
||||||
}
|
}
|
||||||
|
function send_internal_notification(string $message): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$team = Team::find(0);
|
||||||
|
$team->notify(new GeneralNotification('👀 Internal notifications: ' . $message));
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
ray($th->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -174,7 +174,6 @@
|
|||||||
return general_error_handler(err: $e);
|
return general_error_handler(err: $e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/waitlist/confirm', function () {
|
Route::get('/waitlist/confirm', function () {
|
||||||
$email = request()->get('email');
|
$email = request()->get('email');
|
||||||
$confirmation_code = request()->get('confirmation_code');
|
$confirmation_code = request()->get('confirmation_code');
|
||||||
@ -184,6 +183,7 @@
|
|||||||
if ($found && !$found->verified && $found->created_at > now()->subMinutes(config('constants.waitlist.confirmation_valid_for_minutes'))) {
|
if ($found && !$found->verified && $found->created_at > now()->subMinutes(config('constants.waitlist.confirmation_valid_for_minutes'))) {
|
||||||
$found->verified = true;
|
$found->verified = true;
|
||||||
$found->save();
|
$found->save();
|
||||||
|
send_internal_notification('Waitlist confirmed: ' . $email);
|
||||||
return 'Thank you for confirming your email address. We will notify you when you are next in line.';
|
return 'Thank you for confirming your email address. We will notify you when you are next in line.';
|
||||||
}
|
}
|
||||||
return redirect()->route('dashboard');
|
return redirect()->route('dashboard');
|
||||||
@ -199,6 +199,7 @@
|
|||||||
$found = Waitlist::where('uuid', $confirmation_code)->where('email', $email)->first();
|
$found = Waitlist::where('uuid', $confirmation_code)->where('email', $email)->first();
|
||||||
if ($found && !$found->verified) {
|
if ($found && !$found->verified) {
|
||||||
$found->delete();
|
$found->delete();
|
||||||
|
send_internal_notification('Waitlist cancelled: ' . $email);
|
||||||
return 'Your email address has been removed from the waitlist.';
|
return 'Your email address has been removed from the waitlist.';
|
||||||
}
|
}
|
||||||
return redirect()->route('dashboard');
|
return redirect()->route('dashboard');
|
||||||
@ -250,6 +251,7 @@
|
|||||||
case 'subscription_updated':
|
case 'subscription_updated':
|
||||||
case 'subscription_resumed':
|
case 'subscription_resumed':
|
||||||
case 'subscription_unpaused':
|
case 'subscription_unpaused':
|
||||||
|
send_internal_notification('Subscription created or updated: ' . $subscription_id . ' for team ' . $team_id . ' with status ' . $status);
|
||||||
$subscription = Subscription::updateOrCreate([
|
$subscription = Subscription::updateOrCreate([
|
||||||
'team_id' => $team_id,
|
'team_id' => $team_id,
|
||||||
], [
|
], [
|
||||||
@ -271,6 +273,7 @@
|
|||||||
case 'subscription_expired':
|
case 'subscription_expired':
|
||||||
$subscription = Subscription::where('team_id', $team_id)->where('lemon_order_id', $order_id)->first();
|
$subscription = Subscription::where('team_id', $team_id)->where('lemon_order_id', $order_id)->first();
|
||||||
if ($subscription) {
|
if ($subscription) {
|
||||||
|
send_internal_notification('Subscription cancelled or paused: ' . $subscription_id . ' for team ' . $team_id . ' with status ' . $status);
|
||||||
$subscription->update([
|
$subscription->update([
|
||||||
'lemon_status' => $status,
|
'lemon_status' => $status,
|
||||||
'lemon_trial_ends_at' => $trial_ends_at,
|
'lemon_trial_ends_at' => $trial_ends_at,
|
||||||
@ -281,11 +284,13 @@
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$webhook->update([
|
$webhook->update([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
]);
|
]);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ray($e->getMessage());
|
ray($e->getMessage());
|
||||||
|
send_internal_notification('Subscription webhook failed: ' . $e->getMessage());
|
||||||
$webhook->update([
|
$webhook->update([
|
||||||
'status' => 'failed',
|
'status' => 'failed',
|
||||||
'failure_reason' => $e->getMessage(),
|
'failure_reason' => $e->getMessage(),
|
||||||
|
Loading…
Reference in New Issue
Block a user