XF 2.0 Building Add-on with a file in the XF Root?

Don't have time right now to give details - if nobody else has made any suggestions by the time I'm back in the office, I'll try and write some details about how to make a custom route.

(Also, my dev server just died, so I have to spin up a new one before I can do any XF2 stuff :( )
 
Thanks for the information. I'm going to review the routes section tonight and see what I can figure out.
 
It is a valid approach if you want this file to not load all the XenForo library. However, if that's not the case here you can use the routing system to route a root path to your addon directory and the external server won't see the difference.


Maybe I don't understand why this file needs to be in the root path. Is there a public documentation of this webhook to take a look at it?
 
It is a valid approach if you want this file to not load all the XenForo library. However, if that's not the case here you can use the routing system to route a root path to your addon directory and the external server won't see the difference.


Maybe I don't understand why this file needs to be in the root path. Is there a public documentation of this webhook to take a look at it?

I just need to ingest the webhook via the following:

PHP:
//Get Webhook Request
$request = $app->request();
$userAgent = $request->getUserAgent();
$inputRaw = $request->getInputRaw();

With that said, that file needs to be an accessible endpoint for the service to call it.

This is just one: https://developers.sparkpost.com/api/webhooks/

I will also be ingesting from AWS SNS.
 
Adding this code to my controller (thanks to THIS) seems to be getting me on track.

PHP:
public function checkCsrfIfNeeded($action, \XF\Mvc\ParameterBag $params)
    {
        return;
    }
 
It seems I still can't "POST" to my new route.

I've built this:

routeSetup.webp

My Class:

PHP:
<?php

namespace BoostN\EmailSync\Pub\Controller;

use XF\Mvc\ParameterBag;
use XF\Pub\Controller\AbstractController;

class Response extends AbstractController{

    public function actionIndex(ParameterBag $params){

        //Get Webhook Request
        $request = $this->request();
        $userAgent = $request->getUserAgent();
        $inputRaw = $request->getInputRaw();

        file_put_contents("C:\\temp\userAgent.txt", $userAgent);
        
    }
}

My structure:
directoryStructure.webp

I can confirm using NGROK that I'm posting to that webhook:
http://localdomain.com/index.php?emailsync

Doing a "GET" request with a \XF::dump($this->request); gives me output via the browser navigating to that page. I'm assuming no authentication is the issue here?
 
Webhooks are best to reside in the root directory in my opinion. There's a reason we have a payment_callback.php, a sitemap.php and many others in the root directory, and it's a fairly simple one: By only starting the app and not actually running it, we save ourselves the entire bloat of routing, controller weight, and view rendering.

Anyway, if you want to place a file in the root directory, but want to make sure it gets bundled up, place a build.json file in your add-ons directory with the following content:
JavaScript:
{
    "additional_files": [
        "name-of-your-file.php"
    ]
}
Simple as that.
 
Webhooks are best to reside in the root directory in my opinion. There's a reason we have a payment_callback.php, a sitemap.php and many others in the root directory, and it's a fairly simple one: By only starting the app and not actually running it, we save ourselves the entire bloat of routing, controller weight, and view rendering.

Anyway, if you want to place a file in the root directory, but want to make sure it gets bundled up, place a build.json file in your add-ons directory with the following content:
JavaScript:
{
    "additional_files": [
        "name-of-your-file.php"
    ]
}
Simple as that.

That was my thoughts, but I wanted to be sure hence my thread.

I have got it working by creating a route and controller like you've mentioned. So, it was a learning opportunity for me.

Thanks for your input.
 
Back
Top Bottom