This library mostly contains automatically generated code from the official Slack OpenAPI spec.
The library provides three kinds of PHP classes:
- endpoints represent requests to API methods
- models represent data from the API
- normalizers transform JSON from the API to PHP models
If you use the provided Client, you don't have to understand how the library works internally. Calling one of its method will make the HTTP request to the API and return the corresponding PHP object.
Use the ClientFactory
to generate a Client
configured with your token:
<?php
use JoliCode\Slack\Api\Client;
use JoliCode\Slack\ClientFactory;
/** @var Client $client */
$client = ClientFactory::create($yourToken);
The client contains all the methods to communicate with Slack API. Checkout its PHP doc to know which option you can provide to each method:
<?php
//...
$members = $client->usersList(['limit' => 100])->getMembers();
💡 If you need a Slack Token, please follow the instructions at https://api.slack.com/authentication/basics
Here are some examples of library's usages:
Slack's OpenAPI spec is not 100% complete yet, hence our generated client may miss some features.
If you miss an option in a method, until Slack add it to their spec, we can manually add it to our versioned spec then regenerate and release a new version of the library.
The Slack specification is not up to date and miss some critical parts. We do build a better one on top of the official but it can't be perfect.
What's good is that some models use \ArrayObject
as base classes so if the
API returns data we don't have in the mapping, you can still access it via
Array like syntax:
$results = $client->searchMessages([
'query' => 'test'
]);
var_dump($results->getOk()); // Mapped
var_dump($results['messages']); // Not mapped but still readable
Feel free to open issues for those missing fields.