visifo-php / laravel-rocketchat-api-wrapper
Rocket.chat API wrapper for Laravel.
Fund package maintenance!
visifo-php
Requires
- php: ^8.0
- bensampo/laravel-enum: ^3.3|^4.1
- guzzlehttp/guzzle: ^7.3
- illuminate/contracts: ^8.69
- spatie/laravel-package-tools: ^1.9
Requires (Dev)
- nunomaduro/larastan: ^1.0
- orchestra/testbench: ^6.22
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: ^9.3
README
This is a Laravel RocketChat REST API Wrapper. It's simple to use, typesafe and object-oriented.
Installation
You can install the package via composer:
composer require visifo-php/laravel-rocketchat-api-wrapper
You can publish the config file with:
php artisan vendor:publish --provider="visifo\Rocket\RocketServiceProvider" --tag="laravel-rocketchat-api-wrapper-config"
You have to specify your RocketChat Url and the UserId and AuthToken to authenticate with the RocketChat API in your Laravel .env.
You only have to specify the Password if you use the users.update Endpoint, which requires 2FA
ROCKET_URL=your-rocketchat.com ROCKET_USER_ID=RLhxwWHn9RjiWjtdG ROCKET_AUTH_TOKEN=Z9__Y1_Es6OB2kMf4dBD3I6qygRT3s-Lla67pf8AU1p # for users.update you need to set the Password ROCKET_USER_PASSWORD=myPassword
Usage
You can send Requests to an Endpoint via the Endpoint Objects. You can get them from the RocketChat Client like this
$channelsEndpoint = \visifo\Rocket\rocketChat()->channels(); $chatEndpoint = \visifo\Rocket\rocketChat()->chat(); $commandsEndpoint = \visifo\Rocket\rocketChat()->commands(); $rolesEndpoint = \visifo\Rocket\rocketChat()->roles(); $usersEndpoint = \visifo\Rocket\rocketChat()->users();
From there you can make API calls
$channel = $channelsEndpoint->create("myChannel"); // $channel has Type: visifo\Rocket\Objects\Channels\Channel $channelsEndpoint->setTopic($channel->id, "myTopic")
All functions who return the Response from RocketChat will deserialize it into its own simplified Object. Also, some properties gets renamed to something more simple or meaningful, for example "t" to "type" or "_id" to "id"
Alternatively you can make Requests directly via the RocketChat Client which will result in the raw stdClass you get from the RocketChat API
$rocketChatClient = \visifo\Rocket\rocketChat() $channel = $rocketChatClient->post("channels.create", ['name' => 'myChannel']); // $channel has Type: stdClass $rocketChatClient->post("channels.setTopic", ['roomId' => $channel->_id, 'topic' => 'myTopic'])
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.