PHP Classes
elePHPant
Icontem

Laravel Talk: Manage a multiple user conversation system

Recommend this page to a friend!
  Info   View files Documentation   Videos Videos   View files View files (23)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-02-27 (28 days ago) RSS 2.0 feedNot enough user ratingsTotal: 225 This week: 1All time: 7,704 This week: 693Up
Version License PHP version Categories
talk 1.0.10Custom (specified...5PHP 5, Databases, Chat
Description Author

This package can manage multiple user conversation system.

It can manage the conversation of multiple users for instance in chat room or between private messages.

The package can store messages exchanged between users in a database.

  Performance   Level  
Name: Nahid Bin Azhar <contact>
Classes: 8 packages by
Country: Bangladesh Bangladesh
Age: 26
All time rank: 165826 in Bangladesh Bangladesh
Week rank: 32 Up1 in Bangladesh Bangladesh Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Details

Laravel-Talk

Talk is a Laravel 5 based user conversation (inbox) system with realtime messaging. You can easily integrate this package with any Laravel based project. It helps you to develop a messaging system in just few mins. Here is a project screenshot that was developed by Talk.

Talk v2.1.0 is supported realtime messaging. Learn more about Talk Live Messaging

Feedback

If you already used Talk, please share your experience with us. It will makes the project better.

Give us your feedback

Built with Talk

If you are using Talk in your project please share your project URL or project name with us. It will inspire others people to use Talk.

See which project was Built with Talk

Caution

> Do not migrate 1.1.7 from its higher version directly. Please try our sample project first and then apply it on your project.

Talk-Example Screenshot

You may try Talk-Example project.

Or you can try live Demo by using this credentials

username: admin   
password: admin

So let's start your tour :)

Features

  • Head to head messaging
  • Realtime messaging
  • Creating new conversation
  • Message threads with latest one
  • View conversations by user id or conversation id
  • Support pagination in threads and messages
  • Delete(soft delete) message from both end. Sender and receiver can delete their message from their end.
  • Permanent delete message
  • Mark message as seen
  • Only participant can view or access there message or message threads

Installation

Talk is a Larravel package so you can install it via composer. Run this command in your terminal from your project directory.

composer require nahid/talk

Wait for a while, Composer will automatically install Talk in your project.

Configuration

When the download is complete, you have to call this package service in config/app.php config file. To do that, add this line in app.php in providers section

Nahid\Talk\TalkServiceProvider::class,

To use facade you have to add this line in app.php in aliases array

'Talk'      => Nahid\Talk\Facades\Talk::class,

Now run this command in your terminal to publish this package resources

php artisan vendor:publish --provider="Nahid\Talk\TalkServiceProvider"

After running this command, all necessary file will be included in your project. This package has two default migrations. So you have to run migrate command like this. (But make sure your database configuration is configured correctly.)

php artisan migrate

Okay, now you need to configure your user model for Talk. Go to config/talk.php and config it.

return [
    'user' => [
        'model' => 'App\User'
    ],
    'broadcast' => [
        'enable' => false,
        'app_name' => 'your-app-name',
        'pusher' => [
            'app_id'        => '',
            'app_key'       => '',
            'app_secret'    => ''
        ]
    ]
];

Usage

Its very easy to use. First you have to set authenticate user id to Talk as globally.

Talk::setAuthUserId(auth()->user()->id);

Now you may use any method what you need. But if want pass authentic id instantly, this method may help you.

Talk::user(auth()->user()->id)->anyMethodHere();

Please see the API Doc.

API List

setAuthUserId

setAuthUserId method sets the currently loggedin user id, which you pass through parameter. If you pass null or empty value then its return false.

Syntax

void setAuthUserId($userid)

Example

Constructor of a Controller is the best place to write this method.

function __construct()
{
    Talk::setAuthUserId(auth()->user()->id);
}

When you pass logged in user ID, Talk will know who is currently authenticated for this system. So Talk retrieve all information based on this user.

user

You may use this method replacement of setAuthUserId() method. When you have to instantly access users conversations then you may use it. Syntax

object user($id)

Example When you haven't set authenticated user id globally, then you just use this method directly with others method.

$inboxes = Talk::user(auth()->user()->id)->threads();
return view('messages.threads', compact('inboxes'));

isConversationExists

This method checks currently logged in user and if given user is already in conversation

Syntax

int|false isConversationExists($userid)

Example

if ($conversationId = Talk::isConversationExists($userId)) {
    Talk::sendMessage($conversationId, $message);
} 

isAuthenticUser

isAuthenticUser checks if the given user exists in given conversation.

Syntax

boolean isAuthenticUser($conversationId, $userId)

Example

if (Talk::isAuthenticUser($conversationId, $userId)) {
    Talk::sendMessage($conversationId, $message);
} 

sendMessage

You can send messages via conversation id by using this method. If the message is successfully sent, it will return objects of Message model otherwise, it will return false

Syntax

object|false sendMessage($conversationId, $message)

Example

    $message = Talk::sendMessage($conversationId, $message);
    if ($message) {
        return response()->json(['status'=>'success', 'data'=>$message], 200);
   }

sendMessageByUserId

You can send message via receiver id by using this method. If the message is successfully sent, it will return objects of Message model otherwise, it will return false

Syntax

object|false sendMessageByUserId($userId, $message)

getInbox

If you want to get all the inboxes except soft deleted message , this method may help you. This method gets all the inboxes via previously assigned authenticated user id. Its return collections of message thread with latest message.

Syntax

array getInbox([$order = 'desc'[,$offset = 0[, $take = 20]]])

Example

// controller method
$inboxes = Talk::getInbox();
return view('message.threads', compact('inboxes');

<!-- messages/threads.blade.php -->
<ul>
    @foreach($inboxes as $inbox)
        <li>
            <h2>{{$inbox->withUser->name}}</h2>
            <p>{{$inbox->thread->message}}</p>
            <span>{{$inbox->thread->humans_time}}</span>
        </li>
    @endforeach
</ul>

getInboxAll

Its similar as getInbox() method. If you want to get all the inboxes with soft deleted messages, this method may help you. This method gets all the inboxes via given user id.

Syntax

object getInboxAll([$order = 'desc'[,$offset = 0[, $take = 20]]])

threads

This method is an alias of getInbox() method.

Syntax

array threads([$order = 'desc'[,$offset = 0[, $take = 20]]])

threadsAll

This method is an alias of getInboxAll() method.

Syntax

array threadsAll([$order = 'desc'[,$offset = 0[, $take = 20]]])

getConversationsById

When you want to get all the conversations using your desire conversation id, you can try this method. This method returns all the conversations(except soft deleted) with sender and withUser objects

Syntax

array getConversationsById($conversationId[, $offset = 0[, $take = 20]])

Example

// controller method
$conversations = Talk::getConversationsById($conversationId);
$messages = $conversations->messages;
$withUser = $conversations->withUser;

return view('messages.conversations', compact('messages', 'withUser'));

This method returns two objects messages and withUser. messages object contains messages collection and withUser object contains participant User collections.

Let's see how to use it with your views

<!-- messages/conversations.blade.php -->
<div class="message-container">
    <h2>Chat with {{$withUser->name}}</h2>
    @foreach($messages as $msg)
     <div class="message">
        <h4>{{$msg->sender->name}}</h4>
        <span>{{$msg->humans_time}}</span>
        <p>
            {{$msg->message}}
       </p> 
    </div>
    @endforeach
</div>

getConversationsAllById

This method is similar as getConversationsById(). The only difference between this method is its return all messages with soft deleted items.

Syntax

array getConversationsAllById($conversationId[, $offset = 0[, $take = 20]])

getConversationsByUserId

When you want to get all the conversations using your desire receiver id, you can try this method. This method returns all the conversations(except soft deleted message) with user's objects

Syntax

object getConversationsByUserId($receiverId [, $offset = 0[, $take = 20]])

getConversationsAllByUserId

This method is similar as getConversationsByUserId(). The only difference between this method is its return all messages with soft deleted items.

Syntax

array getConversationsAllByUserId($receiverId[, $offset = 0[, $take = 20]])

getMessages

This is a alias of getConversationsById() method.

Syntax

array messages($conversationId[, $offset = 0[, $take = 20]])

getMessagesAll

This is a alias of getConversationsAllById() method.

Syntax

array messagesAll($conversationId[, $offset = 0[, $take = 20]])

getMessagesByUserId

This is a alias of getConversationsByUserId() method.

Syntax

array messagesByUserId($receiverId[, $offset = 0[, $take = 20]])

getMessagesAllByUserId

This is a alias of getConversationsAllByUserId() method.

Syntax

array messagesAllByUserId($receiverId[, $offset = 0[, $take = 20]])

readMessage

If you want to read a single message then you may use it. This message is return a single message object by message id.

Syntax

array readMessage($messageId)

getReceiverInfo

This method returns all the information about message receiver.

> This method is deprecated from version 2.0.0 and it will remove from version 2.0.2

Syntax

object getReceiverInfo($conversationId)

makeSeen

If you want to set a message as seen you can use this method.

Syntax

boolean makeSeen($messageId)

deleteMessage

When you want to delete a specific message from a conversation, you have to use this method. This method soft delete message for both user-end individually.

Syntax

boolean deleteMessage($messageId)

deleteForever

If you want to hard delete or permanently delete a specific message then you have to use this method

Syntax

boolean deleteForever($messageId)

deleteConversations

This method is used to permanently delete all conversations

Syntax

boolean deleteConversations($conversationId)

Realtime Messaging

Talk also support realtime messaging thats called Talk-Live. Talk use pusher for realtime message. So first you have to configure pusher. Go to app/talk.php again and configure.

return [
    'user' => [
        'model' => 'App\User'
    ],
    'broadcast' => [
        'enable' => false,
        'app_name' => 'your-app-name',
        'pusher' => [
            'app_id'        => '',
            'app_key'       => '',
            'app_secret'    => ''
        ]
    ]
];

in this new version broadcast section was added with talk config. Here broadcast is disabled by default. If you want to enable live(realtime) messaging then you have to enable it first. Then add pusher credentials. Thats it. Everytime when you send message then talk will automatically fire two event, one for specific user and second for specific conversation. So you may listen or subscribe one or both as per your wish. Finally you have to subscribe these events by using talk_live() helper function. Go to where you want to subscribe to work with message data follow this code.

<script>
    var msgshow = function(data) {
        // write what you want with this data
        
        console.log(data);
    }
</script>

{!! talk_live(['user'=>["id"=>auth()->user()->id, 'callback'=>['msgshow']]]) !!}

talk_live() is support one parameters as array. The first parameter is for channel name which you want to subscribe. You have not know which channel was broadcast. Talk broadcast two channel by default. One for user and second for conversation. If you want to subscribe channel for currently loggedin user then you have to pass

logedin user id in 'user' key. ['user'=>['id'=>auth()->user()->id, 'callback'=[]] or you want to subscribe for conversation id you have pass conversation id as 'conversation' key. ['conversation'=>['id'=>$conversationID, 'callback'=>[]]. You may pass both if you wants.

You can pass a callback for working with pusher recieved data. For both user and conversation section support callbacks as array. So you can pass multiple callback as array value that was show in previous example.

You can watch Talk-Live-Demo

Try Demo Project

Talk-Example

Special Thanks To

Shipu Ahamed

Thanks :)

Support for this project

Hey dude! Help me out for a couple of :beers:!

Beerpay Beerpay

  Files folder image Files  
File Role Description
Files folder imageconfig (1 file)
Files folder imagedatabase (1 directory)
Files folder imagesrc (2 files, 6 directories)
Files folder imagetests (2 files, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file changelog.txt Doc. Documentation
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  config  
File Role Description
  Accessible without login Plain text file talk.php Aux. Auxiliary script

  Files folder image Files  /  database  
File Role Description
Files folder imagemigrations (2 files)

  Files folder image Files  /  database  /  migrations  
File Role Description
  Plain text file 2015_10_05_110608_..._messages_table.php Class Class source
  Plain text file 2015_10_05_110622_...ersations_table.php Class Class source

  Files folder image Files  /  src  
File Role Description
Files folder imageConversations (2 files)
Files folder imageFacades (1 file)
Files folder imagehelpers (1 file)
Files folder imageLive (2 files)
Files folder imageMessages (2 files)
Files folder imageviews (1 file)
  Plain text file Talk.php Class Class source
  Plain text file TalkServiceProvider.php Class Class source

  Files folder image Files  /  src  /  Conversations  
File Role Description
  Plain text file Conversation.php Class Class source
  Plain text file ConversationRepository.php Class Class source

  Files folder image Files  /  src  /  Facades  
File Role Description
  Plain text file Talk.php Class Class source

  Files folder image Files  /  src  /  helpers  
File Role Description
  Accessible without login Plain text file talk.php Example Example script

  Files folder image Files  /  src  /  Live  
File Role Description
  Plain text file Broadcast.php Class Class source
  Plain text file Webcast.php Class Class source

  Files folder image Files  /  src  /  Messages  
File Role Description
  Plain text file Message.php Class Class source
  Plain text file MessageRepository.php Class Class source

  Files folder image Files  /  src  /  views  
File Role Description
  Accessible without login Plain text file pusherjs.blade.php Aux. Auxiliary script

  Files folder image Files  /  tests  
File Role Description
Files folder imageFacades (1 file)
  Plain text file TalkServiceProviderTest.php Class Class source
  Plain text file TestCase.php Class Class source

  Files folder image Files  /  tests  /  Facades  
File Role Description
  Plain text file Talk.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:225
This week:1
All time:7,704
This week:693Up