2017 © Pedro Peláez
 

library talk

Talk is a Laravel 5 based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.

image

nahid/talk

Talk is a Laravel 5 based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.

  • Monday, July 2, 2018
  • by nahid
  • Repository
  • 60 Watchers
  • 1004 Stars
  • 16,012 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 209 Forks
  • 44 Open issues
  • 19 Versions
  • 14 % Grown

The README.md

Laravel-Talk

Awesome Laravel GitHub license Build Status MadeWithLaravel.com shield, (*1)

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

Talk v2.1.0 supports realtime messaging. Learn more about Talk Live Messaging, (*3)

Feedback

If you already used Talk, please share your experience with us. It will make the project better., (*4)

Give us your feedback, (*5)

Built with Talk

If you are using Talk in your project please share your project URL or project name with us. It will inspire other people to use Talk., (*6)

See which project was Built with Talk., (*7)

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., (*8)

Talk-Example Screenshot, (*9)

You may try Talk-Example project., (*10)

Or you can try live Demo by using this credentials:, (*11)

username: admin   
password: admin

So let's start your tour :), (*12)

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
  • Inline url render using oembed specifications

Installation

Talk is a Laravel package so you can install it via Composer. Run this command in your terminal from your project directory:, (*13)

composer require nahid/talk

Wait for a while, Composer will automatically install Talk in your project., (*14)

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:, (*15)

Nahid\Talk\TalkServiceProvider::class,

To use facade you have to add this line in app.php in aliases array:, (*16)

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

Now run this command in your terminal to publish this package resources:, (*17)

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.), (*18)

php artisan migrate

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

return [
    'user' => [
        'model' => 'App\User',
        'foreignKey' => null,
        'ownerKey' => null,
    ],

    'broadcast' => [
        'enable' => true,
        'app_name' => 'talk-example',
        'driver' => env('TALK_BROADCAST_DRIVER', 'pusher'), // pusher or laravel-websockets
        'pusher' => [
            'app_id' => env('PUSHER_APP_ID', ''),
            'app_key' => env('PUSHER_APP_KEY', ''),
            'app_secret' => env('PUSHER_APP_SECRET', ''),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER', 'ap2'),
                'encrypted' => env('PUSHER_APP_ENCRYPTION', false),
                'host' => '127.0.0.1',
                'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
                'scheme' => 'http',
                'wsHost' => '127.0.0.1',
                'wsPort' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
                'forceTLS' => false,
                'disableStats' => true
            ]
        ],
    ],


    'oembed' => [
        'enabled' => false,
        'url' => '',
        'key' => ''
    ]
];

Usage

Its very easy to use. If you want to set authenticate user id globally then you have to set a middleware first. Go to app/Http/Kernel.php and set it in $routeMiddleware array:, (*20)

php 'talk' => \Nahid\Talk\Middleware\TalkMiddleware::class,, (*21)

And now you can use it from anywhere with middleware. Suppose you have a Controller and you want to set authenticate user id globally then write this in controller constructor:, (*22)

php $this->middleware('talk');, (*23)

But instead of set id globally you can use these procedure from any method in controller:, (*24)

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:, (*25)

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

Please see the API Doc., (*26)

API List

setAuthUserId

setAuthUserId method sets the currently loggedin user id, which you pass through parameter. If you pass null or empty value then it returns false., (*27)

Syntax, (*28)

void setAuthUserId($userid)

Example, (*29)

Constructor of a Controller is the best place to write this method., (*30)

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., (*31)

user

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

object user($id)

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

$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, (*34)

Syntax, (*35)

int|false isConversationExists($userid)

Example, (*36)

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

isAuthenticUser

isAuthenticUser checks if the given user exists in given conversation., (*37)

Syntax, (*38)

boolean isAuthenticUser($conversationId, $userId)

Example, (*39)

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, (*40)

Syntax, (*41)

object|false sendMessage($conversationId, $message)

Example, (*42)

    $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, (*43)

Syntax, (*44)

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. It returns collections of message thread with latest message., (*45)

Syntax, (*46)

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

Example, (*47)

// 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., (*48)

Syntax, (*49)

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

threads

This method is an alias of getInbox() method., (*50)

Syntax, (*51)

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

threadsAll

This method is an alias of getInboxAll() method., (*52)

Syntax, (*53)

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, (*54)

Syntax, (*55)

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

Example, (*56)

// 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., (*57)

Let's see how to use it with your views, (*58)

<!-- 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., (*59)

Syntax, (*60)

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, (*61)

Syntax, (*62)

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

getConversationsAllByUserId

This method is similar as getConversationsByUserId(). The only difference between this method is it returns all messages with soft deleted items., (*63)

Syntax, (*64)

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

getMessages

This is a alias of getConversationsById() method., (*65)

Syntax, (*66)

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

getMessagesAll

This is a alias of getConversationsAllById() method., (*67)

Syntax, (*68)

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

getMessagesByUserId

This is a alias of getConversationsByUserId() method., (*69)

Syntax, (*70)

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

getMessagesAllByUserId

This is a alias of getConversationsAllByUserId() method., (*71)

Syntax, (*72)

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., (*73)

Syntax, (*74)

array readMessage($messageId)

getReceiverInfo

This method returns all the information about message receiver., (*75)

This method is deprecated from version 2.0.0 and it will be removed from version 2.0.2, (*76)

Syntax, (*77)

object getReceiverInfo($conversationId)

makeSeen

If you want to set a message as seen you can use this method., (*78)

Syntax, (*79)

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., (*80)

Syntax, (*81)

boolean deleteMessage($messageId)

deleteForever

If you want to hard delete or permanently delete a specific message then you have to use this method., (*82)

Syntax, (*83)

boolean deleteForever($messageId)

deleteConversations

This method is used to permanently delete all conversations., (*84)

Syntax, (*85)

boolean deleteConversations($conversationId)

Realtime Messaging

Talk also support realtime messaging thats called Talk-Live. Talk support pusher and laravel-websocket for realtime messaging. So first you have to configure pusher or laravel-websocket. Go to app/talk.php again and configure., (*86)

return [
    'user' => [
        'model' => 'App\User',
        'foreignKey' => null,
        'ownerKey' => null,
    ],

    'broadcast' => [
        'enable' => true,
        'app_name' => 'talk-example',
        'driver' => env('TALK_BROADCAST_DRIVER', 'pusher'), // pusher or laravel-websockets
        'pusher' => [
            'app_id' => env('PUSHER_APP_ID', ''),
            'app_key' => env('PUSHER_APP_KEY', ''),
            'app_secret' => env('PUSHER_APP_SECRET', ''),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER', 'ap2'),
                'encrypted' => env('PUSHER_APP_ENCRYPTION', false),
                'host' => '127.0.0.1',
                'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
                'scheme' => 'http',
                'wsHost' => '127.0.0.1',
                'wsPort' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
                'forceTLS' => false,
                'disableStats' => true
            ]
        ],
    ],


    'oembed' => [
        'enabled' => false,
        'url' => '',
        'key' => ''
    ]
];

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 to your .env file and you must add a new line called PUSHER_APP_NAME in the .env file to specify your application pusher name. 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., (*87)



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

talk_live() supports 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, (*88)

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 want., (*89)

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 shown in previous example., (*90)

You can watch Talk-Live-Demo, (*91)

Oembed support

Talk also supports embed urls simply use $message->toHtlmString() in you views to render an embed link, (*92)

Eg. This is a youtube embed link: https://www.youtube.com/watch?v=jNQXAC9IVRw, (*93)

<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->toHtmlString()}}
       </p> 
    </div>
    @endforeach
</div>

If you want to setup your own implementation of oembed you can configure it in the talk config file. You endpoint should follow the Oembed specifications, (*94)

    'user' => [
        ...
    ],
    ...
    ],
    'oembed' => [
        'enabled' => true,
        'url' => 'http://your.domain/api/oembed',
        'key' => 'yout-auth-api-key'
    ]

Testing

Talk is backwards compatible with php 5.5. Use docker to run unit tests., (*95)

docker-compose run php55 composer install
docker-compose run php55 phpunit
docker-compose run php56 composer install
docker-compose run php56 phpunit
docker-compose run php7 composer install
docker-compose run php7 phpunit
docker-compose run hhvm composer install
docker-compose run hhvm phpunit

Try Demo Project

Talk-Example, (*96)

Special Thanks To

Shipu Ahamed, (*97)

Thanks :), (*98)

Support for this project

Hey dude! Help me out for a couple of :beers:!, (*99)

Beerpay Beerpay, (*100)

The Versions

02/07 2018

dev-master

9999999-dev https://github.com/nahid/talk

Talk is a Laravel 5 based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.

  Sources   Download

CC-BY-3.0 CC(3.0)

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php realtime message chat conversations real-time inbox

02/07 2018

v2.2.2

2.2.2.0 https://github.com/nahid/talk

Talk is a Laravel 5 based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.

  Sources   Download

CC-BY-3.0

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php realtime message chat conversations real-time inbox

18/02 2018

dev-development

dev-development https://github.com/nahid/talk

Talk is a Laravel 5 based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.

  Sources   Download

Creative Commons CC-BY-3.0 CC(3.0)

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php realtime message chat conversations real-time inbox

23/05 2017

v2.2.1

2.2.1.0 https://github.com/nahid/talk

Talk is a Laravel 5 based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.

  Sources   Download

CC(3.0)

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php realtime message chat conversations real-time inbox

22/04 2017

v2.2.0

2.2.0.0 https://github.com/nahid/talk

Talk is a Laravel 5 based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.

  Sources   Download

CC(3.0)

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php realtime message chat conversations real-time inbox

31/01 2017

v2.1.2

2.1.2.0 https://github.com/nahid/talk

Talk is a Laravel 5 based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.

  Sources   Download

CC(3.0)

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php realtime message chat conversations real-time inbox

25/01 2017

v2.1.1

2.1.1.0 https://github.com/nahid/talk

Talk is a Laravel 5 based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.

  Sources   Download

CC(3.0)

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php realtime message chat conversations real-time inbox

08/01 2017

v2.1.0

2.1.0.0 https://github.com/nahid/talk

Talk is a Laravel 5 based users conversations library. It helps to develop users messages and conversations in easy way.

  Sources   Download

CC(3.0)

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

05/12 2016

v2.0.1

2.0.1.0 https://github.com/nahid/talk

Talk is a Laravel 5 based users conversations library. It helps to develop users messages and conversations in easy way.

  Sources   Download

CC(3.0)

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

04/12 2016

v2.0.0

2.0.0.0 https://github.com/nahid/talk

Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=

  Sources   Download

CC(3.0)

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

02/11 2016

1.1.7

1.1.7.0 https://github.com/nahid/talk

Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=

  Sources   Download

Creative Commons

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

22/08 2016

1.1.6

1.1.6.0 https://github.com/nahid/talk

Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=

  Sources   Download

Creative Commons

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

26/07 2016

1.1.5

1.1.5.0 https://github.com/nahid/talk

Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=

  Sources   Download

Creative Commons

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

26/07 2016

1.1.4

1.1.4.0 https://github.com/nahid/talk

Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=

  Sources   Download

Creative Commons

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

20/06 2016

1.1.3

1.1.3.0 https://github.com/nahid/talk

Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=

  Sources   Download

Creative Commons

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

09/06 2016

1.1.2

1.1.2.0 https://github.com/nahid/talk

Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=

  Sources   Download

Creative Commons

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

07/06 2016

1.1.1

1.1.1.0 https://github.com/nahid/talk

Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=

  Sources   Download

Creative Commons

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

06/06 2016

1.1.0

1.1.0.0 https://github.com/nahid/talk

Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=

  Sources   Download

Creative Commons

The Requires

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations inbox

06/10 2015

1.0.1

1.0.1.0 https://github.com/nahid/talk

Talk is a PHP based users conversations library. It helps to develop users messages and conversations in easy way. Talk also support Laravel 5>=

  Sources   Download

Creative Commons

The Requires

  • php >=5.4.0

 

The Development Requires

by Nahid Bin Azhar

laravel php message chat conversations