PHPackages                             two16d/block-kit-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. two16d/block-kit-php

ActiveLibrary

two16d/block-kit-php
====================

A fluent PHP builder for creating Slack Block Kit messages

v1.0.0(5mo ago)00MITPHPPHP ^8.1

Since Dec 7Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/two16D/blockkitphp)[ Packagist](https://packagist.org/packages/two16d/block-kit-php)[ RSS](/packages/two16d-block-kit-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Block Kit PHP
=============

[](#block-kit-php)

A PHP library for building Slack Block Kit messages programmatically.

Block Kit PHP makes it easier to construct Slack Block Kit payloads in PHP without manually writing JSON. You can build complex modals, messages, and interactive elements using PHP objects, arrays, or method chaining.

---

Features
--------

[](#features)

- Build Slack Block Kit messages entirely in PHP.
- Supports all Slack Block Kit blocks, surfaces, elements &amp; objects.
- Construct blocks using static helpers or object instances.
- Method chaining for a fluent API.
- Full type hints and docblocks on all methods.
- Strict input validation to ensure payloads comply with Slack's Block Kit rules.
- Convert payloads to JSON or array for Slack API consumption.
- Compatible with PHP 8.1+.

---

Installation
------------

[](#installation)

Install via [Composer](https://getcomposer.org):

```
composer require two16D/block-kit-php
```

---

Quick Example
-------------

[](#quick-example)

```
use BlockKitPHP\Surfaces;
use BlockKitPHP\Blocks;
use BlockKitPHP\Elements;
use BlockKitPHP\Objects;
use BlockKitPHP\RichTextElements;
use BlockKitPHP\RichTextObjects;

$modal = Surfaces::modal(
    'Create Task',
    [
        Blocks::section([
            'block_id' => 'intro',
            'text' => Objects::markdownText("*Create a new task* and assign it to your team.\nPlease fill in the details below."),
        ]),
        Blocks::input(
            'Task title',
            Elements::plainTextInput([
                'action_id' => 'title_input',
                'placeholder' => 'e.g. Prepare Q4 report',
            ]),
            ['block_id' => 'task_title'],
        ),
        Blocks::input(
            'Due date',
            Elements::datePicker([
                'action_id' => 'due_date_select',
                'placeholder' => 'Select a date',
            ]),
            ['block_id' => 'due_date'],
        ),
        Blocks::section([
            'block_id' => 'priority',
            'text' => Objects::markdownText('Set the task *priority*:'),
            'accessory' => Elements::staticSelect([
                'action_id' => 'priority_select',
                'placeholder' => 'Choose priority',
                'options' => [
                    Objects::option('Low', 'low'),
                    Objects::option('Medium', 'medium'),
                    Objects::option('High', 'high'),
                ],
            ]),
        ]),
        Blocks::actions(
            [
                Elements::button('Preview', ['action_id' => 'preview_task', 'style' => 'primary']),
                Elements::button('Clear', [
                    'action_id' => 'delete_draft',
                    'confirm' => Objects::confirmationDialog(
                        'Clear all fields?',
                        'This will remove all entered information.',
                        'Yes, clear',
                        'Keep editing'
                    ),
                ]),
            ],
            ['block_id' => 'footer_actions']
        ),
    ],
    [
        'close' => 'Cancel',
        'submit' => 'Save',
        'callback_id' => 'task_create_modal',
    ]
);

// Convert to JSON
$json = $modal->toJson();

// Or convert to array
$array = $modal->array();
```

---

Usage Patterns
--------------

[](#usage-patterns)

```
// Helper style
$text = Objects::plainText('Hello world', ['emoji' => true]);

// Object style
$text = new PlainText('Hello world', ['emoji' => true]);

// Method chaining
$button = Elements::button('Click me')->setStyle('primary')->setActionId('click_me');
```

---

Blocks and Classes
------------------

[](#blocks-and-classes)

Block Kit PHP is organized to reflect Slack's Block Kit model. This helps you compose messages modularly and clearly.

### Surfaces

[](#surfaces)

The top-level entry points for creating Slack payloads. All other classes ultimately feed into these surface objects.

- Message: `Surfaces::message(...)`
- Modal: `Surfaces::modal(...)`
- App Home (Home Tab): `Surfaces::appHome(...)`

### Blocks

[](#blocks)

Blocks are the main structural elements of a Slack message. For example:

- Actions: `Blocks::actions(...)`
- Section: `Blocks::section(...)`
- Input: `Blocks::input(...)`
- Divider, Header, Image, RichText, Table, Video ...

### Elements

[](#elements)

Elements are interactive components that live inside blocks:

- Button: `Elements::button(...)`
- Select menus: `Elements::staticSelect(...)`, `Elements::usersSelect(...)`
- Inputs: `Elements::plainTextInput(...)`, `Elements::datePicker(...)`
- Checkboxes, Image, Overflow, WorkflowButton ...

### Objects

[](#objects)

Objects represent smaller data structures used inside blocks or elements:

- Text objects: `Objects::plainText(...)`, `Objects::markdownText(...)`
    - Options and option groups: `Objects::option(...)`, `Objects::optionGroup(...)`
    - Confirmation dialogues (`Objects::confirmationDialog(...)`)
    - Workflow triggers, Slack files, Conversation filters ...

### RichText

[](#richtext)

RichText allows creating Slack’s advanced text formatting blocks. It has its own hierarchy:

- Rich Text Elements: `RichTextElements::section(...)`, `RichTextElements::list(...)`, ...
- Rich Text Objects: `RichTextObjects::text(...)`, `RichTextObjects::link(...)`, ...

---

Contributing
------------

[](#contributing)

- Open a GitHub issue for bugs or feature requests.
- Pull requests should include tests where appropriate.
- Keep code style PSR-12 compliant.

---

License
-------

[](#license)

MIT License. See [LICENSE](https://github.com/two16D/blockkitphp/blob/v1.0.0/LICENSE) for details.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance71

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

162d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4dae4be6830d9fdb2a2a5263d9b65e0c0bbe6e5f55b46ee55794fb1014cf905?d=identicon)[two16D](/maintainers/two16D)

---

Top Contributors

[![two16D](https://avatars.githubusercontent.com/u/33282148?v=4)](https://github.com/two16D "two16D (163 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/two16d-block-kit-php/health.svg)

```
[![Health](https://phpackages.com/badges/two16d-block-kit-php/health.svg)](https://phpackages.com/packages/two16d-block-kit-php)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
