-
-
Save BrightnBubbly/ae8c6d7e4aae94490531075b743b010a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use GetStream\StreamChat\Client; | |
use Illuminate\Http\Request; | |
class ChatMessagesController 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){ | |
try{ | |
return response()->json([ | |
'token' => $this->client->createToken($request->name) | |
], 200); | |
}catch(\Exception $e){ | |
return response()->json([ | |
'errorMessage' => $e->getMessage() | |
],500); | |
} | |
} | |
public function getChannel(Request $request){ | |
try{ | |
$from = $request->from; | |
$to = $request->to; | |
$from_username = $request->from_username; | |
$to_username = $request->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); | |
}catch(\Exception $e){ | |
return response()->json([ | |
'errorMessage' => $e->getMessage() | |
],500); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment