PHP code example of fab1en / rocket-chat-rest-client
1. Go to this page and download the library: Download fab1en/rocket-chat-rest-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$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";
// create a new user
$newuser = new \RocketChat\User('new_user_name', 'new_user_password', array(
'nickname' => 'New user nickname',
'email' => '[email protected]',
));
if( !$newuser->login(false) ) {
// actually create the user if it does not exist yet
$newuser->create();
}
echo "user {$newuser->nickname} created ({$newuser->id})\n";
// create a new channel
$channel = new \RocketChat\Channel( 'my_new_channel', array($newuser, $admin) );
$channel->create();
// post a message
$channel->postMessage('Hello world');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.