romanzipp / Laravel-Twitch

Twitch Helix API PHP Wrapper for Laravel
https://packagist.org/packages/romanzipp/laravel-twitch
MIT License
108 stars 18 forks source link

handleWebhook not Called #124

Closed DaWenning closed 2 years ago

DaWenning commented 2 years ago

Laravel Version: 9.2 Laravel-Twitch Version: 4.4

When creating a Webhook subscription the EventSubController is constructed but the handleWebhook Method is not called.

web.php

Route::post('/callback/twitch', [EventSubController::class, 'handleWebhook']);

Route::get('/creating', function()
{
    $twitch = new Twitch;

    $result = $twitch->subscribeEventSub([], [
        'type' => EventSubType::CHANNEL_FOLLOW,
        'version' => '1',
        'condition' => [
            'broadcaster_user_id' => '<id>',
        ],
        'transport' => [
            'method' => 'webhook',
            'callback' => 'https://<URL>/callback/twitch',
        ]
    ]);
    Log::info("Creating!!!");
    var_dump($result->data());

});

In EventSub Controller i made small changes:

class EventSubController extends Controller
{
    public function __construct()
    {
        Log::info("EventSub:__construct()");
        if (config('twitch-api.eventsub.secret')) {
            Log::info("If Case");
            $this->middleware(VerifyEventSubSignature::class);
        }
    }
    [...]
    public function handleWebhook(Request $request): Response
    {
         Log::info("handleWebhook");

==> the handleWebhook is not displayed

and the Log then shows the Following

[2022-06-02 12:20:09] local.INFO: Creating!!!  
[2022-06-02 12:20:11] local.INFO: EventSub:__construct()  
[2022-06-02 12:20:11] local.INFO: If Case
[2022-06-02 12:20:11] local.INFO: Leaving Construct  
[2022-06-02 12:20:21] local.INFO: EventSub:__construct()  
[2022-06-02 12:20:21] local.INFO: If Case
[2022-06-02 12:20:21] local.INFO: Leaving Construct  

and the verification status goes to failed after four tries.

Do i miss something? Did i make mistakes?

DaWenning commented 2 years ago

Okay found my mistake while following the readme again.

Whilst #82 stated, the routes can be in web.php they must be in api.php !

I don't know why, but after putting it in api.php it worked...