Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/takuya/php-laravel-slack-post

slack post by bot account as laravel plugin
https://github.com/takuya/php-laravel-slack-post

Last synced: 21 days ago
JSON representation

slack post by bot account as laravel plugin

Awesome Lists containing this project

README

        

# php-laravel-slack-post
slack post by bot account as laravel plugin

## Installing

```sh
composer config repositories.'php-laravel-slack-post' \
vcs https://github.com/takuya/php-laravel-slack-post
composer require takuya/php-laravel-slack-post:master
composer install
```
## Using
```sh
php artisan make:notification SampleNotify
php artisan make:command SlaclNotifySample
```
#### app/Notification/SampleNotify.php
```php
from( $this->username )
->to( $notifiable->getChannelName() )
->content('Hello World');
return $message;
}
}
```
### app/Commands/SlackNotifySample.php

```php
notify( new SampleNotify() );
}
}
```
### .env
```
SLACK_TOKEN=xoxb-12xxxxxxxxxxxxxx---xxx
SLACK_CHANNEL_NAME=通知テスト用
SLACK_CHANNEL_ID=C01AXXXXX
```
### config/slack.php
```php
env('SLACK_TOKEN'),
'channel_id'=>env('SLACK_CHANNEL_ID'),
'channel_name'=>env('SLACK_CHANNEL_NAME'),
];
```
### run
```sh
php artisan slack:notify
```

### result

![](https://user-images.githubusercontent.com/55338/184298814-74c1e7dd-46e0-407b-9722-a29e93eb093b.png)

## testing
```sh
## prepare
git clone https://github.com/takuya/php-laravel-slack-post
cd php-laravel-slack-post
composer install
## test
export SLACK_TOKEN=xoxb-XXXXX-XXXXXXXXXQoOS5sOv
export SLACK_CHANNEL_NAME='#通知テスト'
export SLACK_CHANNEL_ID=C01AXXXXX
vendor/bin/phpunit --filter testPostSlackChannel
```