Skip to content

Baha2Odeh/yii2-rocket-chat-rest-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

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'=>'[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');
       
        
       

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).

About

Rocket Chat REST API client in PHP

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%