The Php Driver to interact with the Mattermost Web Service API.
Branch: master
Clone or download
Latest commit 222ae38 Oct 1, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src added SchemeModel and updated the documentation Sep 29, 2018
.gitignore added TeamModel Apr 20, 2017
LICENSE.txt Rename LICENSE.md to LICENSE.txt Apr 21, 2017
README.md Update README.md Oct 1, 2018
composer.json update requirements Sep 29, 2018
composer.lock terminated UserModel Apr 18, 2017

README.md

php-mattermost-driver (v4)

Latest Stable Version Scrutinizer Code Quality Total Downloads

The Php Driver to interact with the Mattermost Web Service API.

Please read the api documentation for further information on using this application.

Installation

Composer

The best way to install php-mattermost-driver is to use Composer:

composer require gnello/php-mattermost-driver

Read more about how to install and use Composer on your local machine here.

Laravel

If you are going to install this library on laravel maybe you prefer to install the laravel-mattermost-driver.

V3

If you want to install the V3 Driver instead of the V4 one you should do:

composer require gnello/php-mattermost-driver:1.*

Usage

Authentication

 use \Gnello\Mattermost\Driver;

 $container = new \Pimple\Container([
     'driver'    => [
         'url'       => 'your_chat_url',
         'login_id'  => 'your_login_id',
         'password'  => 'your_password',
     ],
     'guzzle'    => [
         //put here any options for Guzzle
     ]
 ]);
 
 $driver = new Driver($container);
 $result = $driver->authenticate();

Check results

This Driver follows the PSR-7 document therefore any response is a ResponseInterface type:

if ($result->getStatusCode() == 200) {
    echo "Everything is ok.";
    var_dump(json_decode($result->getBody()));
} else {
    echo "HTTP ERROR " . $result->getStatusCode();
}

Users endpoint

//Add a new user
$result = $driver->getUserModel()->createUser([
    'email'    => 'test@test.com', 
    'username' => 'test', 
    'password' => 'testpsw'
]);

//Get a user
$result = $driver->getUserModel()->getUserByUsername('username');

Channels endpoint

//Create a channel
$result = $driver->getChannelModel()->createChannel([
    'name'         => 'new_channel',
    'display_name' => 'New Channel',
    'type'         => 'O',
]);


//Get a channel
$result = $driver->getChannelModel()->getChannelByName('team_id_of_the_channels_to_return', 'new_channel');

Posts endpoint

//Create a post
$result = $driver->getPostModel()->createPost([
    'channel_id' => 'The channel ID to post in',
    'messages' => 'The message contents, can be formatted with Markdown',
]);


//Get a post
$result = $driver->getPostModel()->getPost('post_id_of_the_post_to_return');

Files endpoint

//Upload a file
$result = $driver->getFileModel()->uploadFile([
    'channel_id' => 'The ID of the channel that this file will be uploaded to',
    'filename' => 'The name of the file to be uploaded',
    'files' => 'A file to be uploaded',
]);

//Send a post with the file just uploaded
$result = $driver->getPostModel()->createPost([
    'channel_id' => 'The channel ID to post in',
    'messages' => 'The message contents, can be formatted with Markdown',
    'file_ids' => 'A list of file IDs to associate with the post',
]);

Preferences endpoint

//Get a list of the user's preferences
$result = $driver->getPreferenceModel('user_id')->getUserPreference();

Endpoints supported

Contact