Skip to content

Instantly share code, notes, and snippets.

@ActuallyConnor
Last active January 20, 2021 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ActuallyConnor/75ca4aba325ee6c599797cb620532db0 to your computer and use it in GitHub Desktop.
Save ActuallyConnor/75ca4aba325ee6c599797cb620532db0 to your computer and use it in GitHub Desktop.
Slack Events API challenge handler - Laravel Controller
<?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