diff --git a/.env.example b/.env.example index e2f618cc..e97e0854 100644 --- a/.env.example +++ b/.env.example @@ -73,6 +73,7 @@ TORCHLIGHT_TOKEN= MIX_TORCHLIGHT_TOKEN="${TORCHLIGHT_TOKEN}" UNSPLASH_ACCESS_KEY= TELEGRAM_BOT_TOKEN= +TELEGRAM_CHANNEL= MEDIA_DISK=media SENTRY_LARAVEL_DSN= SENTRY_TRACES_SAMPLE_RATE= diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 2b28a375..0691f4ac 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -26,7 +26,7 @@ protected function schedule(Schedule $schedule) { $schedule->command('media-library:delete-old-temporary-uploads')->daily(); $schedule->command('lcm:delete-old-unverified-users')->daily(); - // $schedule->command('lcm:post-article-to-twitter')->twiceDaily(12, 16); + $schedule->command('lcm:post-article-to-twitter')->twiceDaily(12, 16); $schedule->command('lcm:post-article-to-telegram')->everyFourHours(); $schedule->command('lcm:send-unverified-mails')->weeklyOn(1, '8:00'); $schedule->command('sitemap:generate')->daily(); diff --git a/app/Events/ArticleWasSubmittedForApproval.php b/app/Events/ArticleWasSubmittedForApproval.php new file mode 100644 index 00000000..7074c2af --- /dev/null +++ b/app/Events/ArticleWasSubmittedForApproval.php @@ -0,0 +1,16 @@ +addMedia($this->file->getRealPath())->toMediaCollection('media'); } - if ($article->submitted_at) { - // Envoi du mail à l'admin pour la validation de l'article. - $admin = User::findByEmailAddress('monneylobe@gmail.com'); - Notification::send($admin, new SendSubmittedArticle($article)); + if ($article->isAwaitingApproval()) { + // Envoi de la notification sur le channel Telegram pour la validation de l'article. + event(new ArticleWasSubmittedForApproval($article)); session()->flash('status', 'Merci d\'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article.'); } diff --git a/app/Listeners/SendNewArticleNotification.php b/app/Listeners/SendNewArticleNotification.php new file mode 100644 index 00000000..54b98c6d --- /dev/null +++ b/app/Listeners/SendNewArticleNotification.php @@ -0,0 +1,19 @@ +notifiable->notify(new ArticleSubmitted($event->article)); + } +} diff --git a/app/Notifications/ArticleSubmitted.php b/app/Notifications/ArticleSubmitted.php new file mode 100644 index 00000000..11508ce7 --- /dev/null +++ b/app/Notifications/ArticleSubmitted.php @@ -0,0 +1,50 @@ +article->slug()); + + return TelegramMessage::create() + ->to(config('services.telegram-bot-api.channel')) + ->content($this->content()) + ->button('Voir l\'article', $url); + } + + private function content(): string + { + $content = "*Nouvel Article Soumis!*\n\n"; + $content .= 'Titre: ' . $this->article->title . "\n"; + $content .= 'Par: [@' . $this->article->author->username . '](' . route('profile', $this->article->author->username) . ')'; + + return $content; + } +} diff --git a/app/Notifications/SendSubmittedArticle.php b/app/Notifications/SendSubmittedArticle.php deleted file mode 100644 index 2a021384..00000000 --- a/app/Notifications/SendSubmittedArticle.php +++ /dev/null @@ -1,38 +0,0 @@ -subject('Nouvelle soumission d\'article') - ->greeting('Bonjour Admin!') - ->line("Un nouvel article a été soumis par {$this->article->author->name}") - ->action('Afficher l\'article', route('articles.show', $this->article)) - ->line('Merci d\'avoir utilisé Laravel Cameroun!'); - } -} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index e4db7c52..8315eed5 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,11 +2,13 @@ namespace App\Providers; +use App\Events\ArticleWasSubmittedForApproval; use App\Events\CommentWasAdded; use App\Events\ReplyWasCreated; use App\Events\ThreadWasCreated; use App\Listeners\NotifyMentionedUsers; use App\Listeners\PostNewThreadNotification; +use App\Listeners\SendNewArticleNotification; use App\Listeners\SendNewCommentNotification; use App\Listeners\SendNewReplyNotification; use App\Listeners\SendNewThreadNotification; @@ -33,6 +35,9 @@ class EventServiceProvider extends ServiceProvider SendNewThreadNotification::class, PostNewThreadNotification::class, ], + ArticleWasSubmittedForApproval::class => [ + SendNewArticleNotification::class, + ], CommentWasAdded::class => [ SendNewCommentNotification::class, ], diff --git a/auth.json.example b/auth.json.example deleted file mode 100644 index b26c3e51..00000000 --- a/auth.json.example +++ /dev/null @@ -1,8 +0,0 @@ -{ - "http-basic": { - "satis.spatie.be": { - "username": "", - "password": "" - } - } -} diff --git a/config/services.php b/config/services.php index 4e5226f9..6816ab4b 100644 --- a/config/services.php +++ b/config/services.php @@ -42,8 +42,8 @@ 'client_id' => env('TWITTER_CLIENT_ID'), 'client_secret' => env('TWITTER_CLIENT_SECRET'), 'redirect' => env('TWITTER_REDIRECT'), - 'consumer_key' => env('TWITTER_CONSUMER_KEY'), - 'consumer_secret' => env('TWITTER_CONSUMER_SECRET'), + 'consumer_key' => env('TWITTER_CLIENT_ID'), + 'consumer_secret' => env('TWITTER_CLIENT_SECRET'), 'access_token' => env('TWITTER_ACCESS_TOKEN'), 'access_secret' => env('TWITTER_ACCESS_SECRET'), 'scopes' => [], @@ -56,6 +56,7 @@ 'telegram-bot-api' => [ 'token' => env('TELEGRAM_BOT_TOKEN'), + 'channel' => env('TELEGRAM_CHANNEL'), ], ]; diff --git a/resources/views/vendor/wireui/components/notifications.blade.php b/resources/views/vendor/wireui/components/notifications.blade.php index a16a6be9..9e2a2729 100644 --- a/resources/views/vendor/wireui/components/notifications.blade.php +++ b/resources/views/vendor/wireui/components/notifications.blade.php @@ -4,10 +4,9 @@ x-on:wireui:notification.window="addNotification($event.detail)" x-on:wireui:confirm-notification.window="addConfirmNotification($event.detail)" wire:ignore> -
+
@@ -59,8 +58,8 @@