adds MS teams integration test

This commit is contained in:
Godfrey M 2024-01-17 13:41:45 -08:00
parent 93ef8317e8
commit 9f2af40ef2
3 changed files with 23 additions and 40 deletions

View file

@ -3,6 +3,7 @@
namespace App\Http\Livewire;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Http;
use Livewire\Component;
use App\Models\Setting;
use App\Helpers\Helper;
@ -48,7 +49,7 @@ class SlackSettingsForm extends Component
"placeholder" => "",
"link" => "",
),
"ms_teams" => array(
"microsoft" => array(
"name" => trans('admin/settings/general.ms_teams'),
"icon" => "fa-brands fa-microsoft",
"placeholder" => "https://abcd.webhook.office.com/webhookb2/XXXXXXX",
@ -83,6 +84,7 @@ class SlackSettingsForm extends Component
$this->webhook_name = $this->webhook_text[$this->webhook_selected]['name'];
$this->webhook_icon = $this->webhook_text[$this->webhook_selected]["icon"]; ;
$this->webhook_placeholder = $this->webhook_text[$this->webhook_selected]["placeholder"];
$this->webhook_endpoint = null;
$this->webhook_link = $this->webhook_text[$this->webhook_selected]["link"];
if($this->webhook_selected != 'slack'){
$this->isDisabled= '';
@ -185,44 +187,24 @@ class SlackSettingsForm extends Component
}
public function msTeamTestWebhook(){
$webhook = new Client([
'base_url' => e($this->webhook_endpoint),
'defaults' => [
'exceptions' => false,
],
'allow_redirects' => false,
]);
$payload = json_encode(
[
"@type"=> "MessageCard",
"@context"=> "http://schema.org/extensions",
"themeColor"=> "0076D7",
"summary"=> trans('mail.Asset_Checkin_Notification'),
"sections"=> [
"activityTitle"=> "Larry Bryant created a new task",
"activitySubtitle"=> "On Project Tango",
"activityImage"=> "https://adaptivecards.io/content/cats/3.png",
"facts"=> [
["name"=> "Assigned to",
"value"=> "Unassigned"
]
,
["name"=> "Due date",
"value"=> "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)"
]
,
["name"=> "Status",
"value"=> "Not started"
]
],
"markdown"=> true
]]
);
$payload =
[
"@type" => "MessageCard",
"@context" => "http://schema.org/extensions",
"summary" => "Announcement Summary",
"title" => "Snipe-IT Integration Test",
'text' => trans('general.webhook_test_msg', ['app' => $this->webhook_name]),
];
try {
$test = $webhook->post($this->webhook_endpoint, ['body' => $payload]);
$response = Http::withHeaders([
'content-type' => 'applications/json',
])->post($this->webhook_endpoint,
$payload)->throw();
if(($test->getStatusCode() == 302)||($test->getStatusCode() == 301)){
if(($response->getStatusCode() == 302)||($response->getStatusCode() == 301)){
return session()->flash('error' , trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint]));
}
$this->isDisabled='';

View file

@ -204,6 +204,7 @@ return [
'integrations' => 'Integrations',
'slack' => 'Slack',
'general_webhook' => 'General Webhook',
'ms_teams' => 'Microsoft Teams',
'webhook' => ':app',
'webhook_presave' => 'Test to Save',
'webhook_title' => 'Update Webhook Settings',

View file

@ -61,9 +61,9 @@
<div class="col-md-9 required" wire:ignore>
@if (Helper::isDemoMode())
{{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'ms_teams' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'style'=>'width:100%', 'disabled')) }}
{{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'microsoft' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'style'=>'width:100%', 'disabled')) }}
@else
{{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'ms_teams' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'data-minimum-results-for-search' => '-1', 'style'=>'width:100%')) }}
{{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'microsoft' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'data-minimum-results-for-search' => '-1', 'style'=>'width:100%')) }}
@endif
</div>
@ -124,8 +124,8 @@
@if($webhook_endpoint != null && $webhook_channel != null)
<div class="form-group">
<div class="col-md-offset-2 col-md-9">
@if($webhook_selected == "ms_teams")
<a href="#" wire:click.prevent="testWebhook"
@if($webhook_selected == "microsoft")
<a href="#" wire:click.prevent="msTeamTestWebhook"
@else
<a href="#" wire:click.prevent="testWebhook"
@endif