0

I am trying to send notifications to individual users with laravel 6 using the documentation here: https://laravel.com/docs/6.x/notifications#slack-notifications

My from and to functions don't seem to be doing anything.

// call notification
Notification::route('slack', $slackUrl)->notify(new notifyHours($event->user));

App\Notifications\notifyHours

// send DM
public function toSlack($notifiable)
 {
     return (new SlackMessage())
         ->from('Puffin', ':puffin:') // doesn't seem to do anything
         ->to('@U4KFXXXXX')           // doesn't seem to do anything
         ->image('https://XXX.png')
         ->content("Hi! Make sure I am up to date!")
         ->attachment(function(SlackAttachment $attachment) use ($notifiable) {
            $attachment->title('Your Hours', 'https://xxx/tasks')
                           ->fields([
                                'Today' => $this->hours->today.' hours',
                                'This Week' => 'You worked '.$this->hours->week. ' hours.'
                            ]);
         });
 }

How come the notification is sent to an entire channel, instead of the user I define in the to() function?

Andrew Walsh
  • 35
  • 10

1 Answers1

1

According to the code the to() method only accepts a channel not a user of that team.

   /**
     * Set the Slack channel the message should be sent to.
     *
     * @param  string  $channel
     * @return $this
     */
    public function to($channel)
    {
        $this->channel = $channel;

        return $this;
    }
Rando
  • 71
  • 3