visifo-php/laravel-rocketchat-api-wrapper

Rocket.chat API wrapper for Laravel.

0.3.7 2022-04-10 17:00 UTC

This package is auto-updated.

Last update: 2024-04-21 20:07:47 UTC


README

Latest Stable Version Total Downloads License PHP Version Require

codecov GitHub Tests Action Status GitHub Code Style Action Status

composer.lock .gitattributes

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.