Skip to content
laravel-google-chat
Loading repository…

Google Chat Notification Channel

This package provides a modern, fluent Google Chat notification channel for Laravel 12.x and 13.x to send simple text notifications, formatted markdown messages, and interactive rich cards.

Core Features

  • Simple & Formatted Text: Fluent formatting for bold, italic, strikethrough, monospace, hyperlinks, user mentions, and @all room alerts, plus GitHub-Flavoured Markdown conversion.
  • Rich Card Engine: Full support for interactive Google Chat cards with headers, sections, DecoratedText, ButtonList, Divider, Columns, and CardAction overflow menus.
  • Strict PHP 8.2 Backed Enums: Type-safety using ButtonType, Icon, ImageType, MessageReplyOption, and SelectionType enums.
  • Pluggable Transports: Built-in WebhookTransport (powered by Laravel's Http facade for seamless Http::fake() testing) and ServiceAccountTransport for OAuth REST authentication.
  • Message Updates & Threading: Update existing sent card messages via PATCH and manage thread replies effortlessly.
  • Fluent Builder Closures: Intuitive $message->card(fn (Card $c) => ...) and $card->section(fn (Section $s) => ...) builder closures.

Requirements

  • PHP: ^8.2 or ^8.3 / ^8.4 / ^8.5
  • Laravel: ^12.0 or ^13.0

Installation

Install the package via Composer:

bash
composer require eighteen73/laravel-google-chat

Publish the configuration file to your project:

bash
php artisan vendor:publish --tag=google-chat-config

This creates config/google-chat.php in your application.

Quick Start Example

Add GoogleChatChannel::class to your notification's via() method:

php
namespace App\Notifications;

use Illuminate\Notifications\Notification;
use NotificationChannels\GoogleChat\GoogleChatChannel;
use NotificationChannels\GoogleChat\GoogleChatMessage;

class ServerAlertNotification extends Notification
{
    public function via(object $notifiable): array
    {
        return [
            GoogleChatChannel::class,
        ];
    }

    public function toGoogleChat(object $notifiable): GoogleChatMessage
    {
        return GoogleChatMessage::create()
            ->text('Server alert: High CPU utilisation detected!')
            ->bold('Host:')
            ->line('web-prod-01');
    }
}

Documentation Sitemap

Explore detailed practical guides for every aspect of the package:

  • Configuration & Transports: Set up default space aliases, webhook URLs, test space overrides, and Service Account REST drivers.
  • Service Account Setup: Step-by-step guide to setting up Google Cloud Service Accounts, Chat Apps, and JSON key files.
  • Simple Messages: Format text with fluent helpers, convert GitHub or GitLab Markdown, and mention users.
  • Card Messages: Build Cards v2 structures with headers, sections, and closure builders.
  • Widgets & Components: Explore DecoratedText, ButtonList, Divider, Columns, and icons.
  • Threading & Message Updates: Reply to existing threads and update/patch previously posted cards.