jungleran / rocket-chat-rest-client
There is no license information available for the latest version (v1.1.0) of this package.
Rocket Chat REST API client in PHP.
v1.1.0
2022-10-12 13:03 UTC
Requires
Requires (Dev)
This package is auto-updated.
Last update: 2024-11-12 18:02:05 UTC
README
Cloned from fab1en/rocket-chat-rest-client
Use this client if you need to connect to Rocket Chat with a software written in PHP, such as WordPress or Drupal.
How to use
This Rocket Chat client is installed via Composer. To install, simply add it
to your composer.json
file:
{ "require": { "fab1en/rocket-chat-rest-client": "dev-master" } }
And run composer to update your dependencies:
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update
Then, import the autoload.php
from your vendor
folder.
After this, you have to define some constants to point to your Rocket Chat instance
define('REST_API_ROOT', '/api/v1/'); define('ROCKET_CHAT_INSTANCE', 'https://my-rocket-chat-instance.example.org');
Finally, instance the classes you need:
$api = new \RocketChat\Client(); echo $api->version(); echo "\n"; // login as the main admin user $admin = new \RocketChat\User('my-admin-name', 'my-admin-password'); if( $admin->login() ) { echo "admin user logged in\n"; }; $admin->info(); echo "I'm {$admin->nickname} ({$admin->id}) "; echo "\n";
Manage user
// create a new user $newuser = new \RocketChat\User('new_user_name', 'new_user_password', array( 'nickname' => 'New user nickname', 'email' => 'newuser@example.org', )); if( !$newuser->login(false) ) { // actually create the user if it does not exist yet $newuser->create(); } echo "user {$newuser->nickname} created ({$newuser->id})\n";
Post a message
// create a new channel $channel = new \RocketChat\Channel( 'my_new_channel', array($newuser, $admin) ); $channel->create(); // post a message $channel->postMessage('Hello world');
Credits
This REST client uses the excellent Httpful PHP library by Nate Good (github repo is here).