PHPackages                             codeops/slack-client - 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. codeops/slack-client

ActiveLibrary

codeops/slack-client
====================

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

1.7.1(9y ago)051BSD-2-ClausePHPPHP &gt;=5.5.0

Since May 5Pushed 5y ago1 watchersCompare

[ Source](https://github.com/zz/slack)[ Packagist](https://packagist.org/packages/codeops/slack-client)[ RSS](/packages/codeops-slack-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (16)Used By (0)

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

[](#slack-for-php)

[![Build Status](https://camo.githubusercontent.com/ed573b2b76126bfb89667caec4deca135bbcb1be75c1216401a6fb579f2c2bb8/68747470733a2f2f7472617669732d63692e6f72672f6d616b6e7a2f736c61636b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/maknz/slack)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/788f52588346f3095c2514eb298a71ad7c5c63809550cb83efa26c8f1a3252a3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d616b6e7a2f736c61636b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/maknz/slack/?branch=master)[![StyleCI](https://camo.githubusercontent.com/53f6d35f9a765deeec310c1ca734e07c1b370e8dff4b96247eb9c3b1be10029d/68747470733a2f2f7374796c6563692e696f2f7265706f732f31393434383333302f736869656c64)](https://styleci.io/repos/19448330)

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

- Laravel integration: [Slack for Laravel](https://github.com/maknz/slack-laravel)
- Symfony integration: [NexySlackBundle](https://github.com/nexylan/NexySlackBundle)

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

[](#requirements)

- PHP 5.5, 5.6, 7.0 or HHVM

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 maknz/slack
```

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 Maknz\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 Maknz\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`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([
	'fallback' => 'Server health: good',
	'text' => 'Server health: good',
	'color' => '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([
	'fallback' => 'Current server stats',
	'text' => 'Current server stats',
	'color' => 'danger',
	'fields' => [
		[
			'title' => 'CPU usage',
			'value' => '90%',
			'short' => true // whether the field is short enough to sit side-by-side other fields, defaults to false
		],
		[
			'title' => 'RAM usage',
			'value' => '2.5GB of 4GB',
			'short' => 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([
	'fallback' => 'Keep up the great work! I really love how the app works.',
	'text' => 'Keep up the great work! I really love how the app works.',
	'author_name' => 'Jane Appleseed',
	'author_link' => 'https://yourapp.com/feedback/5874601',
	'author_icon' => '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([
	'fallback' => 'It is all broken, man',
	'text' => 'It is _all_ broken, man',
	'pretext' => 'From user: *JimBob*',
	'color' => 'danger',
	'mrkdwn_in' => ['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([
	'fallback' => 'Some fallback text',
	'text' => '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();
```

Each attachment field is also an object, an AttachmentField. They can be used as well instead of their data in array form:

```
$attachment = new Attachment([
	'fallback' => 'Some fallback text',
	'text' => 'The attachment text',
	'fields' => [
		new AttachmentField([
			'title' => 'A title',
			'value' => 'A value',
			'short' => true
		])
	]
]);
```

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

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 82% 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 ~63 days

Recently: every ~147 days

Total

15

Last Release

3496d ago

Major Versions

0.3.0 → 1.0.02015-01-09

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

0.1.1PHP &gt;=5.4.0

1.7.1PHP &gt;=5.5.0

### Community

Maintainers

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

---

Top Contributors

[![maknz](https://avatars.githubusercontent.com/u/992356?v=4)](https://github.com/maknz "maknz (73 commits)")[![zz](https://avatars.githubusercontent.com/u/41499?v=4)](https://github.com/zz "zz (5 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)")[![jwcobb](https://avatars.githubusercontent.com/u/777522?v=4)](https://github.com/jwcobb "jwcobb (1 commits)")[![drewbroadley](https://avatars.githubusercontent.com/u/1505816?v=4)](https://github.com/drewbroadley "drewbroadley (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)")[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (1 commits)")

---

Tags

laravelslack

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laravel/slack-notification-channel

Slack Notification Channel for laravel.

89069.7M111](/packages/laravel-slack-notification-channel)[vluzrmos/slack-api

Wrapper for Slack.com WEB API.

102589.1k3](/packages/vluzrmos-slack-api)[beyondcode/slack-notification-channel

Slack Notification Channel for Laravel using API tokens.

85525.8k](/packages/beyondcode-slack-notification-channel)[jeremykenedy/slack

A simple PHP package for sending messages to Slack.

10895.4k1](/packages/jeremykenedy-slack)

PHPackages © 2026

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