I want to have a webhook that accepts any JSON payload, extracts some of the attributes from the payload object in a JS preprocessor and hands them over to a workflow that it starts asynchronously. This seems to be harder than I thougth. What's a good way to achieve this?
I tried a lot, but always get Error 500 when sending a payload that does not conform with the defined input parameters, even when inbound passthrough is selected. I can not influence what the sender sends, I have to adapt to it in my JS preprocessor.
What's your suggestions?
You can do this in few different ways. Here are 2 options that I would suggest.
Option 1: Use Foundry Workflow Adapter to invoke the Workflow.
Option 2:
- Create a simple JavaScript or Java Integration service with required payload and preprocessor.
- Raise an Event based on the criteria suitable to your requirements, from Server Events tab of the Operation (as shown below).
- Use this Event to trigger your workflow.
The payload I have to accept from an external service contains unusual html-like tags (<at>, </at> for example) which break the whole integration service approach because every payload must pass the “filter”, and the “filter” doesn’t let those tags pass. They are in string values, so I never thought I would end up at this point but I do.
I can not change the payload I get, I have to adopt to it. How can the “filter” be customized to my needs so that to accepts the unusual tags at least with manual customizing?
I would also like to know how a pre processor should address the keys and values of the structures json object in the payload.
The documentation of the javascript pre/post processor is so poor that I did not yet even get the core concepts.
So let’s work on that.
Payload: {“text”:”<at>Bernd</at> has written a message”,“conversation”:{“id”:”123456;msg=23456”, “name”:”myChat”}}
Preprocessor:
I need a preprocessor that picks the conversation.id, splits it at the “;”, then takes the [0] index as a new key/value “conversationId”:”123456” and the right part, split at the “=“ as the “messageId”:”23456”. these two should become new key/value pairs of the result json payload.
We should also care for the better documentation of the javascript pre/post processors in general. What is request/response/result/param/inputparam/session and which methods are available and how to use them properly.