Skip to content

Instantly share code, notes, and snippets.

@jeremeamia
Created June 8, 2021 17:48
Show Gist options
  • Save jeremeamia/fe7f3bcc951d4b455635eff4c7c54dc5 to your computer and use it in GitHub Desktop.
Save jeremeamia/fe7f3bcc951d4b455635eff4c7c54dc5 to your computer and use it in GitHub Desktop.

Revisions

  1. jeremeamia created this gist Jun 8, 2021.
    24 changes: 24 additions & 0 deletions parse-slack-request.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    <?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);