File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed
Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Console \Commands ;
4+
5+ use App \Models \Article ;
6+ use App \Notifications \PostArticleToTelegram as PostArticleToTelegramNotification ;
7+ use Illuminate \Console \Command ;
8+ use Illuminate \Notifications \AnonymousNotifiable ;
9+
10+ class PostArticleToTelegram extends Command
11+ {
12+ protected $ signature = 'lcm:post-article-to-telegram ' ;
13+
14+ protected $ description = 'Posts the latest unshared article to Telegram ' ;
15+
16+ public function handle (AnonymousNotifiable $ notifiable ): void
17+ {
18+ if ($ article = Article::nexForSharingToTelegram ()) {
19+ $ notifiable ->notify (new PostArticleToTelegramNotification ($ article ));
20+ }
21+ }
22+ }
Original file line number Diff line number Diff line change @@ -330,4 +330,11 @@ public static function nextForSharing(): ?self
330330 ->first ();
331331 }
332332
333+ public static function nexForSharingToTelegram (): ?self
334+ {
335+ return self ::shared ()
336+ ->published ()
337+ ->orderBy ('submitted_at ' , 'asc ' )
338+ ->first ();
339+ }
333340}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Notifications ;
4+
5+ use App \Models \Article ;
6+ use Illuminate \Bus \Queueable ;
7+ use Illuminate \Notifications \Notification ;
8+ use NotificationChannels \Telegram \TelegramChannel ;
9+ use NotificationChannels \Telegram \TelegramMessage ;
10+
11+ class PostArticleToTelegram extends Notification
12+ {
13+ use Queueable;
14+
15+ public function __construct (public Article $ article )
16+ {
17+ }
18+
19+ public function via ($ notifiable )
20+ {
21+ return [TelegramChannel::class];
22+ }
23+
24+ public function toTelegram ($ notifiable )
25+ {
26+ return TelegramMessage::create ()
27+ ->to ('@laravelcm ' )
28+ ->content ("{$ this ->article ->title } " . route ('articles.show ' , $ this ->article ->slug ()));
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments