File tree Expand file tree Collapse file tree 8 files changed +98
-45
lines changed Expand file tree Collapse file tree 8 files changed +98
-45
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ TORCHLIGHT_TOKEN=
73
73
MIX_TORCHLIGHT_TOKEN = " ${ TORCHLIGHT_TOKEN } "
74
74
UNSPLASH_ACCESS_KEY =
75
75
TELEGRAM_BOT_TOKEN =
76
+ TELEGRAM_CHANNEL =
76
77
MEDIA_DISK = media
77
78
SENTRY_LARAVEL_DSN =
78
79
SENTRY_TRACES_SAMPLE_RATE =
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Events ;
4
+
5
+ use App \Models \Article ;
6
+ use Illuminate \Queue \SerializesModels ;
7
+
8
+ class ArticleWasSubmittedForApproval
9
+ {
10
+ use SerializesModels;
11
+
12
+ public function __construct (
13
+ public Article $ article
14
+ ) {
15
+ }
16
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace App \Http \Livewire \Articles ;
4
4
5
+ use App \Events \ArticleWasSubmittedForApproval ;
5
6
use App \Gamify \Points \PostCreated ;
6
7
use App \Models \Article ;
7
8
use App \Models \Tag ;
8
9
use App \Models \User ;
9
- use App \Notifications \SendSubmittedArticle ;
10
10
use App \Traits \WithArticleAttributes ;
11
11
use App \Traits \WithTagsAssociation ;
12
12
use Illuminate \Support \Facades \Auth ;
@@ -67,10 +67,9 @@ public function store()
67
67
$ article ->addMedia ($ this ->file ->getRealPath ())->toMediaCollection ('media ' );
68
68
}
69
69
70
- if ($ article ->submitted_at ) {
71
- // Envoi du mail à l'admin pour la validation de l'article.
72
- $ admin = User::findByEmailAddress ('monneylobe@gmail.com ' );
73
- Notification::send ($ admin , new SendSubmittedArticle ($ article ));
70
+ if ($ article ->isAwaitingApproval ()) {
71
+ // Envoi de la notification sur le channel Telegram pour la validation de l'article.
72
+ event (new ArticleWasSubmittedForApproval ($ article ));
74
73
75
74
session ()->flash ('status ' , 'Merci d \'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article. ' );
76
75
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Listeners ;
4
+
5
+ use App \Events \ArticleWasSubmittedForApproval ;
6
+ use App \Notifications \ArticleSubmitted ;
7
+ use Illuminate \Notifications \AnonymousNotifiable ;
8
+
9
+ final class SendNewArticleNotification
10
+ {
11
+ public function __construct (private AnonymousNotifiable $ notifiable )
12
+ {
13
+ }
14
+
15
+ public function handle (ArticleWasSubmittedForApproval $ event ): void
16
+ {
17
+ $ this ->notifiable ->notify (new ArticleSubmitted ($ event ->article ));
18
+ }
19
+ }
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 \Contracts \Queue \ShouldQueue ;
8
+ use Illuminate \Notifications \Notification ;
9
+ use NotificationChannels \Telegram \TelegramChannel ;
10
+ use NotificationChannels \Telegram \TelegramMessage ;
11
+
12
+ class ArticleSubmitted extends Notification implements ShouldQueue
13
+ {
14
+ use Queueable;
15
+
16
+ public function __construct (private Article $ article )
17
+ {
18
+ }
19
+
20
+ public function via ($ notifiable )
21
+ {
22
+ if (
23
+ ! empty (config ('services.telegram-bot-api.token ' )) &&
24
+ ! empty (config ('services.telegram-bot-api.channel ' ))
25
+ ) {
26
+ return [TelegramChannel::class];
27
+ }
28
+
29
+ return [];
30
+ }
31
+
32
+ public function toTelegram ($ notifiable )
33
+ {
34
+ $ url = route ('articles.show ' , $ this ->article ->slug ());
35
+
36
+ return TelegramMessage::create ()
37
+ ->to (config ('services.telegram-bot-api.channel ' ))
38
+ ->content ($ this ->content ())
39
+ ->button ('Voir l \'article ' , $ url );
40
+ }
41
+
42
+ private function content (): string
43
+ {
44
+ $ content = "*Nouvel Article Soumis!* \n\n" ;
45
+ $ content .= 'Titre: ' .$ this ->article ->title ."\n" ;
46
+ $ content .= 'Par: [@ ' .$ this ->article ->author ->username .']( ' .route ('profile ' , $ this ->article ->author ->username ).') ' ;
47
+
48
+ return $ content ;
49
+ }
50
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2
2
3
3
namespace App \Providers ;
4
4
5
+ use App \Events \ArticleWasSubmittedForApproval ;
5
6
use App \Events \CommentWasAdded ;
6
7
use App \Events \ReplyWasCreated ;
7
8
use App \Events \ThreadWasCreated ;
8
9
use App \Listeners \NotifyMentionedUsers ;
9
10
use App \Listeners \PostNewThreadNotification ;
11
+ use App \Listeners \SendNewArticleNotification ;
10
12
use App \Listeners \SendNewCommentNotification ;
11
13
use App \Listeners \SendNewReplyNotification ;
12
14
use App \Listeners \SendNewThreadNotification ;
@@ -33,6 +35,9 @@ class EventServiceProvider extends ServiceProvider
33
35
SendNewThreadNotification::class,
34
36
PostNewThreadNotification::class,
35
37
],
38
+ ArticleWasSubmittedForApproval::class => [
39
+ SendNewArticleNotification::class,
40
+ ],
36
41
CommentWasAdded::class => [
37
42
SendNewCommentNotification::class,
38
43
],
Original file line number Diff line number Diff line change 42
42
'client_id ' => env ('TWITTER_CLIENT_ID ' ),
43
43
'client_secret ' => env ('TWITTER_CLIENT_SECRET ' ),
44
44
'redirect ' => env ('TWITTER_REDIRECT ' ),
45
- 'consumer_key ' => env ('TWITTER_CONSUMER_KEY ' ),
46
- 'consumer_secret ' => env ('TWITTER_CONSUMER_SECRET ' ),
45
+ 'consumer_key ' => env ('TWITTER_CLIENT_ID ' ),
46
+ 'consumer_secret ' => env ('TWITTER_CLIENT_SECRET ' ),
47
47
'access_token ' => env ('TWITTER_ACCESS_TOKEN ' ),
48
48
'access_secret ' => env ('TWITTER_ACCESS_SECRET ' ),
49
49
'scopes ' => [],
56
56
57
57
'telegram-bot-api ' => [
58
58
'token ' => env ('TELEGRAM_BOT_TOKEN ' ),
59
+ 'channel ' => env ('TELEGRAM_CHANNEL ' ),
59
60
],
60
61
61
62
];
You can’t perform that action at this time.
0 commit comments