get-stream / stream-chat
A PHP client for Stream Chat (https://getstream.io/chat/)
Installs: 1 054 443
Dependents: 2
Suggesters: 0
Security: 0
Stars: 30
Watchers: 31
Forks: 9
Open Issues: 2
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^6.5.8 || ^7.0.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0.0
- phan/phan: ^5.3.2
- phpunit/phpunit: ^9.5.20
- dev-main
- 3.6.0
- 3.5.0
- 3.4.1
- 3.4.0
- 3.3.0
- v3.2.1
- v3.2.0
- 3.1.0
- 3.0.0
- 2.11.1
- 2.11.0
- 2.10.0
- 2.9.0
- 2.8.0
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.0
- 2.4.0
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.10
- v1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- dev-release-3.6.0
- dev-feature/pinning-archiving
- dev-pin-archive-fix
- dev-campaign
- dev-imports
This package is auto-updated.
Last update: 2024-12-05 12:40:46 UTC
README
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.