# Solicitud de datos

Muchas veces es necesario solicitar y guardar ciertos datos de los clientes. Para esto se utiliza el tipo de acción `data-collect` y los key correspondientes:

Ejemplos:&#x20;

{% tabs %}
{% tab title="Nombre" %}

```xml
<action 
type="data-collect"   
key="customer.name"    
ignore_if_exists="ignore_if_exists"    
with_text="¿Cuál es tu nombre?"    
validation="regex"    
validation_pattern="^.{3,20}$"    
validation_error="Pareciera que ingresaste un nombre inválido. ¿Podrías volver a intentar?"
/>
```

{% endtab %}

{% tab title="E-mail" %}

```xml
<action    
type="data-collect"    
key="customer.email"    
ignore_if_exists="ignore_if_exists"    
with_text="¿Cuál es su correo electrónico?"    
validation="regex"    
validation_pattern="[^@\s]+@[^@\s]+\.[^@\s.]+$"    
validation_error="{email_error}"
/>
```

{% endtab %}

{% tab title="Ciudad y pais" %}

```xml
<action      
type="data-collect"      
key="customer.location"      
ignore_if_exists="ignore_if_exists"      
with_text="¿En que país/ciudad esta viviendo?" 
/>
```

{% endtab %}

{% tab title="Otros datos" %}
Se utiliza el key: **key="customer.extra\_fields.X", donde X describirá el dato**

```xml
<action type="data-collect" 
key="customer.extra_fields.dni" 
with_text="¿Cual es tu dni?" 
ignore_if_exists="ignore_if_exists" 
/>

```

{% endtab %}
{% endtabs %}

El comando `ignore_if_exists="ignore_if_exists"` sirve para no volver a pedirle el dato al cliente la próxima vez que escriba.

#### OBTENCIÓN DE OPT-IN&#x20;

Hay dos modos de configurar el pedido de autorización para recibir notificaciones de la empresa por whasapp:

* Por única vez independientemente de la respuesta del cliente
* Por cada contacto del cliente en caso de que haya respondido que "No"

{% tabs %}
{% tab title="Única vez" %}

```xml
<branches switch="customer.whatsapp_opt_in">    
 <branch cases="[False, None]">        
  <options header="¿Aceptas recibir notificaciones por Whatsapp?            
   
   <option text="Sí">                
   <action type="store" key="customer.whatsapp_opt_in" value="True" cast="cast"/>                
   <action type="hand-over" chat_group="ventas"/>             
   </option>            

   <option text="No">                
   <action type="store" key="customer.whatsapp_opt_in" value="False" cast="cast"/>                
   <action type="hand-over" chat_group="ventas"/>             
   </option>        
  </options>    
 </branch>   
  
<branch cases="[True]">      
 <action type="hand-over" chat_group="ventas"/>     
</branch>

</branches>
```

{% endtab %}

{% tab title="Reiterar por respuesta negativa" %}

```xml
<branches switch="customer.extra_data.one_time_whatsapp_opt_in">    
 
 <branch cases="[False, None]">        
 <options header="¿Aceptas recibir notificaciones por Whatsapp?            

 <option text="Sí">                
  <action type="store" key="customer.extra_data.one_time_whatsapp_opt_in" value="True" cast="cast"/>                
  <action type="store" key="customer.extra_fields.one_time_whatsapp_opt_in" value="True" cast="cast"/>                
  <action type="hand-over" chat_group="ventas"/>             
 </option>            

 <option text="No">                
  <action type="store" key="customer.extra_data.one_time_whatsapp_opt_in" value="False" cast="cast"/>                
  <action type="store" key="customer.extra_fields.one_time_whatsapp_opt_in" value="True" cast="cast"/>                
  <action type="hand-over" chat_group="ventas"/>             
 </option>        
 </options>    
</branch>    

 <branch cases="[True]">      
  <action type="hand-over" chat_group="ventas"/>     
 </branch>
 </branches>
```

{% endtab %}
{% endtabs %}

#### UTILIZACIÓN DE DATOS RECOLECTADOS

El dato recolectado se guarda dentro del CRM de Optiwe y puede utilizarse dentro de la misma conversación: **\<action type="reply"    with\_text="Hola {{customer.name}},\_\_\_\_\_\_\_\_\_"/>**

Ejemplo de como se utilza esta acción, dentro de un menu de opciones básico:

```xml
<?xml version="1.0" encoding="utf-8"?>
<root>
   <action        
   type="data-collect"        
   key="customer.name"        
   ignore_if_exists="ignore_if_exists"        
   with_text="¿Cuál es tu nombre? "        
   validation="regex"        
   validation_pattern="^.{3,20}$"        
   validation_error="Pareciera que ingresaste un nombre inválido. ¿Podrías volver a intentar?/>      <options header="¿Con cual de estas opciones te puedo ayudar? Seleccioná la opción escribiendo el número correspondiente👇">
        
  <option text="Ventas">            
   <action type="reply" with_text="Hola {{customer.name}}, como te podemos ayudar?"/>        
   </option> 
            
   <option text="Soporte">            
   ...        
   </option>
          
 </options>
 </root>   
```


---

# 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://soporte.optiwe.com/chatbots/estructura-basica/solicitud-de-datos.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.
