mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
working on Chat integration test
This commit is contained in:
parent
1d3124f89f
commit
6e9a46e582
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Http\Livewire;
|
namespace App\Http\Livewire;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -42,21 +43,21 @@ class SlackSettingsForm extends Component
|
||||||
"icon" => 'fab fa-slack',
|
"icon" => 'fab fa-slack',
|
||||||
"placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX",
|
"placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX",
|
||||||
"link" => 'https://api.slack.com/messaging/webhooks',
|
"link" => 'https://api.slack.com/messaging/webhooks',
|
||||||
"test" => 'testWebhook'
|
"test" => "testWebhook"
|
||||||
),
|
),
|
||||||
"general" => array(
|
"general" => array(
|
||||||
"name" => trans('admin/settings/general.general_webhook'),
|
"name" => trans('admin/settings/general.general_webhook'),
|
||||||
"icon" => "fab fa-hashtag",
|
"icon" => "fab fa-hashtag",
|
||||||
"placeholder" => "",
|
"placeholder" => "",
|
||||||
"link" => "",
|
"link" => "",
|
||||||
"test" => 'testWebhook'
|
"test" => "testWebhook"
|
||||||
),
|
),
|
||||||
"google" => array(
|
"google" => array(
|
||||||
"name" => trans('admin/settings/general.google_workspaces'),
|
"name" => trans('admin/settings/general.google_workspaces'),
|
||||||
"icon" => "fa-brands fa-google",
|
"icon" => "fa-brands fa-google",
|
||||||
"placeholder" => "https://chat.googleapis.com/v1/spaces/xxxxxxxx/messages?key=xxxxxx",
|
"placeholder" => "https://chat.googleapis.com/v1/spaces/xxxxxxxx/messages?key=xxxxxx",
|
||||||
"link" => "https://developers.google.com/chat/how-tos/webhooks#register_the_incoming_webhook",
|
"link" => "https://developers.google.com/chat/how-tos/webhooks#register_the_incoming_webhook",
|
||||||
"test" => 'googleWebhookTest'
|
"test" => "googleWebhookTest"
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -70,6 +71,7 @@ class SlackSettingsForm extends Component
|
||||||
$this->webhook_channel = $this->setting->webhook_channel;
|
$this->webhook_channel = $this->setting->webhook_channel;
|
||||||
$this->webhook_botname = $this->setting->webhook_botname;
|
$this->webhook_botname = $this->setting->webhook_botname;
|
||||||
$this->webhook_options = $this->setting->webhook_selected;
|
$this->webhook_options = $this->setting->webhook_selected;
|
||||||
|
$this->webhook_test = $this->webhook_text[$this->setting->webhook_selected]["test"];
|
||||||
|
|
||||||
|
|
||||||
if($this->setting->webhook_endpoint != null && $this->setting->webhook_channel != null){
|
if($this->setting->webhook_endpoint != null && $this->setting->webhook_channel != null){
|
||||||
|
@ -151,7 +153,29 @@ class SlackSettingsForm extends Component
|
||||||
|
|
||||||
}
|
}
|
||||||
public function googleWebhookTest(){
|
public function googleWebhookTest(){
|
||||||
|
$url = $this->webhook_endpoint;
|
||||||
|
$data = [ 'text' => trans('general.webhook_test_msg', ['app' => $this->webhook_name])];
|
||||||
|
$headers = [
|
||||||
|
'Authorization' => 'Bearer'. 'AIzaSyBu-61gEOhYGfrmT3fHQj6vS8TDWpo1B5U',
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
];
|
||||||
|
$client = new Client();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $client->post($url,[
|
||||||
|
'headers' => $headers,
|
||||||
|
'json' => $data,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (($response->getStatusCode() == 302) || ($response->getStatusCode() == 301)) {
|
||||||
|
return session()->flash('error', trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint]));
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
|
$this->isDisabled='disabled';
|
||||||
|
$this->save_button = trans('admin/settings/general.webhook_presave');
|
||||||
|
return session()->flash('error' , trans('admin/settings/message.webhook.error', ['error_message' => $e->getMessage(), 'app' => $this->webhook_name]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clearSettings(){
|
public function clearSettings(){
|
||||||
|
|
|
@ -126,7 +126,7 @@
|
||||||
@if($webhook_endpoint != null && $webhook_channel != null)
|
@if($webhook_endpoint != null && $webhook_channel != null)
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-md-offset-2 col-md-9">
|
<div class="col-md-offset-2 col-md-9">
|
||||||
<a href="#" wire:click.prevent="testWebhook"
|
<a href="#" wire:click.prevent="{{$webhook_test}}"
|
||||||
class="btn btn-default btn-sm pull-left">
|
class="btn btn-default btn-sm pull-left">
|
||||||
<i class="{{$webhook_icon}}" aria-hidden="true"></i>
|
<i class="{{$webhook_icon}}" aria-hidden="true"></i>
|
||||||
{!! trans('admin/settings/general.webhook_test',['app' => ucwords($webhook_selected) ]) !!}
|
{!! trans('admin/settings/general.webhook_test',['app' => ucwords($webhook_selected) ]) !!}
|
||||||
|
|
Loading…
Reference in a new issue