Making WordPress.org

Changeset 11785


Ignore:
Timestamp:
04/25/2022 07:56:34 PM (2 years ago)
Author:
iandunn
Message:

Props: Enable the Props app.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/slack/props.php

    r11762 r11785  
    22
    33/*
    4  * This endpoint receives payloads from the `/props` slash command in `#props`.
    5  *
    6  * To manage, browse to https://wordpress.slack.com/apps/manage/custom-integrations > Slash Commands > `/props`.
     4 * This endpoint receives requests from the `#props - production` app.
    75 */
    86
     
    1311
    1412namespace Dotorg\Slack\Props {
     13    use Exception;
     14    use function Dotorg\Slack\{ is_valid_request };
     15
     16    require dirname( __DIR__, 2 ) . '/includes/slack/helpers.php';
    1517    require dirname( __DIR__, 2 ) . '/includes/slack/props/lib.php';
    1618
     
    2931
    3032        $hash = md5( strtolower( trim( $email ) ) );
     33
    3134        return sprintf( 'https://secure.gravatar.com/avatar/%s?s=96d=mm&r=G&%s', $hash, time() );
    3235    }
    3336
    3437    if ( constant( __NAMESPACE__ . '\\WEBHOOK_TOKEN' ) === $_POST['token'] ) {
    35         echo run( $_POST );
     38        die( run( $_POST ) );
     39    }
     40
     41    try {
     42        $result              = '';
     43        $request_body_raw    = file_get_contents( 'php://input' );
     44        $request_body_parsed = json_decode( $request_body_raw );
     45        $valid_request       = is_valid_request( APP_ID, APP_SIGNING_SECRET, getallheaders(), $request_body_raw );
     46
     47        if ( $valid_request ) {
     48            // Replying with the challenge verifies this handler to Slack.
     49            $result = $request_body_parsed->challenge ?? handle_props_message( $request_body_parsed );
     50        }
     51
     52        die( $result );
     53
     54    } catch ( Exception $exception ) {
     55        trigger_error( $exception->getMessage(), E_USER_WARNING );
    3656    }
    3757}
Note: See TracChangeset for help on using the changeset viewer.