PHP code example of baha2odeh / yii2-rocket-chat-rest-client
1. Go to this page and download the library: Download baha2odeh/yii2-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/ */
baha2odeh / yii2-rocket-chat-rest-client example snippets
'components' => [
.....
'chat' => [
'class' => '\Baha2Odeh\RocketChat\Rocket',
'rocket_chat_instance' => 'http://rocket-chat-server:3000',
'rest_api_root' => '/api/v1/'
],
]
$user = \Yii::$app->chat->user();
$info = [
'name'=>'name',
'username'=>'username',
'email'=>'[email protected] ',
'pass'=>'123123123'
];
if(($userInfo = $user->login($info['username'],$info['pass'],true))){
print_r($userInfo);
}else if($user->register($info) && ($userInfo = $user->login($info['username'],$info['pass'],true))){
print_r($userInfo);
}else{
die($user->error);
}
$group = $user->group('group-name',[$userInfo->userId]);
$group->create();
$group->postMessage('Hello world');
// create a new channel
$channel = $user->channel( 'my_new_channel', array($newuser, $admin) );
$channel->create();
// post a message
$channel->postMessage('Hello world');