baha2odeh / yii2-rocket-chat-rest-client
Yii2 Rocket Chat REST API client in PHP.
Installs: 240
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 35
pkg:composer/baha2odeh/yii2-rocket-chat-rest-client
Requires
This package is auto-updated.
Last update: 2021-02-23 20:11:53 UTC
README
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": { "baha2odeh/yii2-rocket-chat-rest-client": "dev-master" } }
And run composer to update your dependencies:
$ php composer.phar update
After this, you have to register chat instance into components
common/config/main-local.php
'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:
$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');
Post a message
// create a new channel $channel = $user->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).