Last active
January 20, 2021 19:05
-
-
Save ActuallyConnor/75ca4aba325ee6c599797cb620532db0 to your computer and use it in GitHub Desktop.
Slack Events API challenge handler - Laravel Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
class BurritoController extends Controller { | |
public function slackChallenge( Request $request ) { | |
if ( !empty( $request->json() ) ) { | |
$json = $request->json(); | |
if ($json->has('challenge')) { | |
$challenge = $json->get('challenge'); | |
} elseif ($json->has('body')) { | |
$challenge = $json->get( 'body' )['challenge']; | |
} else { | |
$challenge = ''; | |
} | |
return response() | |
->json( [ | |
'challenge' => $challenge | |
] ) | |
->header( 'Access-Control-Allow-Origin', '*' ); | |
} | |
return response( 'No payload in request' ) | |
->header( 'Content-Type', 'text/plain' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment