# Workflows: automations and bots

> Build flows with triggers, blocks and fields, test them in the simulator, publish versions, follow runs and create or change flows with the AI.

Workflows automate your customer service: they reply to customers, ask questions, transfer to a sector, query other systems and notify your team. In the menu they live under **Workflows**. To create and edit them, you need the **Manage workflows** permission.

## Creating a flow

1. In the menu, open **Workflows** and click **New workflow**.
2. Enter a **Name** (unique per account) and click **Create and open editor**.
3. In the editor, click the **Trigger** block and choose **When to fire**.
4. Drag blocks from the **Blocks** palette into the flow, or click a block to add it.
5. Connect each block's outputs to the next one.

The draft is saved automatically while you edit. The **Arrange** button repositions the blocks automatically.

## Triggers

The trigger sets when the flow starts:

- **Message received**, **Conversation created** and **Conversation updated**: events from Conversations.
- **When starting a conversation (blocking)**: runs before the conversation exists and can stop it from starting. It only accepts conditions, **HTTP request** and **Block with message**.
- **Contact date (scheduled)**: fires for each contact based on a Date attribute. You set the **Days after the date**, the repetition, the **Send time** and the **Time zone**. Without a **Sending inbox**, the flow only runs actions.
- **Webhook**: click **Generate URL and secret**. Another system sends a JSON body to that URL, with the secret in the `X-Vend-Webhook-Secret` header, and the flow runs right away, with no conversation.
- **On a schedule**: runs on its own every N minutes (minimum 5) or at times of day, on the chosen days of the week.
- **Label applied**: fires when one of the checked labels is applied to a conversation. None checked means any label.
- **Called by another flow**: the flow is started by the **Start another flow** block, either without a conversation or in a recipient's conversation.

Under **Start filter**, add conditions (for example inbox, channel, segment, label or message content) and choose whether **All conditions** or **Any condition** must hold.

> **Warning:** WhatsApp groups never trigger flows, not even the ones scheduled by contact date.

## Blocks

The palette sorts blocks into four groups:

- **Flow**: **Condition**, **Wait**, **Set variable**, **Hand off to human**, **End conversation**, **Avoid repeats**, **Transform data** and **Start another flow**.
- **Conversation**: **Send message**, **Send template**, **Options menu** and **Question**.
- **Actions**: **HTTP request**, **Assign agent**, **Transfer to segment**, **Update contact**, **Resolve conversation**, **Block with message**, **Find contact** and **Record event**.
- **Artificial intelligence**: **AI: detect intent**, **AI: extract data**, **AI: reply**, **AI: write text** and **AI: analyze and decide**.

AI blocks draw from one person's AI allowance, the flow's payer, shown in the editor. For AI blocks to work, someone has to click **Take over billing**.

If the flow has problems, the editor shows the error and warning counts. Click **Fix with AI** to ask the assistant for help.

## Dynamic fields

Texts and messages accept fields in double braces. Type `{{` to open the autocomplete, or use **Insert field**. A few examples:

- `{{contact.name}}`: the contact's name.
- `{{message.content}}`: the customer's message.
- `{{conversation.displayId}}`: the conversation number.
- `{{vars.key}}`: a flow variable.
- `{{response.key}}`: the response of an **HTTP request**.
- `{{trigger.field}}`: data received by the webhook or from another flow.

Credentials for external systems go under **Secrets** and are used as `{{secret.alias}}`. The value is never shown again after saving.

## Testing before publishing

1. Click **Test**.
2. Pick the **Version** (**Current draft** or **Published version**) and the **Inbox**.
3. Write the **Triggering message** and click **Start simulation**.
4. Reply as the customer to follow the path.

The simulator doesn't send messages, write anything or spend AI. HTTP requests are skipped, and on AI blocks you pick which output to simulate.

## Draft, publishing and versions

What you edit stays in the **Draft**. The flow only runs for real after you **Publish**, and each publish becomes a new version (v1, v2…).

- **Unpublished changes** means the draft differs from the live version.
- Conversations already in the flow finish on the version they started on.
- **Discard changes** resets the draft to the published version. This cannot be undone.
- **Unpublish** makes the flow stop firing. The draft and the version history remain.

## Runs

Click **Runs** to see every time the published flow ran in the last 14 days: the path it took, what each HTTP request returned and what went wrong.

- Check **Only with problems** to filter.
- Use **Highlight in flow** to see the path in the editor.
- Click **Analyze with AI** for the assistant to explain what happened and how to fix it.

For contact date flows, **Upcoming sends** lists the scheduled sends, and you can cancel a contact's send.

## Creating and changing flows with the AI

With the [AI assistant](https://talkvend.com/en/help/assistente-de-ia), you describe the flow in words. In an empty flow, click **Generate with AI**; on any screen, just ask the assistant.

The AI answers with cards for you to approve:

- **Create flow**: the flow is created as a draft, not published.
- **Change flow**: approving only saves the draft. What is published doesn't change.
- **Publish flow**: asks for confirmation before putting the version live.

Click **View on canvas** to preview the proposal in the editor before clicking **Approve**.

> **Tip:** test in the simulator before approving a publish, especially for flows that send messages to customers.
