63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Enums\LogAction;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Log;
|
|
use App\Models\Quote;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class WebHookController extends Controller
|
|
{
|
|
public function webHookSend(string $payload)
|
|
{
|
|
// TODO: move this to a helper class so we can reuse code between API and FE
|
|
$data = ['text' => $payload];
|
|
$response = Http::post(config('bot.webhook'), $data);
|
|
}
|
|
|
|
public function sendQuote(Request $request)
|
|
{
|
|
$quote = $request->input('quote');
|
|
|
|
if (empty($quote)) {
|
|
return;
|
|
}
|
|
|
|
Log::create([
|
|
'user_id' => auth()?->user()?->id ?? 1,
|
|
'loggable_type' => Quote::class,
|
|
'loggable_id' => null,
|
|
'action' => LogAction::SEND,
|
|
'content' => $quote,
|
|
'ip' => request()->ip(),
|
|
]);
|
|
|
|
$this->webHookSend($quote);
|
|
}
|
|
|
|
public function sendRandomQuote()
|
|
{
|
|
$quote = Quote::inRandomOrder()->first();
|
|
|
|
Log::create([
|
|
'user_id' => auth()?->user()?->id ?? 1,
|
|
'loggable_type' => Quote::class,
|
|
'loggable_id' => $quote->id,
|
|
'action' => LogAction::REQUEST,
|
|
'content' => 'Random quote requested',
|
|
'ip' => request()->ip(),
|
|
]);
|
|
|
|
$this->webHookSend($quote->quote);
|
|
}
|
|
|
|
public function test()
|
|
{
|
|
var_dump('secrets');
|
|
}
|
|
|
|
}
|