Welcome Guest, Not a member yet? Register   Sign In
Process After Webhook Response
#4

(This post was last modified: 08-08-2023, 09:02 AM by 68thorby68.)

After considerable web searching using Stack Overflow in conjunction with the CI manual, I was able to to establish I need to apply a filter NOT event.

First I set up my filter. NOTE: as I only want the filter to apply AFTER the controller has run, i.e. after the controller has responded to the 3rd party webhook in a timely manner, I only need to define the after function.

PHP Code:
<?php namespace App\Libraries\Filters;

use 
CodeIgniter\Filters\FilterInterface;
use 
CodeIgniter\HTTP\IncomingRequest;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;

class 
Webhook_test implements FilterInterface
{
    public function before(RequestInterface $request$arguments null)
    
         //leave this blank
    }
    
    
public function after(RequestInterface $requestResponseInterface $response$arguments null)
    {
         log_message('notice''[SUCCESS] {file}-{line}, This is called from the controller AFTER has run. THIS WILL BE REPLACED WITH A RETURN ROUTE TO  TO PROCESS THE WEBHOOK DATA');
    }

Then I configured my filter in the Config/Filters, first declaring "use App\Libraries\Filters\Webhook_test;" and then creating an alias "Webhook_test" for the class .
PHP Code:
public $aliases = [
        'csrf'          => CSRF::class,
        'toolbar'      => DebugToolbar::class,
        'honeypot'      => Honeypot::class,
        'invalidchars'  => InvalidChars::class,
        'secureheaders' => SecureHeaders::class,
        'webhooktest' => Webhook_test::class,
    ]; 

Then, as I only want the filter to apply to a single controller and I don't want to list (and keep updating) all excluded controllers.  I applied my alias to a url filter, NOT global. ,
Note: my before and after url pattern is an exact match to the controller I want this filter to be applied to (not sure if this is a proper usage, but it works!!) as I do not want it to be applied anywhere else.
PHP Code:
public $filters = [
         'webhooktest' => ['before'=>['mywebhookcontroller'], 'after' => ['mywebhookcontroller']],
 ]; 

Many thanks, I believe I have found a solution without the resource overhead of CRONs and database queries
Reply


Messages In This Thread
Process After Webhook Response - by 68thorby68 - 07-18-2023, 08:27 AM
RE: Process After Webhook Response - by badger - 07-18-2023, 10:19 AM
RE: Process After Webhook Response - by 68thorby68 - 08-08-2023, 09:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB