---
title: Tengo Script
slug: litmusedge/tengo-script
docTags: 
createdAt: 2024-08-06T18:55:53.677Z
---

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.

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/GRpsX8049L2wtne6aqynd_image.png" size="80" width="768" height="714" position="flex-start" showCaption="false" darkWidth="768" darkHeight="714"}

From the editor, you can also access:

- **Fullscreen**, to show the Code Editor in full-screen mode.

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/ydRwRzxTAchIUWb-yRG4S_image.png" size="80" width="1291" height="867" position="flex-start" showCaption="false" indent="2" darkWidth="1291" darkHeight="867"}

- **Playground**, to test, write, and validate your script in real time before deploying it.

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/7sHUytCjJgNd8MWnJrvnI_image.png" size="80" width="1916" height="965" position="flex-start" showCaption="false" indent="2" darkWidth="1916" darkHeight="965"}

- **Validate** to check your code.

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/KJJxmrAyAIRXnf5oBRl9i_image.png" size="80" width="767" height="444" position="flex-start" showCaption="false" indent="2" darkWidth="767" darkHeight="444"}

### 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/)

