Laravel Rocket Chat Notifications
Published on by Paul Redmond
Laravel Rocket Chat Notifications is a package that makes it easy to send notifications using RocketChat with Laravel 9+:
use Illuminate\Notifications\Notification;use TeamNiftyGmbh\RocketChatNotifications\Channels\RocketChatNotificationChannel;use TeamNiftyGmbh\RocketChatNotifications\Messages\RocketChatMessage; class TaskCompleted extends Notification{ public function via(mixed $notifiable): array { return [ RocketChatNotificationChannel::class ]; } public function toRocketChat($notifiable): RocketChatMessage { return RocketChatMessage::create('Test Message'); }}
The RocketChatMessage
class has convenient methods to formulate your RocketChat messages. Here's an example of a few of them, including adding an attachment:
public function toRocketChat($notifiable){ return RocketChatMessage::create('Test message') // optional if set in config ->to('channel_name') // optional if set in config ->from('access_token', 'rocket_chat_user_id') ->attachments([ RocketChatAttachment::create() ->imageUrl('test'), RocketChatAttachment::create([ 'image_url' => 'test' ]), new RocketChatAttachment(['image_url' => 'test']), // Or via array [ 'image_url' => 'test' ] ]);}
For a complete list of everything, you can do to format a message, check out the available methods in the readme.
Rocket.Chat is a communication platform with private chats, team chats, etc. and includes pricing options for the SaaS product and self-managed installations. You can learn more about this package, get full installation instructions, and view the source code on GitHub.
This package was submitted to our Laravel News Links section. Links is a place the community can post packages and tutorials around the Laravel ecosystem. Follow along on Twitter @LaravelLinks