Tengo Script
4 min
the tengo script processor lets you write a tengo script, a scripting language with rules similar to go, to add, remove, or modify fields in the message from an input tag why use the tengo script processor use this processor when you need to reshape a message beyond what a fixed processor supports, for example, renaming a field (such as changing value to furnace pressure ), keeping only the fields you need and dropping the rest, deriving a new field from an existing value (such as adding an error field when value crosses a threshold), or reformatting a unix timestamp into a human readable one how it works write your script in the code editor timeout sets how long (in milliseconds) the script is allowed to run before it's considered timed out from the editor, you can also access fullscreen , to show the code editor in full screen mode playground , to test, write, and validate your script in real time before deploying it validate to check your code working with input messages every message from the input is stored in an array called values use a for i, message in values{} statement to loop over it message holds the full incoming message for you to manipulate, and i identifies which connection wire it came from for a single input, you can replace i with since there's only one connection to distinguish both i and message are just variable names; you can name them whatever you like with multiple inputs, for example three connection wires named a, b, and c, i tells you which wire each message came from as the loop runs use if else logic to manipulate each input differently, or apply the same manipulation to all of them you can output the result for a single input only, or for all of them related topics available standard library https //github com/d5/tengo/blob/master/docs/stdlib md syntax details github https //github com/d5/tengo or official site https //tengolang com/