Trigger-Based AI Automation: Webhook Inbox, Drafted Replies and an Approval Step, Without Code
Hands-on lab · IDE in your browser

Trigger-Based AI Automation: Webhook Inbox, Drafted Replies and an Approval Step, Without Code

Build an automation in a YAML file that answers a vet clinic's incoming messages: ignore machine mail so it never loops with an autoresponder, classify messages and spot emergencies, draft replies from the clinic's facts, send only routine answers and queue the rest for approval or page the vet, and handle webhook re-deliveries, proven on messages it has never seen.

Time
50 min
Checked steps
5
Level
Beginner
Setup
None
Read step 1

Hands-on labs require Pro · $29.99/mo · cancel anytime

The job

Pebblebrook Vets' messages arrive through a webhook, and an AI automation answers them. The first version replied to everything, including an autoresponder it then argued with. You make it answer routine questions on its own, put the rest in front of a person, and page the vet when a pet is in danger.

5 steps, each checked when you finish it

A check runs your work at the end of every step. Hints and the full solution are there if you get stuck.

  1. 1

    Ignore the robots

    Pebblebrook Vets gets its email and website messages through a webhook: each new message arrives as an event, and an automation answers it.

  2. 2

    Sort the messages

    Every message a person sends now reaches the classify step, and its answer drives everything after it.

  3. 3

    Draft from the facts

    The writer has never seen the clinic's hours or prices, so it guesses them.

  4. 4

    Decide what sends itself

    An automation earns its keep by answering routine questions with no one involved, and by putting everything else in front of a person.

  5. 5

    Once per message, on new messages

    Webhooks deliver "at least once": if the clinic's server is slow to answer, the same message arrives again with a new event_id.

Step 1 as it appears in the lab

The lab’s own text. The hint and the solution stay inside the lab.

Step 1: Ignore the robots

Pebblebrook Vets gets its email and website messages through a webhook: each new message arrives as an event, and an automation answers it. You will build that automation in automation.yaml. There is no code to write.

Click Run first. The starting automation sends a reply to every message. Look at the top of the scorecard: it answered a newsletter, a bounce message and an out-of-office autoresponder. The autoresponder answered back, and the bot answered that too: a reply loop, stopped only by the lab after three rounds.

Machines mark their mail. Autoresponders and notifications set an Auto-Submitted header (some use X-Autoreply), mailing lists set List-Unsubscribe, and bounces come from senders like mailer-daemon. People can write anything in a subject line, so a rule based on the subject can catch a real customer.

Do this in automation.yaml, under ignore::

  1. Add one rule per line: - header: Auto-Submitted, - sender_contains: no-reply, and so on. The three kinds are header: (the message has that header), sender_contains: and subject_contains:. Case is ignored.
  2. Click Run. The four machine messages should show ignore, and no one else's.
  3. python3 run_automation.py --event 19 shows one machine message in full.

The check also tries your rules on three machine messages and three people's messages that are not in the inbox.

automation.yaml, the file you edit26 lines
# automation.yaml: what happens when the clinic's inbox webhook delivers a message.
# Placeholders: {message} the sender, subject and text   {clinic} the clinic's facts (clinic.md)
#               {classify} the classify step's JSON, and {classify.category}, {classify.urgent} its fields
# Models: small = Llama 3.1 8B (cheap)   large = Llama 3.3 70B

ignore:
  # TODO (Step 1): rules for messages sent by machines: auto-replies, bounces, newsletters, notifications.

classify:
  model: small
  prompt: |
    What is this message about? Give it a category and say if it is urgent.

    {message}

    Reply with only JSON: {"category": "...", "urgent": true or false}

draft:
  model: small
  prompt: |
    Write a friendly reply to this message from a vet clinic.

    {message}

routes:
  - action: send
Provided for you:automation.pyclinic.mdevents.jsonlrun_automation.py

Frequently asked questions

How do you stop an email automation replying to autoresponders?

Ignore messages that machines mark: the Auto-Submitted and X-Autoreply headers, List-Unsubscribe for mailing lists, and no-reply or mailer-daemon senders. Rules on subject lines catch real customers too.

Which AI-drafted replies should be sent without approval?

Only routine questions answered from known facts, such as opening hours, prices and booking. Complaints, refunds, medical or legal questions and emergencies should go to a person.

Why do webhook automations send duplicate replies?

Webhooks deliver at least once, so the same message can arrive twice with a new event id. Deduplicate on the message's own id before acting.

AI email automation with an approval step

An AI that drafts replies to incoming messages saves time only if it knows what to ignore, what it can answer alone and what a person must see first. Webhooks add their own traps: machine mail and repeated deliveries. You write ignore rules from the headers machines set, a classifier with an urgency flag, a reply prompt grounded in the business's facts, routes that send, queue for approval or alert, and a deduplication key, then check the whole automation on messages it has never seen.