# Constructor Blocks

## What It Is

Botconsole's visual scenario builder provides dedicated actions and blocks for e-commerce automation. You can assemble product showcases, interactive shopping carts, inventory validation, order registration, instant payment processing, and AI advisory workflows without any coding.

## Essential E-Commerce Blocks

| Block / Action | Purpose |
|---|---|
| **Products & Orders** | Look up catalog products, load customer purchases, create orders, and manage shopping cart items |
| **AI Dialog** | Conversational product recommendations, answering customer inquiries, natural language checkout |
| **Payment**  | Generate checkout invoices via Telegram Payments, Stripe, and other gateways |
| **Input / Form**  | Collect customer shipping details, telephone numbers, and notes |
| **Condition** | Check item stock levels, enforce minimum order sums, or verify payment completion |

---

## Products & Orders Actions in Scenarios

In the scenario builder, select your action category: **Products** or **Orders**.

### 1. Product Actions

- **Get Product**: loads all attributes of a single product into a variable (default `shop`).
  - Includes a built-in **«Test»** button: instantly previews live product data and automatically saves properties (`{{shop.name}}`, `{{shop.price}}`, `{{shop.image}}`, etc.) into constructor variable autocomplete hints.
  - All image and video links return as complete web links (`https://...`).
- **Get Products**: retrieves a list of all active products in the store catalog.
- **Get Products by Category**: filters the catalog by category.
- **Create Product**: allows your bot scenario to programmatically add a new item to the store catalog.

### Product Variable Properties:
- `{{shop.id}}` — Product ID
- `{{shop.name}}` — Title
- `{{shop.price}}` — Active price
- `{{shop.old_price}}` — Previous / list price
- `{{shop.amount}}` — Available stock
- `{{shop.description}}` — Summary
- `{{shop.image}}` — Direct photo URL
- `{{shop.video}}` — Direct video URL
- `{{shop.video_thumb}}` — Video poster thumbnail URL
- `{{shop.sku}}` — SKU identifier

---

### 2. Order Actions

All order actions automatically keep the purchased items list, quantities, and final totals synchronized:

| Action | Description |
|---|---|
| **Get Order by ID** | Loads an order and its full list of purchased items into variable `order`. Features a **«Test»** button |
| **Get Orders by User** | Fetches a customer's order history using their **User ID** (`{{USER_ID}}`). Features a **«Test»** button |
| **Create Order** | Creates a new order with status «New», saves selected items, and calculates taxes, discounts, and total amount |
| **Update Order** | Updates order parameters or modifies line items |
| **Add Goods to Order** | Appends an item to the order cart. If already present, increments quantity and recalculates the order total |
| **Remove Goods from Order** | Removes an item from the order and recalculates the total |
| **Change Goods Qty in Order** | Adjusts unit count. Setting `0` removes the item from the cart automatically |
| **Delete Order** | Deletes the order from the registry |

### Accessing Order Line Items in Variables:
- `{{order.id}}` — Order ID
- `{{order.summa}}` — Total amount payable
- `{{order.status}}` — Current status
- `{{order.goods.0.product_name}}` — First item title
- `{{order.goods.0.price}}` — First item unit price
- `{{order.goods.0.quantity}}` — First item quantity
- `{{order.goods.0.summa}}` — First item line total
- `{{order.goods.0.product_image}}` — First item photo URL

---

## «Test» Buttons for Fast Development

Every retrieval action (**«Get Product»**, **«Get Order by ID»**, **«Get Orders by User»**) features an inline **«Test»** button:
1. Click «Test» directly inside the action settings.
2. The system executes a sample query against your bot's catalog (automatically selecting the latest record if parameters are not yet specified).
3. The response is immediately displayed in the preview window.
4. All available fields are automatically saved into the variable autocomplete hints for quick insertion into chat messages.

---

## Connecting with the AI Dialog Block

To build an intelligent sales advisor:
1. Add an **«AI Dialog»** block to your flow.
2. Instruct the model in the system prompt on its role as a friendly, expert product consultant.
3. Supply the product catalog or enable catalog search tools.
4. When the customer confirms their purchase intent, route the scenario to a **«Create Order»** action followed by a payment invoice link.

