PHP code example of tiagomichaelsousa / slack-client

1. Go to this page and download the library: Download tiagomichaelsousa/slack-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tiagomichaelsousa / slack-client example snippets


$client = Slack::client($token);

$conversations = $client->conversations()->create('foo');

echo $conversations->channel->name;

$client = Slack::factory()
    ->withApiKey($token)
    ->withBaseUri('slack.com/api/v2') // default: slack.com/api
    ->withHttpClient($client = new \GuzzleHttp\Client([])) // default: HTTP client found using PSR-18 HTTP Client 
    ->withHttpHeader('X-My-Header', 'foo')
    ->withQueryParam('foo', 'bar')
    ->withStreamHandler(fn (RequestInterface $request): ResponseInterface => $client->send($request, [
        'stream' => true // Allows to provide a custom stream handler for the http client.
    ]))
    ->make();

use Slack\Testing\ClientFake;
use Slack\Responses\Conversation\CreateConversationResponse;

$client = new ClientFake([
    CreateConversationResponse::fake([
        'channel' => [
            'name' => 'foo',
        ],
    ]);
]);

$conversations = $client->conversations()->create('foo');

expect($conversations->channel)->name->toBe('foo');