PHPackages                             markenwerk/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. [API Development](/categories/api)
4. /
5. markenwerk/slack-client

AbandonedArchivedLibrary[API Development](/categories/api)

markenwerk/slack-client
=======================

A basic Slack client library providing simple posting to Slack channels using the webhook API.

2.0.1(9y ago)0231MITPHPPHP &gt;=5.3

Since May 2Pushed 9y ago1 watchersCompare

[ Source](https://github.com/markenwerk/php-slack-client)[ Packagist](https://packagist.org/packages/markenwerk/slack-client)[ Docs](http://markenwerk.net/)[ RSS](/packages/markenwerk-slack-client/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

PHP Slack Client
================

[](#php-slack-client)

[![Build Status](https://camo.githubusercontent.com/9d06bc3911d5614e328c5e1660c2efcd663ac29f1108de20f4ce5f978977cf04/68747470733a2f2f7472617669732d63692e6f72672f6d61726b656e7765726b2f7068702d736c61636b2d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/markenwerk/php-slack-client)[![Test Coverage](https://camo.githubusercontent.com/435cc4e1cbe5c2d91715bd0f0d866d176845bfd081f621450947af4cea4bf791/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d61726b656e7765726b2f7068702d736c61636b2d636c69656e742f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/markenwerk/php-slack-client/coverage)[![Dependency Status](https://camo.githubusercontent.com/37aad0955b2494acb8cf2c34501d3bd78cc7a8e1bb5de1a0fb16b7bbd04fd21a/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537323865326138613063613335303035303833666239302f62616467652e737667)](https://www.versioneye.com/user/projects/5728e2a8a0ca35005083fb90)[![SensioLabs Insight](https://camo.githubusercontent.com/c7a5d1d336d8416d345407029ea8a85bcbdc1df2b63153f2e7508a46ac83fcdb/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f64343538336434622d353432352d343564342d393534642d3862636635633330633962312e737667)](https://insight.sensiolabs.com/projects/d4583d4b-5425-45d4-954d-8bcf5c30c9b1)[![Code Climate](https://camo.githubusercontent.com/24ab52f304faf7074eac24aca7de9d9628939083942dee2d35b1c8f02ec2035b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d61726b656e7765726b2f7068702d736c61636b2d636c69656e742f6261646765732f6770612e737667)](https://codeclimate.com/github/markenwerk/php-slack-client)[![Latest Stable Version](https://camo.githubusercontent.com/3c32d3e703390d7deaf1bc75b2a437b6e1074810cda8bbb5c9202d7da8524d2f/68747470733a2f2f706f7365722e707567782e6f72672f6d61726b656e7765726b2f736c61636b2d636c69656e742f762f737461626c65)](https://packagist.org/packages/markenwerk/slack-client)[![Total Downloads](https://camo.githubusercontent.com/9f20f5be09d1ac54174d5ca94c3b5a67a785052e3aecaab6bd86998ca61072a1/68747470733a2f2f706f7365722e707567782e6f72672f6d61726b656e7765726b2f736c61636b2d636c69656e742f646f776e6c6f616473)](https://packagist.org/packages/markenwerk/slack-client)[![License](https://camo.githubusercontent.com/dac9856068a9cd34d5caa6f40cfdb15ab962ba5519bdf262f27e2e7832eb4df7/68747470733a2f2f706f7365722e707567782e6f72672f6d61726b656e7765726b2f736c61636b2d636c69656e742f6c6963656e7365)](https://packagist.org/packages/markenwerk/slack-client)

A basic Slack client library providing simple posting to Slack channels using the webhook API.

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

[](#installation)

```
{
   	"require": {
        "markenwerk/slack-client": "~2.0"
    }
}

```

Usage
-----

[](#usage)

### Autoloading and namesapce

[](#autoloading-and-namesapce)

```
require_once('path/to/vendor/autoload.php');

```

### Posting to a channel or member

[](#posting-to-a-channel-or-member)

The following example will post to a Slack channel or member looking like this:

[![Slack Example Post](example-post.png "Slack Example Post")](example-post.png)

#### Setup the API client

[](#setup-the-api-client)

```
use Markenwerk\SlackClient\SlackClient;

$client = new SlackClient();
$client
	->setSubdomainName('markenwerk')
	->setToken('')
	->setUsername('PHP SlackClient');

```

#### Setup a Slack message with attachments

[](#setup-a-slack-message-with-attachments)

```
use Markenwerk\SlackClient\SlackAttachment;
use Markenwerk\SlackClient\SlackAttachmentField;
use Markenwerk\SlackClient\SlackMessage;

$message = new SlackMessage();
$message
	->setText('A basic Slack client library providing simple posting to Slack channels using the webhook API.')
	->setIconUrl('https://avatars2.githubusercontent.com/u/5921253?v=3&s=200')
	->setUnfurlLinks(true)
	->setUnfurlMedia(true);

$attachment = new SlackAttachment();
$attachment
	->setText('A basic Slack client library providing simple posting to Slack channels using the webhook API.')
	->setPretext('A basic Slack client library.')
	->setFallback('A basic Slack client library providing simple posting to Slack channels using the webhook API.')
	->setColor(SlackAttachment::COLOR_WARNING);

$shortAttachmentField = new SlackAttachmentField();
$shortAttachmentField
	->setTitle('Short field')
	->setValue('Some chars')
	->setShort(true);

$anotherShortAttachmentField = new SlackAttachmentField();
$anotherShortAttachmentField
	->setTitle('Short field')
	->setValue('Some chars')
	->setShort(true);

$attachmentField = new SlackAttachmentField();
$attachmentField
	->setTitle('Regular field')
	->setValue('Some more chars')
	->setShort(false);

$anotherAttachmentField = new SlackAttachmentField();
$anotherAttachmentField
	->setTitle('Regular field')
	->setValue('Some more chars')
	->setShort(false);

$attachment
	->addField($shortAttachmentField)
	->addField($anotherShortAttachmentField)
	->addField($attachmentField)
	->addField($anotherAttachmentField);

$message->addAttachment($attachment);

```

#### Post to a channel

[](#post-to-a-channel)

```
$client->postToChannel('#channel', $message);

```

#### Post to a member

[](#post-to-a-member)

```
$client->postToMember('@member', $message);

```

---

Exception handling
------------------

[](#exception-handling)

PHP Basic HTTP Client provides different exceptions – also provided by the PHP Common Exceptions project – for proper handling.
You can find more information about [PHP Common Exceptions at Github](https://github.com/markenwerk/php-common-exceptions).

### Exceptions to be expected

[](#exceptions-to-be-expected)

In general you should expect that any setter method could thrown an `\InvalidArgumentException`. The following exceptions could get thrown while using PHP Slack Client.

- `Markenwerk\CommonException\ParserException\StringifyException` on posting to Slack
- `Markenwerk\CommonException\NetworkException\UnexpectedResponseException` on posting to Slack
- `Markenwerk\CommonException\NetworkException\ConnectionTimeoutException` on posting to Slack
- `Markenwerk\CommonException\NetworkException\CurlException` on posting to Slack

---

Contribution
------------

[](#contribution)

Contributing to our projects is always very appreciated.
**But: please follow the contribution guidelines written down in the [CONTRIBUTING.md](https://github.com/markenwerk/php-slack-client/blob/master/CONTRIBUTING.md) document.**

License
-------

[](#license)

PHP Slack Client is under the MIT license.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity61

Established project with proven stability

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 ~24 days

Total

4

Last Release

3636d ago

Major Versions

0.0.1 → 1.0.02016-05-03

1.0.0 → 2.0.02016-07-11

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5921241?v=4)[Martin Brecht-Precht](/maintainers/bonscho)[@Bonscho](https://github.com/Bonscho)

---

Tags

api-clientcomposer-packagephp-libraryslackslack-clientwebhook-apiapislack

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jolicode/slack-php-api

An up to date PHP client for Slack's API

2554.6M13](/packages/jolicode-slack-php-api)[mpociot/slack-client

A better Slack client, with RTM API support

51266.0k1](/packages/mpociot-slack-client)[lisennk/laravel-slack-events-api

Slack Events API for Laravel 5, 6, 7 and 8

3911.6k](/packages/lisennk-laravel-slack-events-api)[lisennk/laravel-slack-web-api

Light Laravel wrapper for Slack Web API

2117.7k](/packages/lisennk-laravel-slack-web-api)

PHPackages © 2026

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