get-stream/stream-chat
Composer 安装命令:
composer require get-stream/stream-chat
包简介
A PHP client for Stream Chat (https://getstream.io/chat/)
README 文档
README
Note:
getstream-phpis the new full-product PHP SDK for Stream, covering Chat, Video, Moderation, and Feeds with long-term support.
stream-chat-phpis now in maintenance mode. It will continue to receive critical fixes and requested features, so it is safe to keep using. However, we encourage existing users to migrate when convenient and strongly recommend that new projects start withgetstream-php.Check out the Migration Guide for side-by-side examples covering common use cases.
Official PHP SDK for Stream Chat
Official PHP API client for Stream Chat, a service for building chat applications.
Explore the docs »
Report Bug
·
Request Feature
📝 About Stream
You can sign up for a Stream account at our Get Started page.
You can use this library to access chat API endpoints server-side.
For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries (docs).
⚙️ Installation
$ composer require get-stream/stream-chat
✨ Getting started
require_once "./vendor/autoload.php";
Instantiate a new client, find your API keys in the dashboard.
$client = new GetStream\StreamChat\Client("<api-key>", "<api-secret>");
Generate a token for client-side usage
$token = $client->createToken("bob-1"); // with an expiration time $expiration = (new DateTime())->getTimestamp() + 3600; $token = $client->createToken("bob-1", $expiration);
Update / Create users
$bob = [ 'id' => 'bob-1', 'role' => 'admin', 'name' => 'Robert Tables', ]; $bob = $client->upsertUser($bob); // Batch update is also supported $jane = ['id' => 'jane', 'role' => 'admin']; $june = ['id' => 'june', 'role' => 'user']; $tom = ['id' => 'tom', 'role' => 'guest']; $users = $client->upsertUsers([$jane, $june, $tom]);
Channel types
$channelConf = [ 'name' => 'livechat', 'automod' => 'disabled', 'commands' => ['ban'], 'mutes' => true ]; $channelType = $client->createChannelType($channelConf); $allChannelTypes = $client->listChannelTypes();
Channels and messages
$channel = $client->Channel("messaging", "bob-and-jane"); $state = $channel->create("bob-1", ['bob-1', 'jane']); $channel->addMembers(['mike', 'joe']);
Messaging
$msg_bob = $channel->sendMessage(["text" => "Hi June!"], 'bob-1'); // Reply to a message $reply_bob = $channel->sendMessage(["text" => "Long time no see!"], 'bob-1', $msg_bob['message']['id']);
Reactions
$channel->sendReaction($reply_bob['message']['id'], ['type' => 'like'], 'june');
Moderation
$channel->addModerators(['june']); $channel->demoteModerators(['june']); $channel->banUser('june', ["reason" => "Being a big jerk", "timeout" => 5, "user_id" => 'bob-1']); $channel->unbanUser('june', ["user_id" => 'bob-1']);
Devices
$device_id = "iOS_Device_Token_123"; $client->addDevice($device_id, "apn", "june"); $devices = $client->getDevices('june'); $client->deleteDevice($device_id, 'june');
🙋♀️ Frequently asked questions
- Q: What date formats does the backend accept?
- A: We accept RFC3339 format. So you either use raw strings as date or you implement a serializer for your DateTime object.
class MyDateTime extends \DateTime implements \JsonSerializable { public function jsonSerialize() { // Note: this returns ISO8601 // but it's compatible with 3339 return $this->format("c"); } } $createdAt = new MyDateTime(); $client->search( ['type' => "messaging"], ['created_at' => ['$lte' => $createdAt]], ['limit' => 10] );
✍️ Contributing
We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our Contributor License Agreement (CLA) first. See our license file for more details.
Head over to CONTRIBUTING.md for some development tips.
🧑💻 We are hiring!
We've recently closed a $38 million Series B funding round and we keep actively growing. Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.
Check out our current openings and apply via Stream's website.
get-stream/stream-chat 适用场景与选型建议
get-stream/stream-chat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2M 次下载、GitHub Stars 达 30, 最近一次更新时间为 2019 年 05 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「stream」 「api」 「chat」 「chat-sdk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 get-stream/stream-chat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 get-stream/stream-chat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 get-stream/stream-chat 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This simple PHP class allows you to easily generate Smartsupp.com JS chat code.
Object-Oriented API for PHP streams
Client for the REST API plugin of the OpenFire Server
Safely namespaced guzzle psr7 for WP2Static
Interface for a factory to create Psr\Http\Message\StreamInterface objects
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 2M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 30
- 点击次数: 25
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-05-28