github.com/argoproj/argo-events@v1.9.1/docs/sensors/transform.md (about) 1 # Event Transformation 2 3 > Available after v1.6.0 4 5 1. Lua Script: Executes user-defined Lua script to transform the event. 6 7 2. JQ Command: Evaluates JQ command to transform the event. We use <https://github.com/itchyny/gojq> to evaluate JQ commands. 8 9 ### Note 10 11 * If set, transformations are applied to the event before the filters are applied. 12 13 * Either a Lua script or a JQ command can be used for the transformation, not both. 14 15 * Only event data is available for the transformation and not the context. 16 17 * The event is discarded if the transformation fails. 18 19 ## Lua Script 20 21 ```yaml 22 apiVersion: argoproj.io/v1alpha1 23 kind: Sensor 24 metadata: 25 name: webhook 26 spec: 27 template: 28 serviceAccountName: operate-workflow-sa 29 dependencies: 30 - name: test-dep 31 eventSourceName: webhook 32 eventName: example 33 transform: 34 script: |- 35 event.body.message='updated' 36 return event 37 triggers: 38 - template: 39 name: webhook-workflow-trigger 40 conditions: "test-dep" 41 k8s: 42 operation: create 43 source: 44 resource: 45 apiVersion: argoproj.io/v1alpha1 46 kind: Workflow 47 metadata: 48 generateName: webhook- 49 spec: 50 entrypoint: whalesay 51 arguments: 52 parameters: 53 - name: message 54 # the value will get overridden by event payload from test-dep 55 value: hello world 56 templates: 57 - name: whalesay 58 inputs: 59 parameters: 60 - name: message 61 container: 62 image: docker/whalesay:latest 63 command: [cowsay] 64 args: ["{{inputs.parameters.message}}"] 65 parameters: 66 - src: 67 dependencyName: test-dep 68 dataKey: body 69 dest: spec.arguments.parameters.0.value 70 ``` 71 72 1. `transform.script` field defines the Lua script that gets executed when an event is received. 73 74 2. The event data is available to Lua execution context via a global variable called `event`. 75 76 3. The above script sets the value of `body.message` field within the event data to a new value called `updated` and returns the event. 77 78 4. The type of the `event` variable is Table and the script must return a Table representing a valid JSON object. 79 80 ## JQ Command 81 82 ```yaml 83 apiVersion: argoproj.io/v1alpha1 84 kind: Sensor 85 metadata: 86 name: webhook 87 spec: 88 template: 89 serviceAccountName: operate-workflow-sa 90 dependencies: 91 - name: test-dep 92 eventSourceName: webhook 93 eventName: example 94 transform: 95 jq: ".body.message *= 2" 96 triggers: 97 - template: 98 name: webhook-workflow-trigger-1 99 conditions: "test-dep-foo" 100 k8s: 101 operation: create 102 source: 103 resource: 104 apiVersion: argoproj.io/v1alpha1 105 kind: Workflow 106 metadata: 107 generateName: webhook- 108 spec: 109 entrypoint: whalesay 110 arguments: 111 parameters: 112 - name: message 113 # the value will get overridden by event payload from test-dep 114 value: hello world 115 templates: 116 - name: whalesay 117 inputs: 118 parameters: 119 - name: message 120 container: 121 image: docker/whalesay:latest 122 command: [cowsay] 123 args: ["{{inputs.parameters.message}}"] 124 parameters: 125 - src: 126 dependencyName: test-dep 127 dataKey: body 128 dest: spec.arguments.parameters.0.value 129 ``` 130 131 1. The above script applies a JQ command `.body.message *= 2` on the event data which appends the value of `.body.message` to itself and 132 return the event. 133 134 2. The output of the transformation must be a valid JSON object.