# Prepare Your Workflow

In this step we’ll set up the [n8n](https://n8n.io/) workflow that powers your SaaS.\
Our example workflow receives data from a webhook and forwards it to a Telegram chat.

{% hint style="success" %}
We’re using **n8n** as the automation engine. However, AgentCraft works with any platform that can expose a webhook or API endpoint — such as **Zapier**, **Make (Integromat)**, or **Flowise**. The concepts are the same: you send data to a webhook, process it, and return a response.
{% endhint %}

### What You’ll Build

We’re creating a simple SaaS service where customers send data to your webhook, and the data is delivered to their Telegram channel.\
This will help you understand how AgentCraft connects n8n workflows with end-user actions.

<figure><img src="/files/dnAef8q6dCswUxI8E40U" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**What Is an n8n Workflow?**

An **n8n workflow** is a visual automation consisting of connected nodes.\
Each node performs an action (receive data, transform data, call an API). When triggered, the workflow executes step by step — similar to a flowchart. In our example, one node receives a webhook, another formats data, and the last sends it to Telegram.
{% endhint %}

Our workflow contains three nodes:

* **Webhook** – receives POST requests from your customers.
* **Edit Fields** (Set node) – maps and formats the incoming data.
* **Telegram** – sends the formatted message to a Telegram chat.

#### Webhook Node

* **Method:** POST
* **Path:** your webhook endpoint (e.g. telegram\_notificator)
* **Auth:** Header Auth (customers will provide their API key / token later)

#### Edit Fields Node

* Maps incoming payload to `body.data`
* Prepares it for Telegram output

#### Telegram Node

* **Chat ID:** your Telegram channel or group
* **Message:** pulls `{{$json.body.data}}` from the previous step
* **Disable Attribution:** true

{% hint style="info" %}
**Creating a Telegram Bot and Adding It to n8n**

1. In Telegram, search for **@BotFather** and start a chat.
2. Use `/newbot` to create a new bot. Follow the prompts to set a name and username.
3. BotFather will send you an **API token** (keep it safe).
4. In n8n, open **Credentials → Telegram API**.
5. Paste your API token there and save.
6. In your Telegram node, select this credential to authenticate your bot.

> Once saved, n8n can send messages to your bot or channel using this token.
> {% endhint %}

#### Test the Workflow

* Create a Telegram Chat and connect the Bot to the Chat
* Click **Execute Workflow** in n8n.
* Send a POST request to your webhook URL with a `body.data` field.&#x20;

```
curl -X POST "<YOUR_WEBHOOK_URL>"
-H "Content-Type: application/json"
-H "Authorization: Bearer <YOUR_API_KEY>"
-d '{ "body": { "data": "Hello from curl test!", "chatId":"<YOUR_TG_CHAT_ID>" } }'
```

{% hint style="success" %}
You can find Telegram chatId by writing /start to @userinfobot&#x20;
{% endhint %}

* Check that the message appears in your Telegram chat.

Once the workflow works end-to-end, you’re ready to register it in AgentCraft to turn it into a SaaS product.


---

# 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.agentcraft.pro/quick-start-build-your-first-saas/prepare-your-workflow.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.
