Skip to content

Instantly share code, notes, and snippets.

@ammezie
Created July 31, 2019 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ammezie/b9104d83a87b33d49aea97574ee7dae7 to your computer and use it in GitHub Desktop.
Save ammezie/b9104d83a87b33d49aea97574ee7dae7 to your computer and use it in GitHub Desktop.
// controllers/MessagesController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use GetStream\StreamChat\Client;
use App\Message;
class MessagesController extends Controller
{
protected $client;
public function __construct(){
$this->client = new Client(
getenv("MIX_STREAM_API_KEY"),
getenv("MIX_STREAM_API_SECRET"),
);
}
public function generateToken(Request $request){
return response()->json([
'token' => $this->client->createToken($request->input('name'))
], 200);
}
public function getChannel(Request $request){
$from = $request->input('from');
$to = $request->input('to');
$from_username = $request->input('from_username');
$to_username = $request->input('to_username');
$channel_name = "livechat-{$from_username}-{$to_username}";
$channel = $this->client->getChannel("messaging", $channel_name);
$channel->create($from_username, [$to_username]);
return response()->json([
'channel' => $channel_name
], 200);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment