44
55use GuzzleHttp \Client ;
66use Illuminate \Support \Facades \Http ;
7+ use Illuminate \Support \Str ;
78use Livewire \Component ;
89use App \Models \Setting ;
910use App \Helpers \Helper ;
10-
11+ use Osama \ LaravelTeamsNotification \ TeamsNotification ;
1112class SlackSettingsForm extends Component
1213{
1314 public $ webhook_endpoint ;
@@ -19,6 +20,7 @@ class SlackSettingsForm extends Component
1920 public $ webhook_placeholder ;
2021 public $ webhook_icon ;
2122 public $ webhook_selected ;
23+ public $ teams_webhook_deprecated ;
2224 public array $ webhook_text ;
2325
2426 public Setting $ setting ;
@@ -62,7 +64,7 @@ public function mount() {
6264 "name " => trans ('admin/settings/general.ms_teams ' ),
6365 "icon " => "fa-brands fa-microsoft " ,
6466 "placeholder " => "https://abcd.webhook.office.com/webhookb2/XXXXXXX " ,
65- "link " => "https://learn .microsoft.com/en-us/microsoftteams/platform/ webhooks-and-connectors/how-to/add-incoming-webhook?tabs=dotnet#create-incoming-webhooks-1 " ,
67+ "link " => "https://support .microsoft.com/en-us/office/create-incoming- webhooks-with-workflows-for-microsoft-teams-8ae491c7-0394-4861-ba59-055e33f75498 " ,
6668 "test " => "msTeamTestWebhook "
6769 ),
6870 ];
@@ -79,15 +81,17 @@ public function mount() {
7981 $ this ->webhook_channel = $ this ->setting ->webhook_channel ;
8082 $ this ->webhook_botname = $ this ->setting ->webhook_botname ;
8183 $ this ->webhook_options = $ this ->setting ->webhook_selected ;
82- if ($ this ->webhook_selected == 'microsoft ' || $ this ->webhook_selected == 'google ' ){
84+ $ this ->teams_webhook_deprecated = !Str::contains ($ this ->webhook_endpoint , 'workflows ' );
85+ if ($ this ->webhook_selected === 'microsoft ' || $ this ->webhook_selected === 'google ' ){
8386 $ this ->webhook_channel = '#NA ' ;
8487 }
8588
86-
8789 if ($ this ->setting ->webhook_endpoint != null && $ this ->setting ->webhook_channel != null ){
8890 $ this ->isDisabled = '' ;
8991 }
90-
92+ if ($ this ->webhook_selected === 'microsoft ' && $ this ->teams_webhook_deprecated ) {
93+ session ()->flash ('warning ' , 'The selected Microsoft Teams webhook URL will be deprecated Jan 31st, 2025. Please use a workflow URL. Microsofts Documentation on creating a workflow can be found <a href="https://support.microsoft.com/en-us/office/create-incoming-webhooks-with-workflows-for-microsoft-teams-8ae491c7-0394-4861-ba59-055e33f75498" target="_blank"> here.</a> ' );
94+ }
9195 }
9296 public function updated ($ field ) {
9397
@@ -109,7 +113,6 @@ public function updatedWebhookSelected() {
109113 if ($ this ->webhook_selected == 'microsoft ' || $ this ->webhook_selected == 'google ' ){
110114 $ this ->webhook_channel = '#NA ' ;
111115 }
112-
113116 }
114117
115118 private function isButtonDisabled () {
@@ -126,7 +129,9 @@ private function isButtonDisabled() {
126129 public function render ()
127130 {
128131 $ this ->isButtonDisabled ();
132+
129133 return view ('livewire.slack-settings-form ' );
134+
130135 }
131136
132137 public function testWebhook (){
@@ -236,20 +241,32 @@ public function googleWebhookTest(){
236241 }
237242 public function msTeamTestWebhook (){
238243
239- $ payload =
240- [
241- "@type " => "MessageCard " ,
242- "@context " => "http://schema.org/extensions " ,
243- "summary " => trans ('mail.snipe_webhook_summary ' ),
244- "title " => trans ('mail.snipe_webhook_test ' ),
245- "text " => trans ('general.webhook_test_msg ' , ['app ' => $ this ->webhook_name ]),
246- ];
244+ try {
247245
248- try {
249- $ response = Http::withHeaders ([
250- 'content-type ' => 'applications/json ' ,
251- ])->post ($ this ->webhook_endpoint ,
252- $ payload )->throw ();
246+ if ($ this ->teams_webhook_deprecated ){
247+ //will use the deprecated webhook format
248+ $ payload =
249+ [
250+ "@type " => "MessageCard " ,
251+ "@context " => "http://schema.org/extensions " ,
252+ "summary " => trans ('mail.snipe_webhook_summary ' ),
253+ "title " => trans ('mail.snipe_webhook_test ' ),
254+ "text " => trans ('general.webhook_test_msg ' , ['app ' => $ this ->webhook_name ]),
255+ ];
256+ $ response = Http::withHeaders ([
257+ 'content-type ' => 'applications/json ' ,
258+ ])->post ($ this ->webhook_endpoint ,
259+ $ payload )->throw ();
260+ }
261+ else {
262+ $ notification = new TeamsNotification ($ this ->webhook_endpoint );
263+ $ message = trans ('general.webhook_test_msg ' , ['app ' => $ this ->webhook_name ]);
264+ $ notification ->success ()->sendMessage ($ message );
265+
266+ $ response = Http::withHeaders ([
267+ 'content-type ' => 'applications/json ' ,
268+ ])->post ($ this ->webhook_endpoint );
269+ }
253270
254271 if (($ response ->getStatusCode () == 302 )||($ response ->getStatusCode () == 301 )){
255272 return session ()->flash ('error ' , trans ('admin/settings/message.webhook.error_redirect ' , ['endpoint ' => $ this ->webhook_endpoint ]));
0 commit comments