deegitalbe/laravel-trustup-io-slack-notifications 问题修复 & 功能扩展

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

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

deegitalbe/laravel-trustup-io-slack-notifications

最新稳定版本:v2.0.0

Composer 安装命令:

composer require deegitalbe/laravel-trustup-io-slack-notifications

包简介

Basic versioned php package.

README 文档

README

This package enhances laravel slack notifications, allowing to send direct messages.

Compatibility

Laravel Package
8.x / 9.x 1.x
12.x 2.x

Installation

Require package

composer require deegitalbe/laravel-trustup-io-slack-notifications

Env variables

SLACK_API_TOKEN=

Usage

Configure your models

use Illuminate\Database\Eloquent\Model;
use Deegitalbe\LaravelTrustupIoSlackNotifications\Traits\Slack\SlackNotifiable;
use Deegitalbe\LaravelTrustupIoSlackNotifications\Contracts\Slack\SlackNotifiableContract;

use Illuminate\Notifications\Notification;

class User extends Model implements SlackNotifiableContract
{
    use SlackNotifiable;
}

Configure your notification

Extending slack notification

use Illuminate\Notifications\Messages\SlackMessage;
use Deegitalbe\LaravelTrustupIoSlackNotifications\SlackNotification;
use Deegitalbe\LaravelTrustupIoSlackNotifications\Enum\SlackChannel;

class OrderReceived extends SlackNotification
{
    public function slackChannel($notifiable): string|SlackChannel
    {
        return SlackChannel::PRODUCTS;
    }

    public function slackMessage(SlackMessage $message, $notifiable): SlackMessage
    {
        return $message->content("A new order has been made.");
    }
}

Implementing contract and using trait

use Illuminate\Notifications\Messages\SlackMessage;
use Deegitalbe\LaravelTrustupIoSlackNotifications\Enum\SlackChannel;
use Deegitalbe\LaravelTrustupIoSlackNotifications\Traits\Slack\IsSlackNotification;
use Deegitalbe\LaravelTrustupIoSlackNotifications\Contracts\Slack\SlackNotificationContract;

class OrderReceived extends Notification implements SlackNotificationContract
{
    use IsSlackNotification;

    public function slackChannel($notifiable): string|SlackChannel
    {
        return $notifiable->getSlackId();
    }

    public function slackMessage(SlackMessage $message, $notifiable): SlackMessage
    {
        return $message->content("A new order has been made.");
    }
}

Send notification to slack channel

// Create notification
<?php

namespace Deegitalbe\LaravelTrustupIoSlackNotifications\Tests\Utils\Notifications;

use Deegitalbe\LaravelTrustupIoSlackNotifications\SlackChannelNotification;
use Illuminate\Notifications\Messages\SlackMessage;

class TestingNotification extends SlackChannelNotification
{
    public function slackMessage(SlackMessage $message, $notifiable): SlackMessage
    {
        return $message->attachment(function ($attachment) {
            $attachment->color('#36a64f')
                ->author('🚨 New Activation Request')
                ->title("Tenant #test")
                ->fields([
                    'Enterprise' => "test",
                    'Account Type' => "test",
                    'Admin First Name' => "test",
                    'Admin Last Name' => "test",
                    'VAT Number' => "test",
                    'Created At' => "test",
                ])
                ->footer('TrustUp')
                ->footerIcon("test")
                ->timestamp(now());
        });
    }
}

// Send notification
SlackChannel::TECH_DEV->notify($notification);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固