{"id":13993518,"url":"https://github.com/sagebind/slack-client","last_synced_at":"2025-07-22T17:32:41.089Z","repository":{"id":32124265,"uuid":"35696813","full_name":"sagebind/slack-client","owner":"sagebind","description":"A better Slack client, with RTM API support.","archived":true,"fork":false,"pushed_at":"2018-01-25T12:03:03.000Z","size":375,"stargazers_count":192,"open_issues_count":18,"forks_count":107,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-07-21T20:03:03.140Z","etag":null,"topics":["async","slack"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagebind.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-15T21:06:17.000Z","updated_at":"2025-02-16T04:23:36.000Z","dependencies_parsed_at":"2022-08-07T17:15:22.858Z","dependency_job_id":null,"html_url":"https://github.com/sagebind/slack-client","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/sagebind/slack-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagebind%2Fslack-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagebind%2Fslack-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagebind%2Fslack-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagebind%2Fslack-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagebind","download_url":"https://codeload.github.com/sagebind/slack-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagebind%2Fslack-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266473595,"owners_count":23934498,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","slack"],"created_at":"2024-08-09T14:02:25.143Z","updated_at":"2025-07-22T17:32:40.787Z","avatar_url":"https://github.com/sagebind.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# PHP Slack API Client\n[![Build](https://img.shields.io/scrutinizer/build/g/sagebind/slack-client.svg)](https://scrutinizer-ci.com/g/sagebind/slack-client)\n[![Version](https://img.shields.io/packagist/v/coderstephen/slack-client.svg)](https://packagist.org/packages/coderstephen/slack-client)\n[![License](https://img.shields.io/packagist/l/coderstephen/slack-client.svg)](https://packagist.org/packages/coderstephen/slack-client)\n[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/sagebind/slack-client.svg)](https://scrutinizer-ci.com/g/sagebind/slack-client)\n[![Code Quality](https://img.shields.io/scrutinizer/g/sagebind/slack-client.svg)](https://scrutinizer-ci.com/g/sagebind/slack-client)\n[![Downloads](https://img.shields.io/packagist/dt/coderstephen/slack-client.svg)](https://packagist.org/packages/coderstephen/slack-client)\n\nThis is an API client for [Slack](http://slack.com) for PHP clients, with support for the [Real Time Messaging API](http://api.slack.com/rtm) (RTM API) using web sockets.\n\n## Project status\nThis project is based on some outdated and unmaintained libraries, and itself is not being actively maintained.\n\n## Overview\nThis library was created primarily for [Slackyboy](https://github.com/sagebind/slackyboy), but was branched off into its own codebase so it could be used in other projects as well. I created this client because existing clients were either too complicated to use, or buggy, or incomplete. This is also the first PHP client I am aware of to support Slack's RTM API.\n\n## Installation\nInstall with [Composer](http://getcomposer.org), obviously:\n\n```sh\n$ composer require coderstephen/slack-client\n```\n\nPlease note that the current version has unstable dependencies.\n\nIn order to install those dependencies, you can set `\"minimum-stability\"` in your `composer.json`, and recommend that you set `\"prefer-stable\"`:\n\n```json\n{\n    \"minimum-stability\": \"dev\",\n    \"prefer-stable\": true\n}\n```\n\n## Usage\nFirst, you need to create a client object to connect to the Slack servers. You will need to acquire an API token for your app first from Slack, then pass the token to the client object for logging in. Since this library uses React, you must also pass in an event loop object:\n\n```php\n$loop = \\React\\EventLoop\\Factory::create();\n\n$client = new \\Slack\\ApiClient($loop);\n$client-\u003esetToken('YOUR-TOKEN-HERE');\n// ...\n$loop-\u003erun();\n```\n\nAssuming your token is valid, you are good to go! You can now use wrapper methods for accessing most of the [Slack API](http://api.slack.com). Below is an example of posting a message to a channel as the logged in user:\n\n```php\n$client-\u003egetChannelById('C025YTX9D')-\u003ethen(function (\\Slack\\Channel $channel) use ($client) {\n    $client-\u003esend('Hello from PHP!', $channel);\n});\n```\n\n### Advanced messages\nSlack supports messages much more rich than plain text through attachments. The easiest way to create a custom message is with a `MessageBuilder`:\n\n```php\nuse Slack\\Message\\{Attachment, AttachmentBuilder, AttachmentField};\n\n$message = $client-\u003egetMessageBuilder()\n    -\u003esetText('Hello, all!')\n    -\u003esetChannel($someChannelObject)\n    -\u003eaddAttachment(new Attachment('My Attachment', 'attachment text'))\n    -\u003eaddAttachment(new Attachment('Build Status', 'Build failed! :/', 'build failed', 'danger'))\n    -\u003eaddAttachment(new AttachmentBuilder()\n        -\u003esetTitle('Some Fields')\n        -\u003esetText('fields')\n        -\u003esetColor('#BADA55')\n        -\u003eaddField(new AttachmentField('Title1', 'Text', false))\n        -\u003eaddField(new AttachmentField('Title2', 'Some other text', true))\n        -\u003ecreate()\n    ]))\n    -\u003ecreate();\n\n$client-\u003epostMessage($message);\n```\n\nCheck the [API documentation](http://sagebind.github.io/slack-client/api) for a list of all methods and properties that messages, attachments, and fields support.\n\n\n### Asynchronous requests and promises\nAll client requests are made asynchronous using [React promises](https://github.com/reactphp/promise). As a result, most of the client methods return promises. This lets you easily compose request orders and handle them as you need them. Since it uses React, be sure to call `$loop-\u003erun()` or none of the requests will be sent.\n\nReact allows the client to perform well and prevent blocking the entire thread while making requests. This is especially useful when writing real-time apps, like Slack chat bots.\n\n### Real Time Messaging API\nYou can also connect to Slack using the [Real Time Messaging API](http://api.slack.com/rtm). This is often useful for creating Slack bots or message clients. The real-time client is like the regular client, but it enables real-time incoming events. First, you need to create the client:\n\n```php\n$client = new \\Slack\\RealTimeClient();\n$client-\u003esetToken('YOUR-TOKEN-HERE');\n$client-\u003econnect();\n```\n\nThen you can use the client as normal; `RealTimeClient` extends `ApiClient`, and has the same API for sending requests. You can attach a callback to handle incoming Slack events using `RealTimeClient::on()`:\n\n```php\n$client-\u003eon('file_created', function($data) {\n    echo 'A file was created called ' . $data['file']['name'] . '!\\n';\n});\n```\n\nBelow is a very simple, complete example:\n\n```php\n$loop = React\\EventLoop\\Factory::create();\n\n$client = new Slack\\RealTimeClient($loop);\n$client-\u003esetToken('YOUR-TOKEN-HERE');\n\n// disconnect after first message\n$client-\u003eon('message', function ($data) use ($client) {\n    echo \"Someone typed a message: \".$data['text'].\"\\n\";\n    $client-\u003edisconnect();\n});\n\n$client-\u003econnect()-\u003ethen(function () {\n    echo \"Connected!\\n\";\n});\n\n$loop-\u003erun();\n```\n\nSee the [Slack API documentation](http://api.slack.com/events) for a list of possible events.\n\n## Documentation\nYou can view the complete API documentation [here](http://sagebind.github.io/slack-client/api).\n\n## Running tests\nYou can run automated unit tests using [PHPUnit](http://phpunit.de) after installing dependencies:\n\n```sh\n$ vendor/bin/phpunit\n```\n\n## Where to get help\nNeed help? Just [send me an email](mailto:me@stephencoakley.com) with your questions. Be sure to add \"Slack client\" to the message subject line so I know how I can help you out.\n\n## License\nThis library is licensed under the MIT license. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagebind%2Fslack-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagebind%2Fslack-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagebind%2Fslack-client/lists"}