cedricziel/mattermost-php
Composer 安装命令:
composer require cedricziel/mattermost-php
包简介
PHP Bindings for Mattermost
README 文档
README
Built for building apps and integrations for Mattermost.
Documentation: https://cedricziel.github.io/mattermost-php/
Installation
composer require cedricziel/mattermost-php
Usage
API Client
The API client is a simple wrapper around the Mattermost API. It provides a fluent interface to interact with the API.
<?php use CedricZiel\MattermostPhp\Client; use CedricZiel\MattermostPhp\Client\Model\CreatePostRequest; // create a client instance $client = new Client(getenv('MATTERMOST_SITE_URL')); // provide a token and authenticate $client->setToken(getenv('MATTERMOST_TOKEN')); $yourUser = $client->authenticate(); // OR authenticate with username and password $client->authenticate($loginId, $password); // get the team and a specific channel $team = $client->teams()->getTeamByName(getenv('MATTERMOST_TEAM_NAME')); $client->channels()->getAllChannels(per_page: 100); $channel = $client->channels()->getChannelByName($team->id, 'town-square'); // create a post in the channel $post = $client->posts()->createPost(new CreatePostRequest($channel->id, 'Hello World!')); var_dump($post);
Slash commands
Slash commands are one of the most common ways to integrate with Mattermost. They are invoked by typing a slash followed by the command name and any arguments into the message box in Mattermost (e.g. /weather New York).
To implement a slash command that would respond with the weather in a given city, you would do something like this:
Note: This library does recommend using a PSR-15 compatible middleware stack to handle the request and response.
This library provides an AbstractSlashCommand class that can be extended to implement a slash command that does everything
once it needs to handle a request.
<?php // your PSR-15 ServerRequestInterface implementation $serverRequest = '...'; $slashCommand = new class('weather') extends \CedricZiel\Mattermost\SlashCommands\AbstractSlashCommand { public function execute(SlashCommandInput $input): SlashCommandOutput { $city = $input->getParameters(); /** * Your business logic here */ $weather = $this->getWeatherForCity($city); return SlashCommandOutput::create() ->setText(sprintf('The weather in %s is %s', $city, $weather)); } }; // handle the request. this will invoke the slash command and return a PSR-7 compatible response $slashCommand->handle($serverRequest);
Please look at the tests for more examples.
License
MIT
cedricziel/mattermost-php 适用场景与选型建议
cedricziel/mattermost-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.92k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2024 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cedricziel/mattermost-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cedricziel/mattermost-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 17.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-02