dev-master
9999999-devYii2 Rocket Chat REST API client in PHP.
The Requires
1.1
1.1.0.0Yii2 Rocket Chat REST API client in PHP.
The Requires
Yii2 Rocket Chat REST API client in PHP.
Use this client if you need to connect to Rocket Chat with a software written in PHP, such as WordPress or Drupal., (*1)
This Rocket Chat client is installed via Composer. To install, simply add it
to your composer.json
file:, (*2)
{ "require": { "baha2odeh/yii2-rocket-chat-rest-client": "dev-master" } }
And run composer to update your dependencies:, (*3)
$ php composer.phar update
After this, you have to register chat instance into components
common/config/main-local.php, (*4)
'components' => [ ..... 'chat' => [ 'class' => '\Baha2Odeh\RocketChat\Rocket', 'rocket_chat_instance' => 'http://rocket-chat-server:3000', 'rest_api_root' => '/api/v1/' ], ]
Finally, instance the classes you need:, (*5)
$user = \Yii::$app->chat->user(); $info = [ 'name'=>'name', 'username'=>'username', 'email'=>'username@email.com', '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');
This REST client uses the excellent Httpful PHP library by Nate Good (github repo is here)., (*6)
Yii2 Rocket Chat REST API client in PHP.
Yii2 Rocket Chat REST API client in PHP.