Skip to content

Commit

Permalink
Telegram notifications, gpt-4o and landing updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsa authored May 13, 2024
2 parents 415f28d + 154b013 commit 20049fd
Show file tree
Hide file tree
Showing 20 changed files with 261 additions and 66 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
TELEGRAM_BOT_TOKEN=
TELEGRAM_ADMIN_CHAT_ID=

DB_CONNECTION=pgsql
DB_HOST=db
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jobs:
LEMON_SQUEEZY_ROLLOVER_CLASSIC: ${{ secrets.LEMON_SQUEEZY_ROLLOVER_CLASSIC }}
LEMON_SQUEEZY_ROLLOVER_POWER: ${{ secrets.LEMON_SQUEEZY_ROLLOVER_POWER }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_ADMIN_CHAT_ID: ${{ secrets.TELEGRAM_ADMIN_CHAT_ID }}
- uses: ./.github/workflows/jobs/build-and-push
with:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
Expand Down Expand Up @@ -160,6 +161,7 @@ jobs:
LEMON_SQUEEZY_ROLLOVER_CLASSIC: ${{ secrets.LEMON_SQUEEZY_ROLLOVER_CLASSIC }}
LEMON_SQUEEZY_ROLLOVER_POWER: ${{ secrets.LEMON_SQUEEZY_ROLLOVER_POWER }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_ADMIN_CHAT_ID: ${{ secrets.TELEGRAM_ADMIN_CHAT_ID }}
- uses: ./.github/workflows/jobs/deploy
with:
SERVER_IP: ${{ secrets.SERVER_IP }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/jobs/build-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ inputs:
required: true
TELEGRAM_BOT_TOKEN:
required: true
TELEGRAM_ADMIN_CHAT_ID:
required: true

runs:
using: "composite"
Expand Down Expand Up @@ -178,3 +180,4 @@ runs:
sed -i "s|LEMON_SQUEEZY_ROLLOVER_CLASSIC=.*|LEMON_SQUEEZY_ROLLOVER_CLASSIC=${{ inputs.LEMON_SQUEEZY_ROLLOVER_CLASSIC }}|" .env
sed -i "s|LEMON_SQUEEZY_ROLLOVER_POWER=.*|LEMON_SQUEEZY_ROLLOVER_POWER=${{ inputs.LEMON_SQUEEZY_ROLLOVER_POWER }}|" .env
sed -i "s|TELEGRAM_BOT_TOKEN=.*|TELEGRAM_BOT_TOKEN=${{ inputs.TELEGRAM_BOT_TOKEN }}|" .env
sed -i "s|TELEGRAM_ADMIN_CHAT_ID=.*|TELEGRAM_ADMIN_CHAT_ID=${{ inputs.TELEGRAM_ADMIN_CHAT_ID }}|" .env
2 changes: 1 addition & 1 deletion app/Jobs/GenerateCalendarJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function handle(): void
private function generateOpenAIResponse(string $systemPrompt): CreateResponse
{
return OpenAI::chat()->create([
'model' => 'gpt-4-turbo-2024-04-09',
'model' => 'gpt-4o',
'messages' => [
['role' => 'system', 'content' => $systemPrompt],
['role' => 'user', 'content' => $this->icsEvent->prompt],
Expand Down
30 changes: 30 additions & 0 deletions app/Notifications/Telegram/Admin/BackupHasFailedNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Notifications\Telegram\Admin;

use NotificationChannels\Telegram\TelegramMessage;
use Spatie\Backup\Events\BackupHasFailed;
use Spatie\Backup\Notifications\BaseNotification;

class BackupHasFailedNotification extends BaseNotification
{
public function __construct(public BackupHasFailed $event)
{
}

public function toTelegram($notifiable): \NotificationChannels\Telegram\TelegramBase|TelegramMessage
{
$telegramMessage = TelegramMessage::create()
->to(config('backup.notifications.telegram.chat_id'))
->content(trans('backup::notifications.backup_failed_subject', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.backup_failed_body', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.exception_message', ['message' => $this->event->exception->getMessage()]))
->line(trans('backup::notifications.exception_trace', ['trace' => $this->event->exception->getTraceAsString()]));

$this->backupDestinationProperties()->each(function ($value, $name) use ($telegramMessage) {
$telegramMessage->line("{$name}: {$value}");
});

return $telegramMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Notifications\Telegram\Admin;

use NotificationChannels\Telegram\TelegramMessage;
use Spatie\Backup\Events\BackupWasSuccessful;
use Spatie\Backup\Notifications\BaseNotification;

class BackupWasSuccessfulNotification extends BaseNotification
{
public function __construct(public BackupWasSuccessful $event)
{
}

public function toTelegram($notifiable): \NotificationChannels\Telegram\TelegramBase|TelegramMessage
{
$telegramMessage = TelegramMessage::create()
->to(config('backup.notifications.telegram.chat_id'))
->content(trans('backup::notifications.backup_successful_subject_title'));

$this->backupDestinationProperties()->each(function ($value, $name) use ($telegramMessage) {
$telegramMessage->line("{$name}: {$value}");
});

return $telegramMessage;
}
}
30 changes: 30 additions & 0 deletions app/Notifications/Telegram/Admin/CleanupHasFailedNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Notifications\Telegram\Admin;

use NotificationChannels\Telegram\TelegramMessage;
use Spatie\Backup\Events\CleanupHasFailed;
use Spatie\Backup\Notifications\BaseNotification;

class CleanupHasFailedNotification extends BaseNotification
{
public function __construct(public CleanupHasFailed $event)
{
}

public function toTelegram($notifiable): \NotificationChannels\Telegram\TelegramBase|TelegramMessage
{
$telegramMessage = TelegramMessage::create()
->to(config('backup.notifications.telegram.chat_id'))
->content(trans('backup::notifications.cleanup_failed_subject', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.cleanup_failed_body', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.exception_message', ['message' => $this->event->exception->getMessage()]))
->line(trans('backup::notifications.exception_trace', ['trace' => $this->event->exception->getTraceAsString()]));

$this->backupDestinationProperties()->each(function ($value, $name) use ($telegramMessage) {
$telegramMessage->line("{$name}: {$value}");
});

return $telegramMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Notifications\Telegram\Admin;

use NotificationChannels\Telegram\TelegramMessage;
use Spatie\Backup\Events\CleanupWasSuccessful;
use Spatie\Backup\Notifications\BaseNotification;

class CleanupWasSuccessfulNotification extends BaseNotification
{
public function __construct(public CleanupWasSuccessful $event)
{
}

public function toTelegram($notifiable): \NotificationChannels\Telegram\TelegramBase|TelegramMessage
{
$telegramMessage = TelegramMessage::create()
->to(config('backup.notifications.telegram.chat_id'))
->content(trans('backup::notifications.cleanup_successful_subject', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.cleanup_successful_body', ['application_name' => $this->applicationName(), 'disk_name' => $this->diskName()]));

$this->backupDestinationProperties()->each(function ($value, $name) use ($telegramMessage) {
$telegramMessage->line("{$name}: {$value}");
});

return $telegramMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Notifications\Telegram\Admin;

use NotificationChannels\Telegram\TelegramMessage;
use Spatie\Backup\Events\HealthyBackupWasFound;
use Spatie\Backup\Notifications\BaseNotification;

class HealthyBackupWasFoundNotification extends BaseNotification
{
public function __construct(public HealthyBackupWasFound $event)
{
}

public function toTelegram($notifiable): \NotificationChannels\Telegram\TelegramBase|TelegramMessage
{
$telegramMessage = TelegramMessage::create()
->to(config('backup.notifications.telegram.chat_id'))
->content(trans('backup::notifications.healthy_backup_found_subject', ['application_name' => $this->applicationName(), 'disk_name' => $this->diskName()]))
->line(trans('backup::notifications.healthy_backup_found_body', ['application_name' => $this->applicationName()]));

$this->backupDestinationProperties()->each(function ($value, $name) use ($telegramMessage) {
$telegramMessage->line("{$name}: {$value}");
});

return $telegramMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Notifications\Telegram\Admin;

use NotificationChannels\Telegram\TelegramMessage;
use Spatie\Backup\Events\UnhealthyBackupWasFound;
use Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFoundNotification as SpatieUnhealthyBackupWasFoundNotification;

class UnhealthyBackupWasFoundNotification extends SpatieUnhealthyBackupWasFoundNotification
{
public function __construct(public UnhealthyBackupWasFound $event)
{
parent::__construct($event);
}

public function toTelegram($notifiable): \NotificationChannels\Telegram\TelegramBase|TelegramMessage
{
$telegramMessage = TelegramMessage::create()
->to(config('backup.notifications.telegram.chat_id'))
->content(trans('backup::notifications.unhealthy_backup_found_subject', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.unhealthy_backup_found_body', ['application_name' => $this->applicationName(), 'disk_name' => $this->diskName()]))
->line($this->problemDescription());

$this->backupDestinationProperties()->each(function ($value, $name) use ($telegramMessage) {
$telegramMessage->line("{$name}: {$value}");
});

if ($this->failure()->wasUnexpected()) {
$telegramMessage
->line('Health check: ' . $this->failure()->healthCheck()->name())
->line(trans('backup::notifications.exception_message', ['message' => $this->failure()->exception()->getMessage()]))
->line(trans('backup::notifications.exception_trace', ['trace' => $this->failure()->exception()->getTraceAsString()]));
}

return $telegramMessage;
}
}
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions config/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@
'notifications' => [

'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailedNotification::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFoundNotification::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupHasFailedNotification::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessfulNotification::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\HealthyBackupWasFoundNotification::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupWasSuccessfulNotification::class => ['mail'],
\App\Notifications\Telegram\Admin\BackupHasFailedNotification::class => ['telegram'],
\App\Notifications\Telegram\Admin\UnhealthyBackupWasFoundNotification::class => ['telegram'],
\App\Notifications\Telegram\Admin\CleanupHasFailedNotification::class => ['telegram'],
\App\Notifications\Telegram\Admin\BackupWasSuccessfulNotification::class => ['telegram'],
\App\Notifications\Telegram\Admin\HealthyBackupWasFoundNotification::class => ['telegram'],
\App\Notifications\Telegram\Admin\CleanupWasSuccessfulNotification::class => ['telegram'],
],

/*
Expand All @@ -208,14 +208,18 @@
'notifiable' => \Spatie\Backup\Notifications\Notifiable::class,

'mail' => [
'to' => env('ADMIN_EMAIL', null),
'to' => env('ADMIN_EMAIL'),

'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
],

'telegram' => [
'chat_id' => env('TELEGRAM_ADMIN_CHAT_ID'),
],

'slack' => [
'webhook_url' => '',

Expand Down
Empty file.
Binary file added public/home/usage/concert-calendized.webp
Binary file not shown.
Binary file added public/home/usage/event-calendized.webp
Binary file not shown.
Binary file added public/home/usage/flight-calendized.webp
Binary file not shown.
Binary file added public/home/usage/tour-calendized.webp
Binary file not shown.
Loading

0 comments on commit 20049fd

Please sign in to comment.