GithubHelp home page GithubHelp logo

laravel / slack-notification-channel Goto Github PK

View Code? Open in Web Editor NEW
852.0 13.0 56.0 178 KB

Slack Notification Channel for laravel.

Home Page: https://laravel.com/docs/notifications#slack-notifications

License: MIT License

PHP 100.00%
laravel notifications slack

slack-notification-channel's Introduction

Laravel Slack Notification Channel

Build Status Total Downloads Latest Stable Version License

Official Documentation

Documentation for Laravel Slack Notification Channel can be found on the Laravel website.

Contributing

Thank you for considering contributing to Slack Notification Channel! The contribution guide can be found in the Laravel documentation.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Laravel Slack Notification Channel is open-sourced software licensed under the MIT license.

slack-notification-channel's People

Contributors

akalongman avatar bsn4 avatar claudiodekker avatar crynobone avatar driesvints avatar erikn69 avatar fideloper avatar gmponos avatar grahamcampbell avatar john-f-chamberlain avatar jubeki avatar lptn avatar maartenpaauw avatar marijoo avatar nunomaduro avatar okaufmann avatar okipa avatar pascalbaljet avatar robclancy avatar slvler avatar taylorotwell avatar tblindaruk avatar themsaid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slack-notification-channel's Issues

Argument #1 ($message) must be of type Illuminate\Notifications\Slack\SlackMessage

Slack Notification Channel Version

3.0

Laravel Version

10.4

PHP Version

8.1

Database Driver & Version

No response

Description

In the latest update it seems that return type for toSlack() changed from \Illuminate\Notifications\Messages\SlackMessage to Illuminate\Notifications\Slack\SlackMessage which results in

TypeError: Illuminate\Notifications\Slack\SlackChannel::buildJsonPayload(): Argument #1 ($message) must be of type Illuminate\Notifications\Slack\SlackMessage, Illuminate\Notifications\Messages\SlackMessage given, called in /vendor/laravel/slack-notification-channel/src/Slack/SlackChannel.php on line 38

This should probably be documented as a breaking change for the upgrade.

Steps To Reproduce

Upgrade slack notifications to v3.0

Driver [slack] not supported.

  • Slack Notification Channel Version: 2.0.0
  • Laravel Version: 5.8.9
  • PHP Version: 7.2.8
  • Database Driver & Version: MySql

Description:

I've upgraded Laravel version from 5.7 to 5.8 and installed slack notification channel package via composer. But somehow slack notifications stopped working. composer dumpautoload discovers this package but seems like it's not registering slack notification channel.

I've traced the code with xdebug and found that createSlackDriver() method is not found on laravel/framework/src/Illuminate/Support/Manager.php:95. Due to this "Driver [slack] not supported" exception occurs.

image

Slack notifications not working, unable to create legacy incoming webhook

  • Slack Notification Channel Version: 2.4.0
  • Laravel Version: 9.5.1
  • PHP Version: 8.1
  • Database Driver & Version:

Description:

I see that to() is not currently supported as noted in #54 .

We're not using to(), as the channel is configured within the Slack App settings. In a greenfield project, we're still unable to send Slack notifications.

There doesn't appear to be a way to even create the legacy Incoming Webhooks anymore, and Slack's current webhook docs list creating a Slack App as the first step.

On the "Custom Integrations" area of the workspace admin dashboard, there's a warning:

We recommend replacing your custom integrations with Slack apps, which have more features and use the latest APIs.

In the Slack workspaces I have admin permissions on, there's no option to even create a custom integration. You must create a Slack App.

Steps To Reproduce:

Create a Slack App and an incoming webhook on that app. Add the webhook URI in .env and attempt to send a notification to Slack.

Our current implementation within a Notification class looks like:

  // ...
    public function via($notifiable)
    {
        return ['slack'];
    }

    public function routeNotificationForSlack($notification)
    {
        return config('app.slack_webhook_url');
    }

    public function toSlack($notifiable)
    {
        $tags = json_encode($this->tags);
        $callLink = url('/nova/resources/calls/' . $this->callId);

        return (new SlackMessage)
            ->success()
            ->content('Applied Tags to Call')
            ->attachment(function ($attachment) use ($tags, $callLink) {
                $attachment->title('Call Id ' . $this->callId, $callLink)
                    ->fields([
                        'Caller Name' => $this->callerName,
                        'Caller Phone Number' => $this->callerPhoneNumber,
                        'Applied Tags' => $tags,
                        'Call Details Page' => $callLink,
                    ]);
            });
    }

Need support for parse=none, parse=full, etc

Thank you so much for this library. Very useful!

For your next release, I'm wondering if you'd consider adding support for https://api.slack.com/docs/message-formatting#parsing_modes

E.g. I'd love to be able to specify a parse mode (string property) on https://github.com/laravel/slack-notification-channel/blob/1.0/src/Messages/SlackMessage.php

And then have https://github.com/laravel/slack-notification-channel/blob/1.0/src/Channels/SlackWebhookChannel.php#L55 add it to the payload.

Thanks for the great work!

InputBlock missing.

I am creating a slack message, now I want to add an input text. But it turns out, the inputBlock doesn't exist at all. I see that there has been a question about this before, the issue has been closed but no solution has been found.

Why wasn't this added?

I like to hear it.

Kind regards, Govert

Error using Illuminate\Notifications\Slack\SlackMessage buildJsonPayload

Slack Notification Channel Version

3.1.0

Laravel Version

10.34.2

PHP Version

8.1.26

Database Driver & Version

MySQL 5.7

Description

I'm trying to send a Slack message via a notification toSlack. My user has a Slack incoming webhook URL that they wish to receive alerts with, but when sending a message, an error is thrown.

Illuminate\Notifications\Channels\SlackWebhookChannel::buildJsonPayload(): Argument #1 ($message) must be of type Illuminate\Notifications\Messages\SlackMessage, Illuminate\Notifications\Slack\SlackMessage given, called in /var/www/html/vendor/laravel/slack-notification-channel/src/Channels/SlackWebhookChannel.php on line 43

The docs say to use Illuminate\Notifications\Slack\SlackMessage which I'm using, put I get an error with that

Steps To Reproduce

  1. Create a notification
  2. Set the incoming webhook url on User model

Here's my routeNotificationForSlack function:

/**
 * Route notifications for the Slack channel.
 */
public function routeNotificationForSlack(Notification $notification): string|null
{
    return 'https://hooks.slack.com/services/XXXXXX';
}

Here's my toSlack function

/**
 * Get the array representation of the notification.
 *
 * @param  mixed  $notifiable
 */
public function toSlack($notifiable): SlackMessage
{
    $data = [
        'type' => 'monitor-down',
        'name' => $this->emailData['monitor_name'],
        'url' => $this->emailData['monitor_url'],
        'value' => 'down',
    ];

    try {
        $this->createHistoryEntry('slack', 'Monitor Down', $data, $notifiable);
    } catch (\Exception $e) {
    }

    $monitorName = $this->emailData['monitor_name'];
    $monitorURL = $this->emailData['monitor_url'];

    return (new SlackMessage)
        ->text('One of your invoices has been paid!')
        ->headerBlock('Invoice Paid')
        ->contextBlock(function (ContextBlock $block) {
            $block->text('Customer #1234');
        })
        ->sectionBlock(function (SectionBlock $block) {
            $block->text('An invoice has been paid.');
            $block->field("*Invoice No:*\n1000")->markdown();
            $block->field("*Invoice Recipient:*\n[email protected]")->markdown();
        })
        ->dividerBlock()
        ->sectionBlock(function (SectionBlock $block) {
            $block->text('Congratulations!');
        });

    // return (new SlackMessage)
    //         ->from('Domain Monitor')
    //         ->image('https://domain-monitor.io/slack-logo.png')
    //         ->error()
    //         ->attachment(function ($attachment) use ($monitorName, $monitorURL) {
    //             $attachment->title('Monitor down')
    //                        ->content("Your monitor *$monitorName* -- _($monitorURL)_ -- has just gone *DOWN*")
    //                        ->markdown(['text']);
    //         });
}

I'm importing

use Illuminate\Notifications\Slack\BlockKit\Blocks\ContextBlock;
use Illuminate\Notifications\Slack\BlockKit\Blocks\SectionBlock;
use Illuminate\Notifications\Slack\BlockKit\Composites\ConfirmObject;
use Illuminate\Notifications\Slack\SlackMessage;

Unable to disable link and media unfurling

  • Slack Notification Channel Version: 2.0.2
  • Laravel Version: 6.0.3
  • PHP Version: 7.2.26
  • Database Driver & Version:

Description:

Disabling link unfurling in slack messages does not work. Optional paramters with value of false gets dropped by array_filter when building json payload in SlackWebhookChannel. Slack ignores string values for unfurl_media and unfurl_links.

Steps To Reproduce:

Create new SlackMessage with a full valid url, set unfurlLinks(false), notify slack channel.

Allow `Attachement` type with the new `Block Kit`

SlackAttachment::timestamp() not setting date correctly

  • Slack Notification Channel Version: 2.3.0
  • Laravel Version: 7.0
  • PHP Version: 7.4.13
  • Database Driver & Version:

Description:

To set a Slack message timestamp, I used Illuminate\Support\InteractsWithTime\SlackAttachment::timestamp(time());
This makes sense. It sets the timestamp, or so the phpdoc says... But in reality it doesn't.

I just sent a message today (20 Feb 2021), but Slack states that it was sent on 20 Feb 2072.

Let's look at the timestamp() method, in Illuminate\Notifications\Messages:

    /**
     * Set the timestamp.
     *
     * @param  \DateTimeInterface|\DateInterval|int  $timestamp
     * @return $this
     */
    public function timestamp($timestamp)
    {
        $this->timestamp = $this->availableAt($timestamp);

        return $this;
    }

This code calls Illuminate\Support\InteractsWithTime:: availableAt($delay):

    /**
     * Get the "available at" UNIX timestamp.
     *
     * @param  \DateTimeInterface|\DateInterval|int  $delay
     * @return int
     */
    protected function availableAt($delay = 0)
    {
        $delay = $this->parseDateInterval($delay);

        return $delay instanceof DateTimeInterface
                            ? $delay->getTimestamp()
                            : Carbon::now()->addRealSeconds($delay)->getTimestamp();
    }

So what's happening is my time stamp of now is being added as a delay, and turned into the year 2072.

Steps To Reproduce:

Create a new Slack Attachement and use the timestamp() method.

I'm happy to submit a fix, by removing the calling of availableAt() method. I'm just wondering if there is some more logic needed here too?

No upgrade guide for upgrading from v2 to v3

Slack Notification Channel Version

2.5.0

Laravel Version

10

PHP Version

8.1

Database Driver & Version

No response

Description

Seems like the way to generate or write a slack notification has completely changed in v3. For example currently in v2, the content method is used, while in v3 it seems like it has been replaced with a new method called text ? Also, seems like configuration has changed drastically as well. For example, currently no tokens for a bot are required to get going. We can just have a routeNotificationForSlack method on the User model and it returns a slack hook url. It would be helpful and hence would like to request for an upgrade guide if possible. The PRs linked in the release section also doesn't have any helpful context for managing user-land code during the upgrade. Thank you for all the work being put in to manage this repo ๐Ÿš€

Steps To Reproduce

couldn't find the discussions tab hence had to create an issue.

Add colored bars to sections/blocks

I know slack can decorate messaging using colored vertical bar, like the follow

image

I suggest / request to add ability to this package to set colored bars

Full support of Slack Blocks

While support of Slack's Block kit is welcome, the PR in #64 for some reason implemented only a very limited subset of the available blocks and elements, and provided no easy way to manually add them. The Input block and its associated elements, as well as the checkbox and radio elements for the Action block are particularly glaring oversights.

I will likely submit a PR in the next few weeks, but wanted to file this issue just in case I'm not able to get to it.

Missing Blocks:
File
Input
Video

Missing Elements:
Checkbox group
Date picker
Datetime picker
Email input
Multi-select menus
Number input
Overflow menu
Radio group
Select menu
Time picker
URL input
Workflow button

slack warning message

I am using laravel version 5.8. What is the proper way to send a warning message to slack? The following code does not generate a warning message...

public function toSlack($notifiable)
    {
        return (new SlackMessage)
            ->content('One of your invoices has been paid!')
            ->warning();
    }

Function to() doesn't work

  • Slack Notification Channel Version: 2.4.0
  • Laravel Version: 8.81.0
  • PHP Version: 8.0.15
  • Database Driver & Version: n/a

Description:

Specifying an alternative channel to send a slack notification to, does not work. Probably linked to #34 from back in 2020.

Steps To Reproduce:

  • Set up Slack integration as per L8 doco
  • Create a notification to be sent to a different channel than specified in the app
  • Notification gets sent to first channel.
// The app is set to send to a channel named #test-channel, but I want to send to #general
return (new SlackMessage())
            ->from('Ghost', ':ghost:')
            ->to('#general')
            ->content('This will be sent to #general');

Demo

https://github.com/ok200paul/l8-slack-channel-bug-report

"From" is not supported

  • Slack Notification Channel Version: 2.0.2
  • Laravel Version: 6.15.1
  • PHP Version: 7.4
  • Database Driver & Version:

Description:

The method from is not supported.

Steps To Reproduce:

return (new SlackMessage)
    ->from('MyBot', ':robot_face:')
    ->to('#general')
    ->content('Hi!');

Not possible to use "Date" as the name of a field

Very simple issue to describe. The SlackAttachment@field method checks if the $title is callable using is_callable. If you use 'Date' as a field name (or any other name of a global function), it'll be used as a function instead of a string. Example:

$attachment->field('Date', $someDate);

Leads to

date() expects parameter 1 to be string, object given

is_callable is not a good way to overload the method, and it should be changed. For example, using an extra boolean parameter to indicate the first argument should be used as a callable.

Please document how to use SlackAttacments

Please, don't close this Issue telling to open a PR: I am here because i have no idea on how to use an undocumented feature of this packges

I can see the class vendor/laravel/slack-notification-channel/src/Messages/SlackAttachment.php in my project.

I would like to add an attachment, but the only way to use is via vendor/laravel/slack-notification-channel/src/Slack/SlackMessage.php

But this is not the class we (and the doc) use, because we (and the dodc) are instead using vendor/laravel/slack-notification-channel/src/Slack/SlackMessage.php

Actually I'm trying to understand the code and if there is a way to use SlackAttachment

It's undocumented

And I cannot create a docuementation PR because I'm not able to document how to use a thing I have no idea how to use.

No way to disable unfurl_links or unfurl_media

Slack Notification Channel Version

3.0.1

Laravel Version

10.2.8

PHP Version

8.1

Database Driver & Version

No response

Description

There is currently no way to set unfurl_links or unfurl_media to false. The only options currently are null (default) or true (by executing the unfurlLinks or unfurlMedia methods.

Unless specifically set to false, Slack will enable unfurl for links and media.

Steps To Reproduce

  1. Create a notification with a link displayed anywhere within the body, for example:
[...]
    public function toSlack(object $notifiable): SlackMessage
    {
        return (new SlackMessage)
            ->text("Test Notification")
            ->headerBlock('Test Notification')
            ->sectionBlock(function (SectionBlock $block) {
                $block->field("*Domain*\n<https://www.google.com/|www.google.com>")->markdown();
            });
    }
[...]
  1. Trigger the notification
  2. Notice that the notification includes the link preview even though you didn't execute the unfurlLinks method.

Undesirable side-effects of is_callable() use

Slack Notification Channel Version

2.5.0

Laravel Version

10.4.1

PHP Version

8.2.4

Database Driver & Version

No response

Description

The use of is_callable() at SlackAttachment.php has undesirable and potentially dangerous side-effects:

 public function field($title, $content = '')
    {
        if (is_callable($title)) {
            $callback = $title;

            $callback($attachmentField = new SlackAttachmentField);

So, imagine you are creating a message with an attachment field like this:

 (new \Illuminate\Notifications\Messages\SlackMessage())
    ->attachment(fn($attachment) => $attachment->field('dd', 'Whoops')
);

In this case, is_callable('dd') will of course return true and call dd() with the SlackAttachmentField as a parameter:

Illuminate\Notifications\Messages\SlackAttachmentField^ {#5154 // vendor/laravel/slack-notification-channel/src/Messages/SlackAttachment.php:216
  #title: null
  #content: null
  #short: true

The same goes for any other callable functions, things like DB::supportedDrivers, session_destroy... I leave it up to the readers' imagination what this could be used for.

A possible fix would be to accept closures only and check by if ($title instanceof Closure). While this would be a breaking change, I think it is worth consideration.

What do you think?

Steps To Reproduce

 (new \Illuminate\Notifications\Messages\SlackMessage())
    ->attachment(fn($attachment) => $attachment->field('dd', 'Whoops')
);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.