# Estructura

### Estructura base de un Autobot

La estructura básica de un Autobot se compone de los campos "steps" y "restart\_on\_refresh".&#x20;

* steps: Aquí estará contenido todo el flujo del bot
* restart\_on\_refresh: Esta clave define el comportamiento del bot al momento de recargar la página. Si tiene un valor *true* el bot comenzará desde el primer step, si su valor es *false* retomará el flujo en el último step conocido. Debe ser del tipo boolean.

```yaml
{
    "steps": [
    ],
    "restart_on_refresh": true,
}
```

### Ejemplo de un step

Cada "step" se compone de un elemento estructurado como clave / valor. El ejemplo hace referencia a un elemento de tipo "*text*" (Para mas información sobre elementos hacer [click aquí](https://docs.imbee.me/imbee-docs/autobots/broken-reference)). &#x20;

Cada elemento debe tener las siguientes claves:&#x20;

* name: Es el nombre del step. Debe ser del tipo string
* tags: Es la forma de indicar cual es el primer step del bot. Debe ser del tipo array de strings o del tipo null.
* actions: Son las acciones que realizará el bot en este step. Debe ser del tipo array de diccionarios. Puede contener n cantidad de elementos tipo "text"
* next\_step: Es el próximo step al que irá el bot una vez finalizadas todas las acciones a realizar en el step actual.&#x20;

{% hint style="warning" %}

* El primer step siempre debe tener el tag "init" con el siguiente formato: \["init"] y solo puede existir un step con este tag.
* El último step siempre debe tener el next\_step como *null*  y el tag "finish" con el siguiente formato: \["finish"].
  {% endhint %}

```yaml
{
    "name":"welcome",
    "tags": ["init"],
    "actions": [
        {
            "msg":"Hello world!",
            "type": "text"
        }
    ],
    "next_step": "step_2"
}
```

### Campos opcionales&#x20;

Estos campos no son necesarios para el funcionamiento básico del bot, no es necesario incluirlos salvo que se quieran activar ciertas funcionalidades

#### EVENT\_HOOKS

* notify\_all: Por defecto el bot guardará todas las interacciones del usuario (por ejemplo al introducir su nombre en un elemento del tipo "*input"*), no así los mensajes mostrados en pantalla (elementos tipo "*text"*). Si esta clave tiene valor *true* se guardaran todos los steps ... MEJORAR ESTA ENTRADA
* url: Url donde se deben notificar los estados del bot ...  MEJORAR ESTA ENTRADA

```yaml
"EVENT_HOOKS": {
    "notify_all": true,
    "url": "https://url_for_notifications.com"
}
```

#### ENVIRONMENT\_VARIABLES

Aquí es posible definir variables que estarán disponibles en cualquier momento del bot. (Para mas información sobre variables hacer [click aquí](https://docs.imbee.me/imbee-docs/autobots/variables)).

```yaml
"ENVIRONMENT_VARIABLES": {
    "@max_attemps" : "3"
}
```

### Ejemplo de un bot funcional

```yaml
{
    "steps": [
        {
            "name":"welcome",
            "tags": ["init"],
            "actions": [
                {
                    "msg":"Hola, gracias por leer la documentación de los Autobots",
                    "type": "text"
                },
                {
                    "msg":"En el siguiente paso te pediremos que nos digas tu nombre",
                    "type": "text"
                }
            ],
            "next_step": "name_request"
        },
        {
            "name":"name_request",
            "tags": null,
            "actions": [
                {
                    "msg":"Ahora si, podrías decirnos tu nombre?",
                    "type": "input_text"
                }
            ],
            "next_step": "goodbye",
            "variables": {
                "@name": "&input_text"
            }
        },
        {
            "name":"goodbye",
            "tags": ["finish"],
            "actions": [
                {
                    "msg":"Gracias @name por haber participado de esta sección",
                    "type": "text"
                },
                {
                    "msg":"Te invitamos a seguir recorriendo la documentación",
                    "type": "text"
                }
            ],
            "next_step": null
        }
    ],
    "restart_on_refresh": true,
    "EVENT_HOOKS": {
        "notify_all": true,
        "url": "https://url_for_notifications.com"
    },
    "ENVIRONMENT_VARIABLES": {
        "@max_attemps" : "3"
    }
}
```
