[webhook] New, very simple binding for listening incomming http requests

Is the “itemname” an information you need in the Webhook JEXL script in OH, or can it just be ignored? I am not sure if there is a way to process parts of the URL in the JEXL script.

I am afraid that is something I have not tried, maybe someone else can help.

I have written a JEXL script that basically puts everything provided by the Webhook binding into a JSON and then passes it on to a JavaScript rule for processing. I also include req.body.json, but I never tested if it actually works.

UID: webhook:Webhook:d1097152a4
label: Webhook
thingTypeUID: webhook:Webhook
configuration:
  expression: resp.status=200
channels:
  - id: lastCall
    channelTypeUID: webhook:lastCall-channel
    label: Last request
    description: Timestamp of the last request to the webhook.
    configuration: {}
  - id: trigger
    channelTypeUID: webhook:trigger-channel
    label: Trigger
    description: Trigger that fires for each incoming request.
    configuration:
      expression: >-
        {
          // This expression takes all data from the request and puts it into a JSON string
          var gson = new( "com.google.gson.Gson" );
          var jsonRoot = {:}; var jsonBody = {:};
          // If text/json are not present put returns an error, so we need to check first
          if( ! empty( req.body.text ) ) jsonBody.put( "text", req.body.text );
          if( ! empty( req.body.json ) ) jsonBody.put( "json", req.body.json );
          jsonRoot.put( "parameters", req.parameters );
          jsonRoot.put( "body", jsonBody );
          jsonRoot.put( "method", req.method );
          return gson.toJson( jsonRoot );
        }

The JavaScript that is triggered by the event channel then simply opens with the following line and continues to process the data:

var request = JSON.parse( event.event );