tomlankhorst / hangouts-chat
Notifications from Laravel to Google Hangouts Chat
Requires
- php: >=7.2
- ext-json: *
- google/apiclient: ^2.0
- illuminate/notifications: ~5.5 || ~6.0 || ~7.0
- illuminate/support: ~5.5 || ~6.0 || ~7.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-10-27 17:34:41 UTC
README
This package makes it easy to send notifications using Google Hangouts Chat with Laravel 5.5+, 6.x and 7.x
Contents
Installation
Install this package with Composer:
composer require tomlankhorst/hangouts-chat
Setting up the Google Hangouts Chat service
In order to send messages using bots, you need to setup a webhook for a room.
Usage
Now you can use the channel in your via()
method inside the notification:
use NotificationChannels\GoogleHangoutsChat\HangoutsChatChannel; use NotificationChannels\GoogleHangoutsChat\HangoutsChatMessage; use Illuminate\Notifications\Notification; class ProjectCreated extends Notification { public function via($notifiable) { return ['hangoutsChat']; } public function toHangoutsChat$notifiable) { return HangoutsChatMessage::create() ->data([ 'text' => 'It is a test message!' ]); } }
Please look at Hangouts Chat Message Formats to understand how send the messages.
In order to let your Notification know which URL should receive the Webhook data, add the routeNotificationForHangoutsChat
method to your Notifiable model.
This method needs to return the URL where the notification Webhook will receive a POST request.
public function routeNotificationForHangoutsChat() { return 'https://chat.googleapis.com/v1/spaces/XXXXX-XXXXX/messages?key={key}&token={token}'; }
You can send to a dynamic Webhook URL on-fly using this syntax:
Notification::route('hangoutsChat', 'https://chat.googleapis.com/v1/spaces/XXXXX-XXXXX/messages?key={key}&token={token}') ->notify(new NotificationClass($params));
Available Message methods
data('')
: Accepts a JSON-encodable value for the Webhook body.query('')
: Accepts an associative array of query string values to add to the request.userAgent('')
: Accepts a string value for the Webhook user agent.header($name, $value)
: Sets additional headers to send with the POST Webhook.verify()
: Enable the SSL certificate verification or provide the path to a CA bundle
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Security
If you discover any security related issues, please email renan@4success.com.br instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.