Blog Detail

29

Jul
A Google Chat notification channel Pacakge for Laravel cover image

arrow_back A Google Chat notification channel Pacakge for Laravel

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.

Published at : 29-07-2021

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project