# Scripts

#### Features

* Access input: customer phone number, session vars.
* Produce output `data` JSON and `outcome` string.
* Save `data` (optional with JSON Path to access any fields) to session variables.
* Fetch HTTP API and parse its response.

**Example script code:**

*UPPERCASE, `userName` are placeholders*

```
// name=SCRIPT_NODE1
export async function onExecute(input, config) {
    console.log('hello from script node!');
    const resp = await fetch('https://jsonplaceholder.typicode.com/users/1');
    const body = await resp.json();

    // 👉 return [data, outcome]
    return [{FIELD1: 'one', FIELD2: 42, userName: body.name}, 'OUTCOME2'];
}
```

**Parameter: `input`**

*UPPERCASE are placeholders*

```
{
    "sessionContext": {
        "business": { "id": "..." },         // only business.id
        "customer": { "phoneNumber": "..." } // only customer.phoneNumber
        "variables": { "VAR1": "1", ... }    // session variables
    },
    "SCRIPT_NODE1": {
        "outcome": "...",                    // SCRIPT_NODE1.outcome
        "data": { "FIELD1": "one", ...}      // SCRIPT_NODE1.data
    }
}
```

**Parameter: `config`**

*UPPERCASE are placeholders*

```
{
    "secrets": { "SECRET1": "one", ... }
    // other session data, but won't be supported in v1
}
```

**Return: `[data, outcome]`**

```
return [{FIELD1: 'one', FIELD2: 42}, 'OUTCOME2']
```

* must return in format `[data, outcome]`
  * other formats may be partially supported: only data, only outcome, etc.

**`outcome`**: must be a string

* each possible outcome will be mapped to an edge
* there is **no default outcome** nor **fallback outcome** for v1

**`output`**: must be a json object

* no other requirement

#### Mapping `data` and `outcome`

*UPPERCASE are placeholders*

| `raw_param`  | session variable |
| ------------ | ---------------- |
| `outcome`    | → `VARX`         |
| `data`       | → `VAR1`         |
| `data.FOO.1` | → `VAR_FOO1`     |

\ <br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.connectly.ai/integrations/scripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
