# Module 3: Hands-on Lab: Building a Lead Qualification Workflow

This hands-on lab will guide you through the process of building a practical n8n workflow that uses a raiaAI agent to qualify a new lead.

{% embed url="<https://youtu.be/Lat2TYBSgqs>" %}

**Objective:** To create a workflow that is triggered by a new lead, uses a raiaAI Analyst Agent to score the lead, and then sends a notification to a sales team based on the score.

**Materials:**

* Access to n8n
* An Analyst Agent that you have created in the raiaAI Launch Pad (instructions below)
* Access to a Slack workspace

**Step 1: Create the Analyst Agent**

1. In the raiaAI Launch Pad, create a new agent named "Analyst Agent - Lead Scoring - \[Your Name]".
2. In the instructions, define the agent's role: "You are a data analyst. Your job is to score a new lead based on the provided information. A good lead is a company with more than 100 employees and a budget of over $10,000. A great lead is a company with more than 500 employees and a budget of over $50,000. Respond with only the score: 'Poor', 'Good', or 'Great'."

**Step 2: Build the n8n Workflow**

1. **The Trigger:** For this lab, we will use a "Webhook" trigger. A webhook is a URL that can receive data from other applications. In a real-world scenario, this webhook would be called by a lead capture form on a website.

* Add a Webhook node to your canvas.
* Copy the "Test URL" provided by the node.

1. **Simulate a New Lead:** Open a new browser tab and paste the webhook URL. Add the following query parameters to the URL to simulate a new lead: `?companyName=TechCorp&employeeCount=250&budget=25000` Press Enter. You should see a message in your browser that says "Workflow executed."
2. **The raiaAI Node:**

* Add a raiaAI node to your workflow and connect it to the Webhook node.
* Configure the node with your raiaAI credentials.
* Select your "Analyst Agent - Lead Scoring" agent.
* In the "Prompt" field, you will use data from the webhook. N8n allows you to reference data from previous nodes using expressions. Use the following expression to create the prompt: `Company: {{ $json.query.companyName }}, Employees: {{ $json.query.employeeCount }}, Budget: {{ $json.query.budget }}`

1. **The IF Node:**

* Add an IF node and connect it to the raiaAI node. The IF node will allow us to branch the workflow based on the agent's response.
* Configure the IF node to check the output of the raiaAI node. Set the condition to: `{{ $node["raiaAI"].json.response }}` - "is" - "Great".

1. **The Slack Nodes:**

* Add two Slack nodes to your canvas.
* Connect the "true" output of the IF node to the first Slack node. Configure this node to send a message to a #sales channel: "🔥 Great new lead! Company: {{ $json.query.companyName }}. Get on it!"
* Connect the "false" output of the IF node to the second Slack node. Configure this node to send a message to a #marketing channel: "New lead for nurture campaign: {{ $json.query.companyName }}."

**Step 3: Test the End-to-End Workflow**

1. Execute the workflow by calling the webhook URL with different data. Try a "Poor" lead and a "Great" lead.
2. Verify that the correct message is sent to the correct Slack channel based on the lead score.

This lab has demonstrated how to build a powerful, automated workflow that combines the data-processing capabilities of n8n with the intelligence of a raiaAI agent. This is a foundational pattern that you will use to build a wide variety of automated solutions for our clients.
