I am struggling with dispatching a Slack notification when the Notification class implements ShouldQueue.
This is how I dispatch the notification
/**
* Handles the sendout of booking request confirmation to the customer
*
* @return void
*/
public function sendCustomerNotifications()
{
$this->booking->customer->notify((new CustomerBookingRequested($this->booking)));
}
This is how I my CustomerBookingRequested notification class looks like
class CustomerBookingRequested extends Notification implements ShouldQueue
{
use Queueable;
private $booking;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Booking $booking)
{
//
$this->booking = $booking;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail','slack'];
}
...
//code for toMail
...
/**
* Get the Slack representation of the notification.
*
* @param mixed $notifiable
* @return IlluminateNotificationsMessageSlackMessage
*/
public function toSlack($notifiable)
{
return (new SlackMessage)
->success()
->content('New booking requested!');
}
My Customer Model uses Notifiable
class Customer extends Model implements HasLocalePreference
{
use HasFactory;
use Billable;
use SoftDeletes;
use Notifiable;
...
I also added to my Customer Model the routing method
/**
* Route notifications for the Slack channel.
*
* @param IlluminateNotificationsNotification $notification
* @return string
*/
public function routeNotificationForSlack($notification)
{
return env('SLACK_WEBHOOK');
}
When I remove implements ShouldQueue from my Notification class, both Slack and Mail Message is sent. When I keep implements ShouldQueue, the Mail message is sent, Slack message is not sent.
I basically want to send the customer a mail notification with a booking confirmation. At the same time I want to send a Slack message to the team's slack workspace. That's why I just added a static webhook URL in the customer model which is linked to the company's slack workspace.
I am a bit stuck here. Probably it's something obvious, but I can't find what I do wrong.
Thanks for your support!
Using Laravel 8.0 with "laravel/slack-notification-channel": "^2.3"
question from:
https://stackoverflow.com/questions/65863653/laravel-slack-notification-not-sent-when-using-implements-shouldqueue 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…