Git Product home page Git Product logo

laravel-slack-blocks's Introduction

Hi there! ๐Ÿ‘‹


I'm a Laravel developer by day, serial side project abandoner by night. Lately, I've been spending my free time making games ๐ŸŽฎ for the Playdate.

Laravel Slack Blocks has been stable and running in production for a while now. Go check it out if you want to level-up the Slack messages your application sends.

Laravel Watermelon ๐Ÿ‰ is a new project that I'm hoping will make it a breeze for Laravel developers to integrate Watermelon DB into their applications. If you need easy offline data storage in your web or mobile apps, check out Watermelon DB and this package to get up and running quickly.

laravel-slack-blocks's People

Contributors

aarondfrancis avatar ashikpaul avatar nathanheffley avatar sbine avatar tomwelch 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

Watchers

 avatar  avatar  avatar  avatar

laravel-slack-blocks's Issues

Does this package also support "type": "context"?

Hello, a good job with this package. Everything works fine, except maybe it's my lack of understanding of the inner workings - does this package supports type context? You code recognizes "elements", but I can't get it to work for type:context. Can you please help?

Slack Blocks example that I can't get to work:

{
  "type": "context",
  "elements": [{
      "type": "image",
      "image_url": "https://api.slack.com/img/blocks/bkb_template_images/tripAgentLocationMarker.png",
      "alt_text": "Location Pin Icon"
    },
    {
      "type": "plain_text",
      "emoji": true,
      "text": "Location: Central Business District"
    }
  ]
}

My simple attempt:

$attachment->block(function ($block) use ($item) {
  $block
      ->type('context')
      ->elements([
          'type' => 'plain_text',
          'text' => 'text'
      ]);
});

Action block "elements" must be array

Im experiencing this issue now and I cant get it to work with your "test"-example:

return (new SlackMessage)
    ->attachment(function ($attachment) {
        $attachment
            ->block(function ($block) {
                $block
                    ->type('actions')
                    ->elements([
                        'type' => 'button',
                        'text' => [
                            'type' => 'plain_text',
                            'text' => 'Cancel',
                        ],
                    ]);
            });
    });

Laravel throws a bad request with invalid_attachments response.

Its working fine with a text section.

I had the original laravel notification package installed prior to yours, but uninstalled before installing yours.
I've tried to clear composer cache, dump auto load and run composer install again.

I still get the error. Any idea on how to get it to work?

EDIT:
Okay, so for some reason I can only get it to work with an extra [] around the elements, compared to the test example:

->elements([
    [
        'type' => 'button',
        'text' => [
            'type' => 'plain_text',
            'text' => 'Approve',
            'emoji' => false,
        ],
        'value' => 'click_me_123',
        'action_id' => 'approve_x',
        'style' => 'primary',
    ]
]);

Originally posted by @ejerskov in #4 (comment)

New line doesnt work

Describe the bug
Using \n in a mrkdwn section doesnt work.

To Reproduce

->block(function ($block) {
    $block
      ->type('section')
      ->text([
          'type' => 'mrkdwn',
          'text' => 'Test \n newline',
      ])

The \n is just rendered as text in Slack

Allow laravel/slack-notification-channel v2?

I'd like to try out your library and blocks with Slack, but have the following issue with a new Laravel 5.8 project with Nova:

composer require nathanheffley/laravel-slack-blocks

Using version ^1.1 for nathanheffley/laravel-slack-blocks
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for nathanheffley/laravel-slack-blocks ^1.1 -> satisfiable by nathanheffley/laravel-slack-blocks[1.1.x-dev, v1.1.0, v1.1.1].
- Can only install one of: laravel/slack-notification-channel[1.0.x-dev, v2.0.0].
- Can only install one of: laravel/slack-notification-channel[v2.0.0, 1.0.x-dev].
- Can only install one of: laravel/slack-notification-channel[1.0.x-dev, v2.0.0].
- Conclusion: install laravel/slack-notification-channel 1.0.x-dev
- Installation request for laravel/slack-notification-channel (locked at v2.0.0, required as ^2.0) -> satisfiable by laravel/slack-notification-channel[v2.0.0].

I'd appreciate any assistance. Thanks!

Undefined property: Illuminate\Notifications\Messages\SlackMessage::$blocks

Hey there,

Thanks for making this great library. We started using it yesterday and it's made our slack notifications much more customizable.

We're currently running into an error sending a slack message that we don't control. Specifically, Horizon sends the LongWaitDetected message through slack. Since we don't control that, it's a standard SlackMessage instead of one of the new ones with the blocks property.

That means that when your code gets to this line, it dies because blocks is not defined on the base SlackMessage.

Can we add a property_exists check for that property?

Thanks!

Slack message seems to be "preview"

When sending a message to slack, it seems to be "preview" (see the gray bar next to hello world)

image

When posting a longer message, it shows see more at the bottom and the message is not fully shown... Do you have any ideas how to fix this?

My code:

return (new SlackMessage)
            ->from($name, $icon)
            ->to('#testing')
            ->attachment(function ($attachment) {
                $attachment->block(function ($block) {
                    $block
                        ->type('section')
                        ->text([
                            'type' => 'mrkdwn',
                            'text' => '*Hello World!*',
                        ]);
                });
            });

Using block json

Hello and thank you for creating this.

I was wondering why we cant just use the slack json as attachment instead of using ->type(...) ->text(...) etc

Noticed an issue with trying to assign a url

Theres a typo in the 'SlackBlock.php' file, where assigning the url. Kinda drove me batty for a while until I found it.
Starting at line 144, you have:

/**
* Set the url of the block.
*
* @param string $url
* @return $this
*/
public function url($url)
{
$this->$url = $url;

    return $this;
}

$this->$url = $url;

Should be :
$this->url = $url

Note For Those Attempting To Add Multiple Blocks and/or use action buttons. I just spent a good 2 hours troubleshooting how to do these things...so maybe itll help someone else who sees this. This is working code for multiple blocks and using an "actions" button:

(new SlackMessage)
            ->error()
            ->attachment(function ($attachment) {
                  $attachment->block(function ($block) {
                      $block
                          ->type('section')
                          ->text([
                              'type' => 'mrkdwn',
                              'text' => 'hello world',
                          ]);
                  });
                  $attachment->block(function ($block) {
                      $block
                          ->type('actions')
                          ->elements([[
                              'type' => 'button',
                              'text' => [
                                  'type' => 'plain_text',
                                  'text' => 'Google Home Page',
                              ],
                              'url' => "https://google.com"
                          ]]);
                  });
            });

Support for `actions` block

The official BlockKit has an actions block:

https://api.slack.com/reference/block-kit/blocks#actions

{
  "type": "actions",
  "elements": [
    {
        ...
   }
  ]

but I'm getting an error when I try to use it. This is meant to house buttons.

Here's my example code:

$attachment->block(function($block) use ($url, $self) {
  $block
    ->type('actions')
    ->elements([
      [
        'type' => 'button',
	'text' => [
	  'type' => 'plain_text',
	  'text' => 'Go to app'
         ],
	'url' => $url
      ]
  ]);
});

Are you going to support this part of the blockkit?

Please update guzzlehttp/guzzle to v7.0.1

Problem
With Laravel 8 Update, they have you update Guzzle to Version 7.0.1. This the problem that occurs"
https://laravel.com/docs/8.x/upgrade#updating-dependencies

Problem 1
- Installation request for nathanheffley/laravel-slack-blocks ^2.2 -> satisfiable by nathanheffley/laravel-slack-blocks[v2.2.0, v2.2.1].
- Can only install one of: guzzlehttp/guzzle[7.0.1, 6.5.x-dev].
- Can only install one of: guzzlehttp/guzzle[7.0.x-dev, 6.5.x-dev].
- Can only install one of: guzzlehttp/guzzle[7.1.x-dev, 6.5.x-dev].
- Conclusion: install guzzlehttp/guzzle 6.5.x-dev
- Installation request for guzzlehttp/guzzle ^7.0.1 -> satisfiable by guzzlehttp/guzzle[7.0.1, 7.0.x-dev, 7.1.x-dev].

Solution
Please update Composer package guzzlehttp/guzzle to v7.0.1. Thank you.

About the maximum number of blocks

Valid number of block items as JSON in Block Kit is "50". Post errors like Invalid_Item will be returned if you notify more than 50 items.

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.