PHP code example of serafim / gitter-api

1. Go to this page and download the library: Download serafim/gitter-api 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/ */

    

serafim / gitter-api example snippets


use Gitter\Client;

$client = new Client($token); 
// OR
$client = new Client($token, $logger); // $logger are instance of \Psr\Log\LoggerInterface

// ... SOME ACTIONS ...

$client->connect(); // Locks current runtime and starts an EventLoop (for streaming requests)

// $client = new \Gitter\Client('token');

$client->groups;   // Groups resource (Traversable)
$client->messages; // Messages resource
$client->rooms;    // Rooms resource (Traversable)
$client->users;    // Users resource

foreach ($client->rooms as $room) {
    var_dump($room);
}

$observer = $client->rooms->messages('roomId'); // Observer

$observer->subscribe(function ($message) {
    var_dump($message);
});

// Connect to stream!
$client->connect();

$client->notify($hookId)
    // ->error($message) - Send "Error" message
    // ->info($message) - Send "Info" message
    // ->withLevel(...) - Sets up level
    ->send('Your message with markdown'); // Send message with markdown content

$route = Route::get('rooms/{roomId}/chatMessages')
    ->with('roomId', $roomId)
    ->toStream();
    
// Contains "GET https://stream.gitter.im/v1/rooms/.../chatMessages" url

$client->viaStream()->request($route)->subscribe(function($message) {
     var_dump($message);
    // Subscribe on every message in target room (Realtime subscribtion)
});

$client->connect();