Completed Php Driver to interact with the Mattermost Web Service API.
Please read the api documentation for further information on using this application.
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.
$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();
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();
}
//Add a new user
$requestOptions = [
'email' => 'test@test.com',
'username' => 'test',
'password' => 'testpsw'
];
$result = $driver->getUserModel()->createUser($requestOptions);
//Get a user
$result = $driver->getUserModel()->getUserByUsername('username');
//Add a new team
$requestOptions = [
'name' => 'new_team',
'display_name' => 'New Team',
'type' => 'O',
];
$result = $driver->getTeamModel()->createTeam($requestOptions);
//Get a team
$result = $driver->getTeamModel()->getTeamByName('new_team');
//Create a channel
$teamId = 'team_id_to_add_the_channel_to';
$requestOptions = [
'name' => 'new_channel',
'display_name' => 'New Channel',
'type' => 'O',
];
$result = $driver->getChannelModel($teamId)->createChannel($requestOptions);
//Get a channel
$teamId = 'team_id_of_the_channels_to_return';
$result = $driver->getChannelModel($teamId)->getChannelByName('new_channel');
//Create a post
$teamId = 'team_id_to_create_the_post_to';
$channelId = 'channel_id_to_create_the_post_to';
$requestOptions = [
'message' => 'hello world!'
];
$result = $driver->getPostModel($teamId)->createPost($channelId, $requestOptions);
//Get a post
$teamID = 'team_id_of_the_post_to_return';
$channelId = 'channel_id_of_the_post_to_return';
$postId = 'post_id_of_the_post_to_return';
$result = $driver->getPostModel($teamId)->getPost($channelId, $postId);
[x] Add Team data model
[x] Add Channel data model
[x] Add Post data model
[x] Add File data model
[ ] Add Admin data model (in development)
[x] Add Preference data model