Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kawax/laravel-notification-mastodon
https://github.com/kawax/laravel-notification-mastodon
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kawax/laravel-notification-mastodon
- Owner: kawax
- License: mit
- Created: 2017-11-08T16:27:39.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-19T03:54:27.000Z (9 months ago)
- Last Synced: 2024-05-23T03:03:46.158Z (7 months ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Notification for Mastodon
## Requirements
- PHP >= 8.2
- Laravel >= 10.0## Installation
### Composer
```
composer require revolution/laravel-notification-mastodon
```## Config
Set default `domain` and `token`
### config/services.php
```php
'mastodon' => [
'domain' => env('MASTODON_DOMAIN'),
'token' => env('MASTODON_TOKEN'),
],
```### .env
```
MASTODON_DOMAIN=https://example.com
MASTODON_TOKEN=
```### TOKEN?
Go to your Mastodon's preferences page.## Usage
```php
status = $status;
}/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
*
* @return array
*/
public function via($notifiable)
{
return [MastodonChannel::class];
}/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
*
* @return MastodonMessage
*/
public function toMastodon($notifiable)
{
return MastodonMessage::create($this->status);
}
}
```### Send to specific one account
```php
use Illuminate\Support\Facades\Notification;
use Revolution\Laravel\Notification\Mastodon\MastodonRoute;Notification::route('mastodon', MastodonRoute::to(config('services.mastodon.domain'), config('services.mastodon.token')))
->notify(new MastodonNotification('test'));
```### Send to user's account
Get token by https://github.com/kawax/socialite-mastodon```php
use Illuminate\Notifications\Notifiable;
use Revolution\Laravel\Notification\Mastodon\MastodonRoute;class User extends Authenticatable
{
use Notifiable;public function routeNotificationForMastodon($notification): MastodonRoute
{
return MastodonRoute::to(domain: $this->domain, token: $this->token);
}
}
``````php
$user->notify(new MastodonNotification('test'));
```### Set options
https://docs.joinmastodon.org/methods/statuses/```php
public function toMastodon($notifiable)
{
$options = [
'visibility' => 'unlisted',
];return MastodonMessage::create($this->status)
->options($options);
}
```## LICENSE
MIT
Copyright kawax