Error when trying to send a notification to my slack with Laravel 5.8
Asked Answered
A

2

5

I try to send a simple slack notification on my channel to know when a customer buy something or register but i've got an error and i can't find any solution on the web.

That's my notification SlackNotification.php :

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;

class SlackNotification extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['slack'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\SlackMessage
     */
    public function toSlack($notifiable)
    {

        return (new SlackMessage)
                ->from('Ghost', ':ghost:')
                ->to('#new-user-notification')
                ->content('Hello World !');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

I also put update User.php like the documentation asked (with my personnal code of course)

public function routeNotificationForSlack($notification)
{
    return 'https://hooks.slack.com/services/XXXXXXXXXXXX';
}

Then when a customer buy something on my website

$user->notify(new SlackNotification);

All the use are correct.

Even if I am making the notification with the facade like this

\Notification::route('slack', env('SLACK_HOOK'))->notify(new SlackNotification());

I've got this result every time :

InvalidArgumentException Driver [slack] not supported.
Alister answered 18/10, 2019 at 12:39 Comment(0)
A
9

The composer was not update... Here the solution i've found !

composer require laravel/slack-notification-channel
Alister answered 18/10, 2019 at 13:55 Comment(0)
D
1

In my case, I had a Homestead VM with only 2048 MB RAM. When I ran composer require laravel/slack-notification-channel first time, it failed due to lack of memory, but suddenly it managed to install the package, but this above-mentioned error persisted after testing.

Then I had to turn off my VM, temporarily upgrade its RAM to 4096 MB, edit Homestead.yaml to recognize these same 4096 MB, then I turned it on again, and once I was connected via SSH I ran composer require laravel/slack-notification-channel again, then composer dumpautoload and composer install. As my machine has limited resources, I had to restart it with 2048 MB again, after reverting all this changes related to the temporary RAM upgrade.

Once it was up, I tested and then it worked perfectly. I believe the package wasn't well installed, or it was corrupted, or something like that.

Domella answered 13/7, 2020 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.