webhookrelay / node-red-contrib-webhookrelay

8 stars 2 forks source link

Handling multiple triggering sources with different JSON data #3

Closed hepcat72 closed 5 years ago

hepcat72 commented 5 years ago

First, thanks for webhookrelay. I really like it. I'm using it for personal/home automation.

I have a question and a possible feature request.

First, if I include a webhookrelay node connected to the same public endpoint in 2 different node-red flows, are 2 separate websockets maintained or is one socket per endpoint maintained? I'm just curious if there's more overhead in terms of sockets if I put a webhookrelay node using the same endpoint in different flows.

I set up my first flow which I call automatically from an app on my phone based on location. It has an immutable JSON structure. I can change a value or 2, but not the variable names. I'm planning on creating another flow that gets its webhook POSTs from a different source. If I set up a second flow which uses the same webhookrelay endpoint but is called from a different source (e.g. IFTTT) and has a different JSON file structure, is it possible to inject a variable into the JSON based on where the webhook is coming from?

rusenask commented 5 years ago

Hi, glad to hear it's useful for you!

Regarding nodes and separate connections - yes, each node will create a websocket but it's okay, they are very lightweight and even having several open will never approach the amount of data passed when you open a typical web page :)

In my workflows I have several webhookrelay nodes always active. I also use "switch" node to separate incoming webhooks based on their webhookrelay bucket names:

image

Then, based on topic/bucket name you divert flow into a nodes that decode different JSON structures.

You can also detect which input received it by inspecting payload.meta.input_name field:

image

Does this sound helpful to you? I imagine that for a second flow you can either inspect the bucket or input names, that should be enough :) Also, you can also check request headers, usually they are different when dispatched by multiple separate applications.

hepcat72 commented 5 years ago

Well, I'm embarrassed to say I'm trying to get by with the 1 free bucket/input, so I guess if there's no way to tell where a POST came from (coming into webhookrelay and relayed to my nodered instance), I'll have to handle using different/missing JSON variables.

rusenask commented 5 years ago

No worries, I will bump up your limits later today when I have a chance :)

On 26 Apr 2019, at 20:12, Robert Leach notifications@github.com wrote:

Closed #3.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.