Page 1 of 1

Webhooks Receiver - any hints on how to build one in Livecode?

Posted: Wed Sep 28, 2022 11:41 pm
by aetaylorBUSBnWt
Hi,

I am working on an App that needs to integrate with a Camera system where the vendor can send me data via a Webhooks Receiver.
They say it is easy and just go search on Google for how to do such.

I thought I might check to see if there is built in support in Livecode or somebody who has done this and willing to share some code about how to build such in Livecode.

Thanks,
Andrew

Re: Webhooks Receiver - any hints on how to build one in Livecode?

Posted: Thu Sep 29, 2022 1:28 am
by FourthWorld
Is this app to be run on a server? AFAIK webhooks require a persistent listener.

Re: Webhooks Receiver - any hints on how to build one in Livecode?

Posted: Thu Sep 29, 2022 2:44 pm
by aetaylorBUSBnWt
I had nor really thought about it, but yes the program would be running constantly on the machine it is on.

The machine would not be technically a server, but it would be constantly on.

Re: Webhooks Receiver - any hints on how to build one in Livecode?

Posted: Thu Sep 29, 2022 6:35 pm
by FourthWorld
aetaylorBUSBnWt wrote:
Thu Sep 29, 2022 2:44 pm
The machine would not be technically a server, but it would be constantly on.
That's the first step. As I understand it the receiver will need to open a port for listening, and have an HTTPS server process running to receive the hook message on that port. So it effectively becomes a server.

To be reachable at the URL provided to the hook service, the server will need a fixed IP (or DynDNS, but that has its own concerns). And since most hooks use SSL it'll need a cert, which will usually need an assigned domain name (can be a subdomain; most of my server services are on subdomains 'cause they're easy and cheap to set up).

And of course if the machine running this app is inside your firewall, this will likely require setting up port forwarding on the local router, so the hook request will be allowed to reach the server.

You can write an httpd server in LC, and the one they provide for testing mobile apps may make a good starting point.

But no need to reinvent that wheel. Apache, Lighttp, NginX and other packages are free, open source, and purpose-built for that. Each of those includes mechanisms for launching custom programs to pass request handling to; Apache and Lighttpd support CGI, and NginX provides socket comms to persistent processes. There may even be webhook add-on packages for those servers to simplify some aspects of implementation.

If all that setup is impractical in the local client, you could consider having the hook handling on an external server, with the local app polling your server periodically for new data. That obviates the push benefit of hooks, of course, but at least it keeps the local app simple to install and maintain.