Skip to content

Instantly share code, notes, and snippets.

@jeremeamia
Created June 8, 2021 17:48
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 jeremeamia/fe7f3bcc951d4b455635eff4c7c54dc5 to your computer and use it in GitHub Desktop.
Save jeremeamia/fe7f3bcc951d4b455635eff4c7c54dc5 to your computer and use it in GitHub Desktop.
Quick and dirty Slack request parsing in PHP
<?php
function parse_slack_request(string $body): array
{
if (empty($body)) {
return [];
}
if ($body[0] === '{') {
$data = json_decode($body, true);
} else {
parse_str($body, $data);
}
if (isset($data['payload'])) {
$data = json_decode(urldecode($data['payload']), true);
}
return $data;
}
// Example
$body = file_get_contents('php://input');
$data = parse_slack_request($body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment