PHPackages                             yuki777/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. [HTTP &amp; Networking](/categories/http)
4. /
5. yuki777/slack

ActiveLibrary[HTTP &amp; Networking](/categories/http)

yuki777/slack
=============

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

v2.2.4(5y ago)01.8kMITPHPPHP ^7.1

Since May 5Pushed 5y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (8)Versions (28)Used By (0)

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.1+

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 php-http/guzzle6-adapter
```

Why `php-http/guzzle6-adapter`? We are decoupled from any HTTP messaging client thanks to [HTTPlug](http://httplug.io/).

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)

```
// Instantiate without defaults
$client = new Nexy\Slack\Client('https://hooks.slack.com/...');

// Instantiate with defaults, so all messages created
// will be sent from 'Cyril' and to the #accounting channel
// by default. Any names like @regan or #channel will also be linked.
$settings = [
	'username' => 'Cyril',
	'channel' => '#accounting',
	'link_names' => true
];

$client = new Nexy\Slack\Client('https://hooks.slack.com/...', $settings);
```

#### 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

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 55.1% 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

Every ~119 days

Recently: every ~188 days

Total

22

Last Release

1889d ago

Major Versions

0.3.0 → 1.0.02015-01-09

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

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

0.1.1PHP &gt;=5.4.0

v2.0.0PHP ^7.1

### Community

Maintainers

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

---

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 (39 commits)")[![yuki777](https://avatars.githubusercontent.com/u/177159?v=4)](https://github.com/yuki777 "yuki777 (9 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)")[![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)")[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (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)")[![mvatansever](https://avatars.githubusercontent.com/u/5843891?v=4)](https://github.com/mvatansever "mvatansever (1 commits)")[![drewbroadley](https://avatars.githubusercontent.com/u/1505816?v=4)](https://github.com/drewbroadley "drewbroadley (1 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (1 commits)")

---

Tags

slackwebhook

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/http-cache

Tools to manage HTTP caching proxies with PHP

36114.7M36](/packages/friendsofsymfony-http-cache)[php-http/httplug-bundle

Symfony integration for HTTPlug

38921.0M54](/packages/php-http-httplug-bundle)[jolicode/slack-php-api

An up to date PHP client for Slack's API

2534.4M12](/packages/jolicode-slack-php-api)[j0k3r/graby

Graby helps you extract article content from web pages

384349.6k2](/packages/j0k3r-graby)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[php-soap/psr18-transport

PSR-18 HTTP Client transport for SOAP

183.4M20](/packages/php-soap-psr18-transport)

PHPackages © 2026

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