moscajs / aedes

Barebone MQTT broker that can run on any stream server, the node way
MIT License
1.78k stars 232 forks source link

Can Aedes send webhooks? #906

Closed andrewroberts closed 11 months ago

andrewroberts commented 11 months ago

I have a Google Apps Script web app that I want to use to receive notifications from Aedes as a HTTP GET or POST request, for then writing into a Google Sheet.

This SO answer suggests the only way to integrate MQTT and Google Sheets with Apps Script is for the broker (Aedes in this case) to generate a webhook.

Is this possible with Aedes?

robertsLando commented 11 months ago

Aedes doesn't do this out of the box but you can bind to aedes events and call webhooks yourself

crapthings commented 11 months ago

Method 1:

You can connect to Aedes through a server-side MQTT client and publish messages to a topic. This way, other MQTT clients, whether they are in a browser or using Node.js, can receive the messages.

Method 2:

You can use HTTP methods like fetch or axios to make requests in Aedes, as described in the documentation here: https://github.com/moscajs/aedes/blob/main/docs/Aedes.md#handler-published-packet-client-callback. Alternatively, you can also use an MQTT client to publish any desired content with 'published callback', similar to Method 1.