TACTIC Open Source
Webhooks listener for TACTIC - Printable Version

+- TACTIC Open Source (http://forum.southpawtech.com)
+-- Forum: TACTIC Open Source (http://forum.southpawtech.com/forumdisplay.php?fid=3)
+--- Forum: TACTIC Discussion (http://forum.southpawtech.com/forumdisplay.php?fid=4)
+--- Thread: Webhooks listener for TACTIC (/showthread.php?tid=276)



Webhooks listener for TACTIC - dankitchen - 01-02-2024

Happy New Year All!

I am in the process of extending my internal TACTIC system to handle CRM data.  Part of this is using external services like GMass for email campaigns.   Gmass has the ability to send webhooks on events in their system. Instead of taking the API route, I am thinking it will be interesting to use webhooks as this seems to be the way many apps communicate including things like Zapier.

So far, I have done some basic tests using the Python Webhooks Listener library (Webhook-Listener · PyPI).  I think this is a good route as it uses CherryPy.  I am using it's default use of port 8090 as I know tactic the standard web ports. So I mainly just needed to open port 8090 in the firewall.

Here is the webhooks_listener.py file I have on my server.  I left the initial test print as it shows what is available in the event

Code:
import time
import webhook_listener


def process_post_request(request, *args, **kwargs):
    """
    print(
        "Received request:\n"
        + "Method: {}\n".format(request.method)
        + "Headers: {}\n".format(request.headers)
        + "Args (url path): {}\n".format(args)
        + "Keyword Args (url parameters): {}\n".format(kwargs)
        + "Body: {}".format(
            request.body.read(int(request.headers["Content-Length"]))
            if int(request.headers.get("Content-Length", 0)) > 0
            else ""
        )
    )
    """


    # Process the request!
    print(kwargs)

    return


webhooks = webhook_listener.Listener(handlers={"POST": process_post_request})
webhooks.start()

while True:
    print("Still alive...")
    time.sleep(300)

Now all of that said, I have a few questions:


  1. Is there something already in place that makes this not necessary?  I ask because I see some code for sending Webhooks from TACTIC
  2. If I was to use this code, what the best approach to adding it as a service that starts up when Tactic starts?
I am still tinkering with this so I will update this post as I figure out more