gnello / php-mattermost-driver
与 Mattermost Web Service API 交互的 Php 驱动程序
v2.18.0
2022-12-08 08:10 UTC
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
This package is auto-updated.
Last update: 2024-09-09 23:04:56 UTC
README
与 Mattermost Web Service API 交互的 PHP 驱动程序。
请阅读 API 文档 以获取有关使用此应用程序的更多信息。
安装
Composer
安装 php-mattermost-driver 的最佳方式是使用 Composer
composer require gnello/php-mattermost-driver
有关如何在您的本地机器上安装和配置 Composer 的更多信息,请参阅 此处。
Laravel
如果您打算在 Laravel 上安装此库,您可能希望安装 laravel-mattermost-driver。
V3
如果您想安装 V3 驱动程序而不是 V4,您应该这样做
composer require gnello/php-mattermost-driver:1.*
用法
身份验证
登录 ID 和密码
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();
令牌
use \Gnello\Mattermost\Driver; $container = new \Pimple\Container([ 'driver' => [ 'url' => 'your_chat_url', 'token' => 'your_token', ] ]); $driver = new Driver($container); $result = $driver->authenticate();
选项
以下列出了所有可用的驱动程序选项,有关 Guzzle 选项,请参阅其 官方文档。
您可以将选项指定如下例所示
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();
检查结果
此驱动程序遵循 PSR-7 文档,因此任何响应都是 ResponseInterface 类型
if ($result->getStatusCode() == 200) { echo "Everything is ok."; var_dump(json_decode($result->getBody())); } else { echo "HTTP ERROR " . $result->getStatusCode(); }
用户端点
//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.
频道端点
//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.
帖子端点
//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.
文件端点
//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.
偏好设置端点
//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.
支持的端点
- Bleve
- 机器人
- 品牌
- 频道
- 集群
- 命令
- 合规性
- 数据保留
- Elasticsearch
- 表情符号
- 文件
- 组
- 集成操作
- 工作
- LDAP
- OAuth
- 插件
- 帖子
- 偏好设置
- 反应
- 角色
- SAML
- 方案
- 状态
- 系统
- 团队
- 线程
- 用户
- Webhooks
没有看到您需要的端点?请随意打开一个问题或 PR!