← Back to docs

Recipe: Capture leads (name, email, phone)

Power user

Recipe: Capture leads

When a visitor asks about pricing, demos, or quotes — that's buying intent. Capture their details before the conversation drifts.

Detect intent and ask for an email

import re

INTENT_PHRASES = ["how much", "pricing", "quote", "demo", "trial", "sales"]
EMAIL_REGEX = re.compile(r"[\w\.-]+@[\w\.-]+\.\w+")

def respond(message, context):
    msg = message.lower()
    history = context.get("history", [])

    # Already captured an email earlier? Don't ask again.
    transcript = " ".join(t.get("content", "") for t in history)
    if EMAIL_REGEX.search(transcript):
        return None

    # Buying intent detected — ask for an email
    if any(phrase in msg for phrase in INTENT_PHRASES):
        return ("Happy to help with that. Could you share your email so we can send full details "
                "and follow up if needed?")

    return None

Confirm the email and forward to your CRM

The next message is likely the email itself. Catch it:

import re
import requests

EMAIL_REGEX = re.compile(r"[\w\.-]+@[\w\.-]+\.\w+")

def respond(message, context):
    match = EMAIL_REGEX.search(message)
    if not match:
        return None

    email = match.group(0)

    # Send to your CRM webhook (replace with your real URL)
    try:
        requests.post(
            "https://hooks.zapier.com/hooks/catch/123/your-webhook",
            json={"email": email, "session_id": context.get("session_id")},
            timeout=3,
        )
    except Exception:
        pass  # never let webhook failures block the reply

    return f"Got it — {email}. Someone from sales will reach out within 1 working day. Anything else?"

Multi-step capture (name + email + phone)

Use a simple state machine via the conversation history:

def respond(message, context):
    history = context.get("history", [])
    bot_msgs = [t["content"] for t in history if t.get("role") == "assistant"]

    if any("what's your name" in m.lower() for m in bot_msgs[-3:]):
        # Last bot message was asking for name
        name = message.strip()
        return f"Thanks {name}! What's your email?"

    if "demo" in message.lower():
        return "Sure, I can book you a demo. What's your name?"

    return None

That's a basic pattern — for serious flows, use a real form widget rather than chatting through it.