PHPackages                             nexylan/slack - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. nexylan/slack

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

nexylan/slack
=============

A simple PHP package for sending messages to Slack, with a focus on ease of use and elegant syntax.

v3.2.0(5y ago)1061.7M↓49.2%27[2 issues](https://github.com/nexylan/slack/issues)[2 PRs](https://github.com/nexylan/slack/pulls)1MITPHPPHP ^7.4 || ^8.0

Since May 5Pushed 2y ago6 watchersCompare

[ Source](https://github.com/nexylan/slack)[ Packagist](https://packagist.org/packages/nexylan/slack)[ RSS](/packages/nexylan-slack/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (8)DependenciesVersions (25)Used By (1)

Slack for PHP
=============

[](#slack-for-php)

A simple PHP package for sending messages to [Slack](https://slack.com)with [incoming webhooks](https://my.slack.com/services/new/incoming-webhook), focused on ease-of-use and elegant syntax.

[![Latest Stable Version](https://camo.githubusercontent.com/dc6bdcc568859839819935f079fe2b6930e9943770cedb8ce539377a7a5c010d/68747470733a2f2f706f7365722e707567782e6f72672f6e6578796c616e2f736c61636b2f762f737461626c65)](https://packagist.org/packages/nexylan/slack)[![Latest Unstable Version](https://camo.githubusercontent.com/7e7441025536c0c4830d3d44147aacf99b47c874bc208ad9edb077ad62a2a27f/68747470733a2f2f706f7365722e707567782e6f72672f6e6578796c616e2f736c61636b2f762f756e737461626c65)](https://packagist.org/packages/nexylan/slack)[![License](https://camo.githubusercontent.com/6f58a5dd8b33d6a5a17a9f5b3444d527bbafc2b31c19df653559983b106b8cec/68747470733a2f2f706f7365722e707567782e6f72672f6e6578796c616e2f736c61636b2f6c6963656e7365)](https://packagist.org/packages/nexylan/slack)

[![Total Downloads](https://camo.githubusercontent.com/71adbb92ab47656970748d9e5ccd72563951153a5fd0c25fa3d08ec6b90038a7/68747470733a2f2f706f7365722e707567782e6f72672f6e6578796c616e2f736c61636b2f646f776e6c6f616473)](https://packagist.org/packages/nexylan/slack)[![Monthly Downloads](https://camo.githubusercontent.com/de9b8337ec818df403b6d53f90ccce0ace81468991cc434c7e282582018a562c/68747470733a2f2f706f7365722e707567782e6f72672f6e6578796c616e2f736c61636b2f642f6d6f6e74686c79)](https://packagist.org/packages/nexylan/slack)[![Daily Downloads](https://camo.githubusercontent.com/3a5f83f1eb7b5bbd65a2cdad1b0d08b8cb7307bca79ecc68695dacbbd1098197/68747470733a2f2f706f7365722e707567782e6f72672f6e6578796c616e2f736c61636b2f642f6461696c79)](https://packagist.org/packages/nexylan/slack)

[![Build Status](https://camo.githubusercontent.com/768556ef8004b0ac5f5fbbbaa9ce8c837e1b932023054af892c43562db3d63b1/68747470733a2f2f7472617669732d63692e6f72672f6e6578796c616e2f736c61636b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/nexylan/slack)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/168949c6421523c27833c06f73c6fd482ff00abb97df64953c074e7bfcdd2116/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e6578796c616e2f736c61636b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/nexylan/slack/?branch=master)[![Code Climate](https://camo.githubusercontent.com/721740046ec5062fd38f2551ab378721a2fac165a67c49a5b508c233521149d8/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6e6578796c616e2f736c61636b2f6261646765732f6770612e737667)](https://codeclimate.com/github/nexylan/slack)[![Coverage Status](https://camo.githubusercontent.com/3ba5d592cea90c5e3cbd5a3c7817271aebebb176947f75ec27fa38eaaafbb6da/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6e6578796c616e2f736c61636b2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/nexylan/slack?branch=master)

- Symfony integration: [Slack bundle](https://github.com/nexylan/slack-bundle)

This repository started from a fork of the popular [maknz/slack](https://github.com/maknz/slack) library, which [is not maintained anymore](https://github.com/maknz/slack/commit/89ff7b2).

The 1.x branch and all the related releases are an exact copy of the original repository and are under the [BSD 2-clause "Simplified" License](https://github.com/maknz/slack/blob/master/LICENSE.md).

The next releases will be under the MIT license. See the current [LICENSE](LICENSE) file for more details.

Requirements
------------

[](#requirements)

- PHP 7.3+

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

[](#installation)

You can install the package using the [Composer](https://getcomposer.org/) package manager. You can install it by running this command in your project root:

```
composer require nexylan/slack
```

We also follow [PSR-7](https://www.php-fig.org/psr/psr-7/), [PSR-17](https://www.php-fig.org/psr/psr-17/) and [PSR-18](https://www.php-fig.org/psr/psr-18/) standards for HTTP messaging. It allows you to use any HTTP client following this convention and make the library maintenability better for us.

So you need to install an HTTP client following those standards. We recommand to use the popular [HTTPlug](http://httplug.io/) project, but you are free to choose the more convinient one for you.

Then [create an incoming webhook](https://my.slack.com/services/new/incoming-webhook) on your Slack account for the package to use. You'll need the webhook URL to instantiate the client (or for the configuration file if using Laravel).

Basic Usage
-----------

[](#basic-usage)

### Instantiate the client

[](#instantiate-the-client)

In this example, we use the [HTTPlug discovery component](http://docs.php-http.org/en/latest/discovery.html) to bring the needed PSR tools.

```
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;

use Nexy\Slack\Client;

$client = new Client(
    Psr18ClientDiscovery::find(),
    Psr17FactoryDiscovery::findRequestFactory(),
    Psr17FactoryDiscovery::findStreamFactory(),
    'https://hooks.slack.com/...',
    [
        'username' => 'Cyril', // Default messages are sent from 'Cyril'
        'channel' => '#accounting', // Default messages are sent to '#accounting'
        'link_names' => true
    ]
);
```

Note: The `$options` last parameter is optional.

#### Settings

[](#settings)

The default settings are pretty good, but you may wish to set up default behaviour for your client to be used for all messages sent. **All settings are optional and you don't need to provide any**. Where not provided, we'll fallback to what is configured on the webhook integration, which are [managed at Slack](https://my.slack.com/apps/manage/custom-integrations), or our sensible defaults.

FieldTypeDescription`channel`stringThe default channel that messages will be sent to`sticky_channel`boolIf set to true, all messages will be sent to the default channel only (defaults to false). It can be useful for dev/test environments.`username`stringThe default username for your bot`icon`stringThe default icon that messages will be sent with, either `:emoji:` or a URL to an image`link_names`boolWhether names like `@regan` or `#accounting` should be linked in the message (defaults to false)`unfurl_links`boolWhether Slack should unfurl text-based URLs (defaults to false)`unfurl_media`boolWhether Slack should unfurl media-based URLs, like tweets or Youtube videos (defaults to true)`allow_markdown`boolWhether markdown should be parsed in messages, or left as plain text (defaults to true)`markdown_in_attachments`arrayWhich attachment fields should have markdown parsed (defaults to none)### Sending messages

[](#sending-messages)

#### Sending a basic message ([preview](https://goo.gl/fY43nw))

[](#sending-a-basic-message-preview)

```
$client->send('Hello world!');
```

#### Sending a message to a non-default channel

[](#sending-a-message-to-a-non-default-channel)

```
$client->to('#accounting')->send('Are we rich yet?');
```

#### Sending a message to a user

[](#sending-a-message-to-a-user)

```
$client->to('@regan')->send('Yo!');
```

#### Sending a message to a channel as a different bot name ([preview](https://goo.gl/xCeEfY))

[](#sending-a-message-to-a-channel-as-a-different-bot-name-preview)

```
$client->from('Jake the Dog')->to('@FinnTheHuman')->send('Adventure time!');
```

#### Sending a message with a different icon ([preview](https://goo.gl/lff21l))

[](#sending-a-message-with-a-different-icon-preview)

```
// Either with a Slack emoji
$client->to('@regan')->withIcon(':ghost:')->send('Boo!');

// or a URL
$client->to('#accounting')->withIcon('http://example.com/accounting.png')->send('Some accounting notification');
```

#### Send an attachment ([preview](https://goo.gl/fp3iaY))

[](#send-an-attachment-preview)

```
$client->to('#operations')->attach((new \Nexy\Slack\Attachment())
    ->setFallback('Server health: good')
    ->setText('Server health: good')
    ->setColor('danger')
)->send('New alert from the monitoring system'); // no message, but can be provided if you'd like
```

#### Send an attachment with fields ([preview](https://goo.gl/264mhU))

[](#send-an-attachment-with-fields-preview)

```
$client->to('#operations')->attach((new \Nexy\Slack\Attachment())
    ->setFallback('Current server stats')
    ->setText('Current server stats')
    ->setColor('danger')
    ->setFields([
        new \Nexy\Slack\AttachmentField(
            'Cpu usage',
            '90%',
            true // whether the field is short enough to sit side-by-side other fields, defaults to false
        ),
        new \Nexy\Slack\AttachmentField('RAM usage', '2.5GB of 4GB', true),
    ])
)->send('New alert from the monitoring system'); // no message, but can be provided if you'd like
```

#### Send an attachment with an author ([preview](https://goo.gl/CKd1zJ))

[](#send-an-attachment-with-an-author-preview)

```
$client->to('@regan')->attach((new \Nexy\Slack\Attachment())
    ->setFallback('Keep up the great work! I really love how the app works.')
    ->setText('Keep up the great work! I really love how the app works.')
    ->setAuthorName('Jan Appleseed')
    ->setAuthorLink('https://yourapp.com/feedback/5874601')
    ->setAuthorIcon('https://static.pexels.com/photos/61120/pexels-photo-61120-large.jpeg')
)->send('New user feedback');
```

Advanced usage
--------------

[](#advanced-usage)

### Markdown

[](#markdown)

By default, Markdown is enabled for message text, but disabled for attachment fields. This behaviour can be configured in settings, or on the fly:

#### Send a message enabling or disabling Markdown

[](#send-a-message-enabling-or-disabling-markdown)

```
$client->to('#weird')->disableMarkdown()->send('Disable *markdown* just for this message');

$client->to('#general')->enableMarkdown()->send('Enable _markdown_ just for this message');
```

#### Send an attachment specifying which fields should have Markdown enabled

[](#send-an-attachment-specifying-which-fields-should-have-markdown-enabled)

```
$client->to('#operations')->attach((new \Nexy\Slack\Attachment())
    ->setFallback('It is all broken, man')
    ->setText('It is _all_ broken, man')
    ->setPretext('From user: *JimBob*')
    ->setColor('danger')
    ->setMarkdownFields(['pretext', 'text'])
)->send('New alert from the monitoring system');
```

### Explicit message creation

[](#explicit-message-creation)

For convenience, message objects are created implicitly by calling message methods on the client. We can however do this explicitly to avoid hitting the magic method.

```
// Implicitly
$client->to('@regan')->send('I am sending this implicitly');

// Explicitly
$message = $client->createMessage();

$message->to('@regan')->setText('I am sending this explicitly');

$message->send();
```

### Attachments

[](#attachments)

When using attachments, the easiest way is to provide an array of data as shown in the examples, which is actually converted to an Attachment object under the hood. You can also attach an Attachment object to the message:

```
$attachment = (new Attachment())
    ->setFallback('Some fallback text')
    ->setText('The attachment text')
;

// Explicitly create a message from the client
// rather than using the magic passthrough methods
$message = $client->createMessage();

$message->attach($attachment);

// Explicitly set the message text rather than
// implicitly through the send method
$message->setText('Hello world')->send();
```

You can also set the attachments and fields directly if you have a whole lot of them:

```
// implicitly create a message and set the attachments
$client->setAttachments($bigArrayOfAttachments);

// or explicitly
$client->createMessage()->setAttachments($bigArrayOfAttachments);
```

```
$attachment = new Attachment();

$attachment->setFields($bigArrayOfFields);
```

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

[](#contributing)

If you're having problems, spot a bug, or have a feature suggestion, please log and issue on Github. If you'd like to have a crack yourself, fork the package and make a pull request. Please include tests for any added or changed functionality. If it's a bug, include a regression test.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity54

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Every ~113 days

Recently: every ~154 days

Total

23

Last Release

1938d ago

Major Versions

0.3.0 → 1.0.02015-01-09

1.x-dev → v2.0.02018-01-17

v2.3.0 → v3.0.02019-11-25

PHP version history (5 changes)0.1.0PHP &gt;=5.3.0

0.1.1PHP &gt;=5.4.0

v2.0.0PHP ^7.1

v3.0.0PHP ^7.3

v3.2.0PHP ^7.4 || ^8.0

### Community

Maintainers

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

![](https://avatars.githubusercontent.com/u/2728195?v=4)[Gaetan Allart](/maintainers/gallart)[@gallart](https://github.com/gallart)

![](https://avatars.githubusercontent.com/u/59648802?v=4)[Florent BOSSUYT](/maintainers/flubble)[@flubble](https://github.com/flubble)

---

Top Contributors

[![maknz](https://avatars.githubusercontent.com/u/992356?v=4)](https://github.com/maknz "maknz (76 commits)")[![soullivaneuh](https://avatars.githubusercontent.com/u/1698357?v=4)](https://github.com/soullivaneuh "soullivaneuh (58 commits)")[![rbaarsma](https://avatars.githubusercontent.com/u/1061560?v=4)](https://github.com/rbaarsma "rbaarsma (2 commits)")[![4c0n](https://avatars.githubusercontent.com/u/2325383?v=4)](https://github.com/4c0n "4c0n (2 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (1 commits)")[![georgecoca](https://avatars.githubusercontent.com/u/6689915?v=4)](https://github.com/georgecoca "georgecoca (1 commits)")[![iwiznia](https://avatars.githubusercontent.com/u/521248?v=4)](https://github.com/iwiznia "iwiznia (1 commits)")[![Jerome1337](https://avatars.githubusercontent.com/u/7968649?v=4)](https://github.com/Jerome1337 "Jerome1337 (1 commits)")[![jwcobb](https://avatars.githubusercontent.com/u/777522?v=4)](https://github.com/jwcobb "jwcobb (1 commits)")[![mbabker](https://avatars.githubusercontent.com/u/368545?v=4)](https://github.com/mbabker "mbabker (1 commits)")[![mvatansever](https://avatars.githubusercontent.com/u/5843891?v=4)](https://github.com/mvatansever "mvatansever (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")[![qmcree](https://avatars.githubusercontent.com/u/7796024?v=4)](https://github.com/qmcree "qmcree (1 commits)")[![rajabishek](https://avatars.githubusercontent.com/u/6145125?v=4)](https://github.com/rajabishek "rajabishek (1 commits)")[![rap2hpoutre](https://avatars.githubusercontent.com/u/1575946?v=4)](https://github.com/rap2hpoutre "rap2hpoutre (1 commits)")[![stefanzweifel](https://avatars.githubusercontent.com/u/1080923?v=4)](https://github.com/stefanzweifel "stefanzweifel (1 commits)")[![tzookb](https://avatars.githubusercontent.com/u/3749973?v=4)](https://github.com/tzookb "tzookb (1 commits)")[![vysinsky](https://avatars.githubusercontent.com/u/3693578?v=4)](https://github.com/vysinsky "vysinsky (1 commits)")[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (1 commits)")[![balazscsaba2006](https://avatars.githubusercontent.com/u/1202594?v=4)](https://github.com/balazscsaba2006 "balazscsaba2006 (1 commits)")

---

Tags

slackwebhook

### Embed Badge

![Health badge](/badges/nexylan-slack/health.svg)

```
[![Health](https://phpackages.com/badges/nexylan-slack/health.svg)](https://phpackages.com/packages/nexylan-slack)
```

###  Alternatives

[maknz/slack

A simple PHP package for sending messages to Slack, with a focus on ease of use and elegant syntax.

1.2k12.0M66](/packages/maknz-slack)[spatie/laravel-failed-job-monitor

Get notified when a queued job fails

1.1k2.8M4](/packages/spatie-laravel-failed-job-monitor)[alek13/slack

A simple PHP package (fork of maknz/slack) for sending messages to Slack, with a focus on ease of use and elegant syntax.

1405.5M18](/packages/alek13-slack)[guanguans/notify

Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NotifyX、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

687114.3k8](/packages/guanguans-notify)[symfony/slack-notifier

Symfony Slack Notifier Bridge

426.7M13](/packages/symfony-slack-notifier)[beyondcode/slack-notification-channel

Slack Notification Channel for Laravel using API tokens.

85531.5k](/packages/beyondcode-slack-notification-channel)

PHPackages © 2026

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