Skip to main content

Ping a Slack channel when a cancelled subscriber’s app polls a revoked token

Premium Beginner Since v1.0.0

FeedController::dispatch() fires benecaster_feed_request_dispatched after every feed poll with the full request context — including token_status (one of valid, over_limit, revoked, not_found). Hook it to react to the interesting statuses without querying the log table. This recipe filters for revoked polls (cancelled subscribers whose podcast apps still try to fetch their old feed) and sends a Slack webhook — a lightweight winback signal that fires in real time, before the nightly rollup consolidates the data.

The event fires whether or not the feed request log is enabled — the log-enabled option only gates the built-in FeedRequestLogger listener, not the action itself. Filter for token_status === 'not_found' instead to detect potential token-sharing or app-glitch patterns.

Code

<?php
add_action( 'benecaster_feed_request_dispatched', function ( array $ctx ): void {
    if ( 'revoked' !== $ctx['token_status'] ) {
        return; // only interested in cancelled subscribers still polling
    }

    $webhook = getenv( 'SLACK_WINBACK_WEBHOOK' );
    if ( ! $webhook ) return;

    wp_remote_post( $webhook, [
        'blocking' => false,
        'body'     => wp_json_encode( [
            'text' => sprintf(
                'Revoked-token poll on show #%d — token %s from %s (%s)',
                $ctx['show_id'],
                $ctx['token_prefix'] ?? 'unknown',
                $ctx['country_code'] ?? '??',
                $ctx['user_agent'] ?? 'unknown UA'
            ),
        ] ),
        'headers'  => [ 'Content-Type' => 'application/json' ],
    ] );
} );

View on GitHub →

Hooks Used