FabRiviere / Livre_Or_Symfony

Développement du projet concernant un livre d'or sur les conférences. Projet du livre Symfony 6.
0 stars 0 forks source link

Discuter avec les admins - Messagerie instantanée #44

Closed FabRiviere closed 1 year ago

FabRiviere commented 1 year ago
FabRiviere commented 1 year ago

Installation du package Slack :

symfony composer req slack-notifier

Attribuer un jeton d'accès à Slack et le stocker dans les chaines secrètes :

symfony console secrets:set SLACK_DSN

et on fait pareil pour la production :

symfony console secrets:set SLACK_DSN --env=prod

Modification du fichier config/packages/notifier.yaml :

framework:
    notifier:
        chatter_transports:
            slack: '%env(SLACK_DSN)%'
        # texter_transports:
        channel_policy:
            # use chat/slack, chat/telegram, sms/twilio or sms/nexmo
            urgent: ['email']
            high: ['email']
            medium: ['email']
            low: ['email']
        admin_recipients:
            - { email: "%env(string:default:default_admin_email:ADMIN_EMAIL)%" }

Mise à jour de la classe CommentReviewNotification.php :

Implémentation de ChatNotificationInterface :

Ajout de la méthode getChannels() , sans oublier les use qui vont avec.

public function getChannels(RecipientInterface $recipient): array
    {
        if (preg_match('{\b(great|awesome)\b}i', $this->comment->getText())) {
            return ['email', 'chat/slack'];
        }

        $this->importance(Notification::IMPORTANCE_LOW);

        return ['email'];
    }