brandonjbegle/slack-app-laravel-notification-channel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

brandonjbegle/slack-app-laravel-notification-channel

最新稳定版本:v0.1.0

Composer 安装命令:

composer require brandonjbegle/slack-app-laravel-notification-channel

包简介

Laravel Notification Channel For Slack Apps.

README 文档

README

The first-party Laravel Slack channel only supports the limited Incoming Webhooks integration. This package uses the Chat Post Message api to send a message to any channel in your workspace as long as you have the Channel ID.

I have also made a Nova 4 package to easily retrieve Slack Channel IDs for use in this package here

This package is a WIP. Some Block types are implemented to make it easier to compose messages, but currently only one ( SectionBlock) allows (only, for now) arrays. I have provided an example Notification here

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require brandonjbegle/slack-app-laravel-notification-channel

Now publish config file:

php artisan vendor:publish --provider="BrandonJBegle\SlackNotificationChannel\SlackAppChannelServiceProvider"

Create a Slack App, install it to your workspace, and retrieve your bot token. Complete Instructions Here

Add the key and token to your .env file

SLACK_OAUTH_TOKEN=############################

Usage

Create a notification

class HealthStatusChangedNotification extends Notification
{
    use Queueable;

    private $site;
    private $prevStatus;
    private $newStatus;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Site $site, $prevStatus, $newStatus)
    {
        $this->site = $site;
        $this->prevStatus = $prevStatus;
        $this->newStatus = $newStatus;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param mixed $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [SlackAppChannel::class];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param mixed $notifiable
     * //     * @return SlackAppMessage
     */
    public function toSlackApp($notifiable)
    {
        $now = now()->setTimezone('America/New_York')->toDayDateTimeString();
        return (new SlackAppMessage())
            ->text($this->site->name . " health status changed: {$this->prevStatus} to {$this->newStatus}")
            ->blocks([
                (new HeaderBlock)
                    ->content('Health Status Changed'),
                (new ContextBlock)
                    ->elements([
                        (new ContextBlockImage)->text('text')->url('https://' . $this->site->name . '/favicon.ico'),
                        (new ContextBlockText)->type('plain_text')->content($this->site->name),
                    ]),
                (new SectionBlock)
                    ->text("Status changed from {$this->prevStatus} to {$this->newStatus}")
                    ->fields([
                        [
                            'type' => 'mrkdwn',
                            'text' => "*{$now}*"
                        ],
                    ])
            ]);
    }
}

Add Notifiable trait to your model

class Site extends Model
{
    use Notifiable;

Add routeNotificationForSlackApp method to your model

public function routeNotificationForSlackApp()
    {
        // If you use the Nova 4 field, this will get the id of the Channel, otherwise simply return the id
        if ($this->slack_notification_channel) {
            return $this->slack_notification_channel['value'] ?? null ;
        }
        return null;
    }

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固