gnello / php-mattermost-driver
The Php Driver to interact with the Mattermost Web Service API
Installs: 230 437
Dependents: 3
Suggesters: 0
Security: 0
Stars: 79
Watchers: 4
Forks: 27
Open Issues: 7
Requires
- php: >=5.5.0
- ext-json: *
- guzzlehttp/guzzle: ^6.2|^7.4
- pimple/pimple: ~3.0
- psr/http-message: ^1.0
Requires (Dev)
- symfony/var-dumper: ^3.1
- dev-master
- v2.18.0
- v2.17.0
- v2.16.1
- v2.16.0
- v2.15.0
- v2.14.3
- v2.14.2
- v2.14.1
- v2.14.0
- v2.13.0
- v2.12.0
- v2.11.0
- v2.10.0
- v2.9.1
- v2.9.0
- v2.8.3
- v2.8.2
- v2.8.1
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.1
- v2.4.0
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.1
- v2.0.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.0
- dev-dependabot/composer/symfony/var-dumper-6.4.4
This package is auto-updated.
Last update: 2024-12-02 21:09:36 UTC
README
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
Login id and password
use \Gnello\Mattermost\Driver; $container = new \Pimple\Container([ 'driver' => [ 'url' => 'your_chat_url', 'login_id' => 'your_login_id', 'password' => 'your_password', ] ]); $driver = new Driver($container); $result = $driver->authenticate();
Token
use \Gnello\Mattermost\Driver; $container = new \Pimple\Container([ 'driver' => [ 'url' => 'your_chat_url', 'token' => 'your_token', ] ]); $driver = new Driver($container); $result = $driver->authenticate();
Options
Below a list of all the Driver available options, for the Guzzle options please refer to its official documentation.
You can specify the options as shown in the following example:
use \Gnello\Mattermost\Driver; $container = new \Pimple\Container([ 'driver' => [ //put here any options for the driver ], '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'); //Please read the UserModel class or refer to the api documentation for a complete list of available methods.
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_channel_to_return', 'new_channel'); //Search a channel $result = $driver->getChannelModel()->searchChannels($teamId, [ 'term' => "full or partial name or display name of channels" ]); //Please read the ChannelModel class or refer to the api documentation for a complete list of available methods.
Posts endpoint
//Create a post $result = $driver->getPostModel()->createPost([ 'channel_id' => 'The channel ID to post in', 'message' => 'The message contents, can be formatted with Markdown', ]); //Get a post $result = $driver->getPostModel()->getPost('post_id_of_the_post_to_return'); //Please read the PostModel class or refer to the api documentation for a complete list of available methods.
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' => fopen('Path of the file to be uploaded', 'rb'), ]); //Send a post with the file just uploaded $result = $driver->getPostModel()->createPost([ 'channel_id' => 'The channel ID to post in', 'message' => 'The message contents, can be formatted with Markdown', 'file_ids' => 'A list of file IDs to associate with the post', ]); //Please read the FileModel class or refer to the api documentation for a complete list of available methods.
Preferences endpoint
//Get a list of the user's preferences $result = $driver->getPreferenceModel('user_id')->getUserPreference(); //Please read the PreferenceModel class or refer to the api documentation for a complete list of available methods.
Endpoints supported
- Bleve
- Bots
- Brand
- Channels
- Cluster
- Commands
- Compliance
- DataRetention
- Elasticsearch
- Emoji
- Files
- Groups
- Integration Actions
- Jobs
- LDAP
- OAuth
- Plugins
- Posts
- Preferences
- Reactions
- Roles
- SAML
- Schemes
- Status
- System
- Teams
- Threads
- Users
- Webhooks
Don't you see the endpoint you need? Feel free to open an issue or a PR!