Coder Social home page Coder Social logo

rocket-chat's Introduction

Fork of https://github.com/albanafmeti/rocket-chat

Rocket-chat is a rest client package for Laravel that you can use to consume Rocket.Chat REST API.

Install

This package is installed via Composer. To install, simply add it to your composer.json file:

{
    "require": {
        "noisim/rocket-chat": "dev-master"
    }
}

and run composer to update the dependencies composer update.

Then open your Laravel config file config/app.php and in the $providers array add the service provider for this package.

\Noisim\RocketChat\RocketChatServiceProvider::class

Finally generate the configuration file running in the console:

php artisan vendor:publish --tag=config

How to use

## app/Http/Auth/RegisterController.php
//sync rocketchat user at main laravel registration

    protected function create(array $data)
    {
        $password = Hash::make($data['password']);
        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => $password,
        ]);

        $chatUser = new ChatUser($user->name, $password, $user->name, $user->email);
        $chatUser->store();
        $chatUser->login();

        $user->chat_id = $chatUser->id();
        $user->chat_token = $chatUser->authToken();
        $user->save();
        
        return $user;
    }
}


## app/User.php
//add shortcuts in your user class

use Noisim\RocketChat\Entities\User as ChatUser;
use Noisim\RocketChat\Entities\Im as ChatIm;

class User extends Authenticatable
{
    //..
    
    public function chatUser(){
        return (new ChatUser())->loginByToken($this->chat_token, $this->chat_id);
    }

    public function chatIm(){
        return (new ChatIm())->loginByToken($this->chat_token, $this->chat_id);
    }
}


## app/Http/Controllers/ChatController.php
//samples

    public function im($id)
    {
        //create im (from current auth user to another one)
        $user = auth()->user(); 
        $profile = User::find($id); 
        
        $user->chatIm()->create($profile->name);
        //...

    }

rocket-chat's People

Contributors

albanafmeti avatar zofe avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.