Add generic api schema and scripts model
This commit is contained in:
@@ -4,6 +4,9 @@ namespace App\Bots;
|
||||
|
||||
use App\Bots\BotContract;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Mattermost implements BotContract
|
||||
@@ -25,49 +28,48 @@ class Mattermost implements BotContract
|
||||
public function run(): void
|
||||
{
|
||||
try {
|
||||
$request = new \GuzzleHttp\Psr7\Request(
|
||||
$this->client->request(
|
||||
$this->config['method'] ?? 'POST',
|
||||
$this->config['endpoint'],
|
||||
['Content-Type' => 'application/json'],
|
||||
json_encode($this->config['body'] ?? [])
|
||||
[
|
||||
'json' => json_decode($this->config['body'] ?? '', true),
|
||||
]
|
||||
);
|
||||
|
||||
$res = $this->client->send($request);
|
||||
|
||||
// $res = $this->client->put('users/me/status/custom', [
|
||||
// 'json' => [
|
||||
// 'emoji' => 'house',
|
||||
// 'text' => 'Working Home',
|
||||
// 'status' => 'online',
|
||||
// ]
|
||||
// ]);
|
||||
|
||||
if ($res->getStatusCode() === 200) {
|
||||
Log::info("Mattermost home status updated successfully.");
|
||||
} else {
|
||||
Log::error("Failed to update Mattermost status. HTTP Status: " . $res->getStatusCode());
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Error updating Mattermost status: " . $e->getMessage());
|
||||
} catch (GuzzleException $e) {
|
||||
Log::error("Call to Mattermost failed. " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function configSchema(): array
|
||||
{
|
||||
return [
|
||||
'endpoint' => ['type' => 'string', 'label' => 'API Endpoint', 'rules' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
]],
|
||||
'method' => ['type' => 'string', 'label' => 'HTTP Method', 'default' => 'POST', 'rules' => [
|
||||
'required',
|
||||
'in:GET,POST,PUT,DELETE,PATCH',
|
||||
]],
|
||||
'body' => ['type' => 'array', 'label' => 'Request Body (JSON)', 'rules' => [
|
||||
'nullable',
|
||||
'array',
|
||||
]],
|
||||
'endpoint' => [
|
||||
'type' => 'string',
|
||||
'label' => 'API Endpoint',
|
||||
'rules' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
]
|
||||
],
|
||||
'method' => [
|
||||
'type' => 'string',
|
||||
'label' => 'HTTP Method',
|
||||
'default' => 'POST',
|
||||
'rules' => [
|
||||
'required',
|
||||
'in:GET,POST,PUT,DELETE,PATCH',
|
||||
]
|
||||
],
|
||||
'body' => [
|
||||
'type' => 'json',
|
||||
'label' => 'Request Body (JSON)',
|
||||
'rules' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'json',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user