2024-06-09 23:18:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
use App\Events\Matrix\Factory as MatrixEventFactory;
|
2024-06-11 04:17:03 +00:00
|
|
|
use App\Events\Matrix\Message;
|
2024-06-09 23:18:59 +00:00
|
|
|
|
|
|
|
final class MatrixController extends Controller
|
|
|
|
{
|
|
|
|
private const LOGKEY = 'CMC';
|
|
|
|
|
2024-06-11 04:17:03 +00:00
|
|
|
public function webhook(Request $request): mixed
|
2024-06-09 23:18:59 +00:00
|
|
|
{
|
|
|
|
$event = MatrixEventFactory::make(Arr::get($request->events,0,[]));
|
2024-06-11 04:17:03 +00:00
|
|
|
|
|
|
|
// Catch our messages that we've posted
|
|
|
|
if (($event instanceof Message) && preg_match('#^.*\^[0-9]+_[0-9]+/[0-9]+(\.[0-9]+)?:#',$event->sender)) {
|
|
|
|
Log::info(sprintf('%s:- Ignoring Matrix Message event, probably from us [%s]',static::LOGKEY,$event->sender));
|
|
|
|
return response(['result'=>'OK']);
|
|
|
|
}
|
|
|
|
|
2024-06-09 23:18:59 +00:00
|
|
|
Log::info(sprintf('%s:- Dispatching Matrix Event [%s]',static::LOGKEY,get_class($event)));
|
|
|
|
event($event);
|
|
|
|
|
|
|
|
return response(['result'=>'OK']);
|
|
|
|
}
|
|
|
|
}
|