diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.php index 317224389..942c4a5fe 100644 --- a/app/Http/Controllers/Api/SettingsController.php +++ b/app/Http/Controllers/Api/SettingsController.php @@ -8,6 +8,8 @@ use App\Models\Ldap; use Validator; use App\Models\Setting; use Mail; +use App\Notifications\SlackTest; +use Notification; class SettingsController extends Controller { @@ -96,6 +98,29 @@ class SettingsController extends Controller } + + public function slacktest() + { + + if ($settings = Setting::getSettings()->slack_channel=='') { + \Log::debug('Slack is not enabled. Cannot test.'); + return response()->json(['message' => 'Slack is not enabled, cannot test.'], 400); + } + + \Log::debug('Preparing to test slack connection'); + + try { + Notification::send($settings = Setting::getSettings(), new SlackTest()); + return response()->json(['message' => 'Success'], 200); + } catch (\Exception $e) { + \Log::debug('Slack connection failed'); + return response()->json(['message' => $e->getMessage()], 400); + } + + + } + + /** * Test the email configuration * diff --git a/app/Notifications/SlackTest.php b/app/Notifications/SlackTest.php new file mode 100644 index 000000000..213b21315 --- /dev/null +++ b/app/Notifications/SlackTest.php @@ -0,0 +1,77 @@ +from($settings->slack_botname, ':heart:') + ->to($settings->slack_channel) + ->image('https://snipeitapp.com/favicon.ico') + ->content('Oh hai! Looks like your Slack integration with Snipe-IT is working!'); + } + + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index c717910dd..d544657df 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -105,7 +105,8 @@ return array( 'slack_channel' => 'Slack Channel', 'slack_endpoint' => 'Slack Endpoint', 'slack_integration' => 'Slack Settings', - 'slack_integration_help' => 'Slack integration is optional, however the endpoint and channel are required if you wish to use it. To configure Slack integration, you must first create an incoming webhook on your Slack account.', + 'slack_integration_help' => 'Slack integration is optional, however the endpoint and channel are required if you wish to use it. To configure Slack integration, you must first create an incoming webhook on your Slack account. Once you have saved your Slack information, a test button will appear.', + 'slack_test_help' => 'Test whether your Slack integration is configured correctly. YOU MUST SAVE YOUR UPDATED SLACK SETTINGS FIRST.', 'snipe_version' => 'Snipe-IT version', 'support_footer' => 'Support Footer Links ', 'support_footer_help' => 'Specify who sees the links to the Snipe-IT Support info and Users Manual', diff --git a/resources/views/settings/slack.blade.php b/resources/views/settings/slack.blade.php index 7aded72be..3647934aa 100644 --- a/resources/views/settings/slack.blade.php +++ b/resources/views/settings/slack.blade.php @@ -38,9 +38,14 @@
+ {!! trans('admin/settings/general.slack_integration_help',array('slack_link' => 'https://my.slack.com/services/new/incoming-webhook')) !!} +
+ + + +{!! trans('admin/settings/general.slack_integration_help',array('slack_link' => 'https://my.slack.com/services/new/incoming-webhook')) !!}
{{ trans('admin/settings/general.slack_test_help') }}
+