github.com/argoproj/argo-events@v1.9.1/docs/sensors/filters/script.md (about) 1 # Script filter 2 3 Script filters can be used to filter the events with [LUA](https://www.lua.org/) scripts. 4 5 Script filters are applied to the event `data`. A CloudEvent from Webhook event-source has payload structure as: 6 7 ```json 8 { 9 "context": { 10 "type": "type_of_event_source", 11 "specversion": "cloud_events_version", 12 "source": "name_of_the_event_source", 13 "id": "unique_event_id", 14 "time": "event_time", 15 "datacontenttype": "type_of_data", 16 "subject": "name_of_the_configuration_within_event_source" 17 }, 18 "data": { 19 "header": {}, 20 "body": {} 21 } 22 } 23 ``` 24 25 ## Fields 26 27 An Script filter can be defined under `filters` with a field `script`: 28 29 ```yaml 30 filters: 31 script: |- 32 if event.body.a == "b" and event.body.d.e == "z" then return true else return false end 33 ``` 34 35 ## Practical example 36 37 1. Create a webhook event-source 38 39 kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/webhook.yaml 40 41 1. Create a webhook sensor with context filter 42 43 kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/filter-script.yaml 44 45 1. Send an HTTP request to the event-source 46 47 kubectl port-forward svc/webhook-eventsource-svc 12000 48 curl -d '{"hello": "world"}' -X POST http://localhost:12000/example 49 50 1. You will notice in sensor logs that the event did not trigger anything. 51 52 1. Send another HTTP request the event-source 53 54 curl -X POST -d '{"a": "b", "d": {"e": "z"}}' http://localhost:12000/example 55 56 1. Then you will see the event successfully triggered a workflow creation.