Download the PHP package slack-php/slack-block-kit without Composer

On this page you can find all versions of the php package slack-php/slack-block-kit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package slack-block-kit

Slack Block Kit for PHP

:point_right: For formatting messages and modals for Slack using their Block Kit syntax via an OOP interface :point_left:

By Jeremy Lindblom (@jeremeamia)

Slack logo placed on top of blocks

Coded in PHP 8.1 Packagist Version Build Status


Introduction

From Slack's Block Kit documentation:

Block Kit is a UI framework for Slack apps that offers a balance of control and flexibility when building experiences in messages and other surfaces.

Customize the order and appearance of information and guide users through your app's capabilities by composing, updating, sequencing, and stacking blocks — reusable components that work almost everywhere in Slack.

This library provides an OOP interface in PHP for composing messages/modals using Slack Block Kit. It also does the reverse, meaning you can "hydrate" message/modal JSON into an object hierarchy.

Block Kit Concepts

This library helps you build Slack messages and modals programmatically and dynamically in your code, but you need to know how they work generally first. The library does try to prevent you from doing things you are not permitted to do in Block Kit, but it may not validate against every single or condition.

You may want to review the following concepts in the Slack documentation:

In general, we refer to ALL of these different things in Block Kit collectively as "components".

Installation

Install easily via Composer:

Then include the Composer-generated autoloader in your project's initialization code.

Note: This library is built for PHP 8.1+.

Version 1 of this library supports version 7.3/7.4.

Basic Usage

This library supports an intuitive syntax for composing Slack surfaces (e.g., messages, modals) that utilizes PHP 8's named parameters feature.

The Kit Façade

The Kit class acts as a façade for the whole library's set of components and has factory methods for each one. It allows you to limit the number of classes you have to import to build a message (or other surface).

Each factory method has the same parameters as the original component's constructor.

Fluent Interface

If named parameters aren't your jam, there is another way to set a component's properties, through the setter methods. Each component has chainable setter methods for each of its properties, which allows for a fluent-style interface.

The fluent syntax is not dependent on the Kit façade. Component classes have a static new() method that can be used for chaining as well.

Null Values

All properties are considered as null/empty until set.

You can also set a property explicitly to null to remove its value (e.g., from a component you created from existing data).

Finally, null values are allowed in lists of blocks, elements, options, etc., so it's safe to use conditional items.

Preview in Block Kit Builder

Slack provides an interactive Block Kit Builder for composing/testing messages and other surfaces. This is a great way to play around with and learn the Block Kit format.

The Kit::preview method allows you to render your message/surface as a Block Kit Builder URL, so you can link to a preview or your message/surface in the browser via their interactive tool. This will help you see how it would be rendered in a Slack client.

Output

And here's the actual Block Kit Builder link.

It will show up in the Block Kit Builder looking something like this:

Component Hydration

Some Slack application integrations (such as with Modals) require receiving the JSON of an existing surface and then modifying or replacing that surface with another. You can "hydrate" the JSON of a surface (or element) into its object representation using its fromArray method (or fromJson).

Message Formatting

The Md class exists to provide helpers for formatting "mrkdwn" text. These helpers can be used so that you don't have to have the Slack mrkdwn syntax memorized. Also, these functions will properly escape <, >, and & characters automatically, if it's needed.

Example:

Example Result:

Virtual Blocks

In addition to the standard blocks, the following are virtual/custom blocks composed of one or more other blocks:

Class Structure

UML diagram for slack-block-kit

See the YUML
[Kit]-creates>[Component]
[Surface]^[Message]
[Surface]^[Modal]
[Surface]^[AppHome]
[Surface]^[Attachment]
[Component]^[Surface]
[Component]^[Block]
[Component]^[Element]
[Component]^[Part]
[Component]<>->[Part]
[Surface]<>->[Block]
[Message]<>->[Attachment]
[Block]<>->[Element]
[Element]^[Input]
[Element]-[note:Examples: Button, OverflowMenu {bg:cornsilk}]
[Input]-[note:Examples: Select Menu, DatePicker {bg:cornsilk}]
[Part]-[note: Examples: Text, Fields {bg:cornsilk}]
[Block]-[note: Examples: Section, Actions {bg:cornsilk}]

Contributions

Contributions welcome to support new elements, add tests, improve code, etc.


All versions of slack-block-kit with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package slack-php/slack-block-kit contains the following files

Loading the files please wait ....