39 lines
951 B
PHP
39 lines
951 B
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use App\Models\Quote;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class Slack
|
|
{
|
|
private string $url;
|
|
|
|
public function __construct() {
|
|
$this->url = config('bot.webhook');
|
|
}
|
|
|
|
private function send($text): \GuzzleHttp\Promise\PromiseInterface|\Illuminate\Http\Client\Response
|
|
{
|
|
return Http::post($this->url, ['text' => $text]);
|
|
}
|
|
|
|
public function sendText(string $text): \GuzzleHttp\Promise\PromiseInterface|\Illuminate\Http\Client\Response
|
|
{
|
|
activity()
|
|
->event('send')
|
|
->log("Manually sent quote: $text");
|
|
|
|
return $this->send($text);
|
|
}
|
|
|
|
public function sendQuote(Quote $quote): \GuzzleHttp\Promise\PromiseInterface|\Illuminate\Http\Client\Response
|
|
{
|
|
activity()
|
|
->performedOn($quote)
|
|
->event('send')
|
|
->log("Requested quote: $quote");
|
|
|
|
return $this->send($quote->quote);
|
|
}
|
|
} |