A Google Chat notification channel Pacakge for Laravel

A Google Chat notification channel Pacakge for Laravel cover image

Laravel Notification Channel introduced a package known as Google Chat that makes it effortless to send notifications with Laravel 8.x

Installation

You can install the Google Chat notification channel quickly via Composer:

$ composer require laravel-notification-channels/google-chat

Usage

This package provides a way to send notifications utilizing a custom Google chat message channel:

// Create a super simple message
public function toGoogleChat($notifiable)
{
return GoogleChatMessage::create('An invoice was paid!');
}

You can also do simple formatting and advanced card layouts using the package’s provided classes:

// Simple text formatting and routing to a specific chat room
 GoogleChatMessage::create()
  ->text('Someone just paid an invoice... ')
  ->bold('Woo-hoo!')
  ->line('Looking for ')
  ->link(route('invoices'), 'the details?')
  ->to('sales_team'); // ... and route it to specific rooms
 // Advanced card layout
GoogleChatMessage::create()
->text('Invoice Paid! Here\'s the details:')
->card(
Card::create(
Section::create(
KeyValue::create('Amount', '$520.99', '#10004756')
->onClick(route('invoices'))
->button(TextButton::create(route('invoices'), 'View'))
	)
     )
);

Alternate Rooms

In the end, this package has the notion of “alternate” rooms, which you can configure to directly send messages to a Google chat room instead of the default:

// config/google-chat.php
return [
    'spaces' => [
        'sales_team' => 'https://chat.googleapis.com/sales-team-room?key=xxxxx',
        'dev_team' => 'https://chat.googleapis.com/dev-team-room?key=xxxxx',
        'executive' => 'https://chat.googleapis.com/executives?key=xxxxx',
    ]
]

// Usage
GoogleChatMessage::create()->to('dev_team')->...

Learn More

If you are interested to learn more about this package, you can get full installation instructions and the source code on GitHub. You can also review the Laravel Notification Channels documentation for complete setup and usage details.

Written by

Rizwan Aslam

Founder and CEO of CodeBrisk, with years of experience building web applications with Laravel and leading a team of expert developers.

More about Rizwan
Book a free call
Book a call with CodeBrisk