How to build an AI Agent in n8n connected to Altegio CRM for WhatsApp & Instagram automation?

Hello everyone,

I am looking to build an autonomous AI Agent using n8n (self-hosted version) to fully automate customer support and appointment scheduling for my business.

My goal is to deploy this AI Agent across WhatsApp Business API and Instagram Direct. It needs to handle the following core workflow automatically:

  1. Provide Pricing Information: When a customer asks about services, the AI should fetch the current price list from my CRM, Altegio, and send it back to the user.
  2. Check Available Time Slots: If the user wants to book an appointment, the AI should look up live availability/free slots in the Altegio calendar for a specific date or professional.
  3. Book Appointments: Once the user selects a time, the AI must collect their basic details (name, phone number) and instantly create a booking/record inside the Altegio CRM calendar.

I am planning to use the AI Agent node in n8n combined with an LLM (like OpenAI GPT-4o or Anthropic Claude) and custom HTTP Request tools.

Could anyone share a workflow template, a node setup example, or guide me on:

  • How to properly structure the API tool definitions (Headers, Request Bodies) so the AI Agent can accurately call Altegio v1/v2 API endpoints for checking slots and booking?
  • What is the best practice for handling real-time WhatsApp/Instagram webhooks inside an OpenAI-powered agent loop without hitting timeout or token repetition issues?

If anyone has built a similar setup for Altegio or a comparable scheduling CRM, I would highly appreciate your advice, JSON snippets, or any pre-made workflow blueprints!

Thank you in advance!


For this pattern (chat channel → AI agent → booking API), here’s a structure that holds up.

1. Split the webhook from the agent

Meta retries a webhook if it doesn’t get a 200 quickly, and that retry is where duplicate replies come from. So:

  • Workflow A (webhook): Webhook node → Respond to Webhook (200) immediately. Then drop the message ID if it’s already been seen (Remove Duplicates node, or a lookup in a Data Table), then Execute Workflow (don’t wait for it to finish) → Workflow B.
  • Workflow B (agent): does the slow LLM and Altegio work, then sends the reply through the WhatsApp/Instagram send-message API.

This removes both the timeouts and the “answered twice” problem.

2. Memory per customer

Use a memory node (Postgres or Redis Chat Memory rather than Simple Memory if you’re self-hosted) with the session key set to the sender ID, e.g. {{ $json.from }} for WhatsApp. Keep the context window small, 10–15 messages. Old tool outputs, like price lists, are what make the model repeat itself and burn tokens.

3. Altegio tools: few, narrow, explicit

Give the agent three HTTP Request Tool nodes rather than one generic “call the API” tool:

  • get_services – list services and prices.
  • get_free_slots(date, staff_id?) – available times.
  • create_booking(service_id, staff_id, datetime, name, phone).

In each tool:

  • Hard-code the URL, method and headers. Altegio’s API uses a partner token plus a user token in the Authorization header and a versioned Accept header; check the exact format in their API docs for your account.
  • Expose only the parameters the model must fill, using $fromAI('date', 'Date in YYYY-MM-DD', 'string') and so on.
  • Write a precise tool description, e.g. “Returns free time slots for one date. Call this before offering any time to the customer.”

The model is much more reliable choosing between three well-described tools than writing request bodies itself.

4. Guardrails in the system prompt

  • Never state a price or a time unless it came from a tool call in this conversation.
  • Before calling create_booking, repeat the service, date/time and name back to the customer and wait for a “yes”.
  • If the request is outside booking or prices, or the customer asks for a person, reply that a team member will follow up, and flag the conversation, e.g. a row in a sheet or a message to your phone.

5. Two channel gotchas

  • WhatsApp only allows free-form replies within 24 h of the customer’s last message. Reminders sent later need an approved template.
  • Instagram DMs come in through a different webhook payload. Normalise both channels into the same shape (channel, from, text, message_id) in Workflow A, so Workflow B doesn’t care where the message came from.

Before going live, test the booking tool with a dummy staff member or calendar in Altegio. A wrong datetime format usually fails silently or books the wrong day.

Agree with the split webhook setup above. Here are some things I would add to it:

  • Trim Altegio’s responses before they reach the agent. Wrap each tool in a sub-workflow (Call n8n Workflow Tool) then use a Set or Code node to only return the fields the model needs (id, title, price or even just the time strings). Raw API payloads are where most of the token bloat comes from.
  • Do your validation in the same sub-workflow: ISO date, normalised phone number, and a re-check that the slot is still free right before the booking call. That’s more reliable than trusting the model’s formatting.
  • Often customers will send 3 short messages in a row. Have a buffer of around 5-10 seconds (a Redis key per sender works) so the agent answers once, and avoid running two executions for the same sender at the same time, or memory gets out of order.

The webhook split and narrow-tool advice above covers most of it. One addition on memory, since you have two channels:

WhatsApp gives you a phone/wa_id and Instagram gives you an IGSID, so the same customer shows up with two different IDs. If you key chat memory on the raw sender ID, they’ll be two strangers. Resolve a stable customer key first: after the booking tool has their phone number, look up or create the Altegio client and use the Altegio client ID, or a normalised phone number, as the key. Keep the short-term chat window per conversation (Postgres/Redis Chat Memory keyed on channel+sender is fine, 10–15 messages as suggested). Store only durable facts (preferred professional, usual service, language) against the customer key so a return visit on either channel picks them up.

Disclosure: I work on MemorySync, which has a self-hosted community node (n8n-nodes-memorysync) built for exactly that split. Chat Memory takes a Session ID per conversation and an End User ID per person, and it extracts durable facts from the customer’s messages. You don’t need it: a Postgres table of facts keyed by the Altegio client ID works too.

Hi,

One detail I’d be careful about in your Altegio setup: the AI shouldn’t promise an appointment slot just because it was available a moment ago. It needs to recheck availability before booking, while handling webhook retries without replying to the same customer twice.

I’d build the n8n flow around three separate Altegio actions—fetch prices, check slots, and create bookings—with duplicate-message protection and a fast webhook acknowledgement.

I’m Atharv, an AI-Powered Systems Builder, and I’d be interested in implementing this with you rather than just sharing a workflow template.

Do you already have Altegio API access set up, and are you open to hiring someone for the implementation?

Best,
Atharv

is altegio already holding your live price list and staff calendar, or are you still setting that part up?

Hi, I’d build this as one webhook workflow plus an agent with three narrow tools. I haven’t run it against a live Altegio account, so test each tool with a manual call first. The endpoints below come from Altegio’s public Online Booking spec: Online Booking

Flow
Meta webhook (WhatsApp and Instagram) → Respond: Immediately → dedupe on message id → debounce → AI Agent with memory keyed by phone / IG id → reply on the same channel.

Tools (base URL https://api.alteg.io/api/v1)

  • get_services: GET /book_services/{location_id} (price_min, price_max, seance_length)
  • get_free_slots: GET /book_times/{location_id}/{staff_id}/{date} (GET /book_dates/{location_id} lists days with free sessions)
  • create_booking: POST /book_record/{location_id}

Put staff names and ids in the system prompt (GET /book_staff/{location_id} lists them).

Headers: Authorization: Bearer <partner_token> (keep it in a Header Auth credential; the “partner, User user_token” form is for the business endpoints), Accept: application/vnd.api.v2+json, Content-Type: application/json.

Free slots, HTTP Request Tool:

GET https://api.alteg.io/api/v1/book_times/<LOCATION_ID>/{{ $fromAI('staff_id','Team member id','number') }}/{{ $fromAI('date','YYYY-MM-DD','string') }}
Query: service_ids[] = {{ $fromAI('service_id','Chosen service id','number') }}

Booking body:

{ "phone": "{{ $fromAI('phone','Phone with country code','string') }}",
  "fullname": "{{ $fromAI('name','Customer name','string') }}",
  "appointments": [{ "id": 1, "services": [<service_id>], "staff_id": <staff_id>,
    "datetime": "<value copied from get_free_slots>" }] }

The schema says fullname while the text table says “full name”, so test it. A taken slot returns 422 with code 433: tell the agent to offer other times.

In the system prompt: confirm service, time, name and phone with the customer before create_booking, call get_free_slots again right before booking, and never build the datetime yourself.

Timeouts and repetition

  • Respond: Immediately answers Meta with a 200 and the workflow keeps running. Meta resends when it gets no quick 200, hence the dedupe.
  • n8n’s WhatsApp Trigger node handles Meta’s webhook verification for you. If you use a plain Webhook node instead (for example for Instagram), it must also answer Meta’s GET verification request (hub.challenge).
  • Run the agent in a sub-workflow so retries and errors stay separate.
  • Debounce: store each message, wait a few seconds, and let only the newest execution continue, joining the texts.
  • Use a small memory window. Simple Memory is fine for testing; use a database-backed memory node in production.
  • Put today’s date and the time zone in the system prompt.
  • Trim tool output with Optimize Response, selected fields only (services: id, title, price_min, price_max; slots: time, datetime).
  • Set a low max iterations on the agent. Altegio allows 200 requests/min and 5/sec per IP.
  • WhatsApp free-form replies work only within 24 hours of the customer’s last message; after that you need a template.

Instagram: it uses the same Meta app. Subscribe the webhook to the messages field and reply through the Instagram messaging API.

Please check in the docs: the $fromAI() arguments, the max iterations option name, Meta’s current permissions, and whether staff_id 0 means “any” on book_times.

I published a similar pattern for a WhatsApp support agent (FAQ, order lookup, hand-off to a person) here: GitHub - 1ybxows/n8n-whatsapp-ai-support-agent: Bilingual (English + Arabic) WhatsApp AI support agent for n8n 2.x: FAQ answers, order lookup, refund logging, human hand-off, weekly report. Demo on made-up data, with offline tests. · GitHub. Happy to help if you get stuck.

For the booking part, I’d keep the agent from writing to the calendar directly. Have it collect service, date and contact details, then pass them to a separate sub-workflow that checks availability and creates the booking, returning a clear confirmed/unavailable result for the agent to relay. That makes it much easier to test and stops the agent from inventing slots. Also store the conversation ID per customer, so a repeat message resumes the same session.

Hey, have you managed to get the booking part working with Altegio yet, or are you still setting it up?

I’d test the booking API separately before connecting it to the AI agent. If you’re stuck on a specific step, feel free to share what’s happening. Might be easier to figure it out from there.

For altegio + WhatsApp/IG, the agent should own booking end to end. Split it so meta never times out and the models can’t invent a slot

Webhook; workflow A answers meta with 200 immediately, dedupes on message_id, the kicks workflow B (don’t wait). Put the ai agents only in B

Three narrow tools only (HTTP request took, hard coded url, $fromAI for pars);

  • get_services
  • get_free_slots
  • Create_booking but better; agent collect service/time/name/phone, then a sub workflow recheck the slot and posts the booking. Agent just relays confirmed

Never let the model build date time itself, copy the value returned by get_free_soot . Confirm the customer before booking. Trim aktegio payload to id /title do it doesn’t loop and burn tokens

Same customer on WA + IG= two ids; once you have a phone key memory on alregio client ID not raw sender id

Full disclosure; I’m affiliated with pond ai. Pond ai builds run and maintain custom ai agents. Free architecture map first (yours to keep) plus a 7 days refund refund if you build with them

Do you already have altegio api token working on a normal HTTP request or is that the first blocker

You’ll want three Altegio API tools for the agent: get prices, get free slots (by date and staff) and create a booking. Each should return small, structured JSON. Confirm the booking back to the customer only after Altegio returns an ID, and log failures. If you’d rather have it built and tested for you, I do this kind of booking agent and can quote a fixed price. — Brian

One thing I’d add to the advice above: make the booking tool re-check the slot right before it creates the record, and have it return the Altegio record ID. The agent only tells the customer “booked” when that ID comes back; otherwise it apologises and offers the next free slot. That handles two people taking the same slot.

For Instagram, the webhook can arrive twice, so store the message ID and skip repeats before the agent runs.

Have you got a working API call to the free-slots endpoint yet, outside the agent? If you’d like a hand building the three tools (prices, slots, booking) and testing them on your account, I’m happy to do that as a small fixed job.

One thing I would add is: treat booking as a small state machine with an AI front end, not as a chat that the model drives all the way into the calendar. That separation is what makes this reliable in production.

For the two channels, I would use one agent workflow rather than building the logic twice. Right after each webhook, normalise WhatsApp and Instagram into the same object — channel, sender_id, text, and message_id. The agent then works with one format, and a Switch at the end sends the reply back through the correct channel.

Do not rely on the agent’s chat memory as the source of truth for booking progress. Keep per-customer state in an n8n Data Table or Redis, keyed by the Instagram IGSID first and by the normalised phone number once you have it. Store fields such as service_id, staff_id, datetime, and stage (awaiting_name, awaiting_confirmation, and so on). Chat memory is useful for natural conversation, but customers interrupt, restart, or send “yes” hours later — the workflow needs to know exactly what that “yes” refers to.

Most importantly, let the agent collect the details and propose a booking, but put the actual booking in a separate sub-workflow. That sub-workflow should receive the exact datetime value returned by the availability tool, call the free-slots endpoint again, and check with an IF/Code step that the slot is still there. If the customer has not yet confirmed the summary, it should return that summary and set the stage to awaiting_confirmation; when the customer says yes, run the re-check once more before creating the record. If the slot has gone, it returns other times instead. I would never let the model construct a datetime itself or call the create-booking endpoint directly; LLMs are quite capable of sounding certain about a slot that no longer exists.

On the Altegio side, use one narrow HTTP tool per operation — get services, get free slots, create booking — with tight descriptions and only the parameters the model must supply. Keep the tokens in n8n credentials, and handle user-token refresh in a separate scheduled workflow so the agent never sees or manages raw tokens. Also remember the WhatsApp 24-hour window: an immediate confirmation is fine, but a later reminder needs an approved template message.

Hi @dag07121991. The webhook split and the narrow tools above are the right base. Before you put this on a live number, I would close one hole that structure still leaves open: the same appointment can be created twice, and nothing in the flow would tell you.

It happens in three ordinary places.

One is Meta. If Workflow A is slow to answer, the webhook is redelivered with the same message id. Deduping on the id covers that, but only if the dedupe write lands before the agent starts working. If you check the Data Table and then insert, two deliveries that arrive 200ms apart can both pass the check. Insert first and decide after: upsert on message_id, and let the unique constraint pick the one that continues.

Second is the tool call itself. Your create_booking request times out at 30 seconds. Altegio may already have written the record. The agent sees a failure, retries, and you now have two bookings for one customer. Retrying a POST because you did not get a response is the same as booking twice.

Third is two customers, same slot. Both ask for 14:00 with the same staff member, get_free_slots shows it open to both, both agents write. A re-check right before the write narrows that window but does not close it. What closes it is the database, not the model.

The version I would ship is a two-phase booking with a key the model cannot invent:

// Code node, before the HTTP Request that creates the record
const { client_key, staff_id, service_id, datetime } = $json;
const booking_key = [client_key, staff_id, service_id, datetime]
  .map(v => String(v).trim())
  .join('|');

return [{ json: { ...$json, booking_key } }];
// Data Table: unique index on booking_key where status in ('pending','confirmed')

Write the row as pending with that key before you call Altegio. If the insert conflicts, the booking already exists, so the agent reads the existing record and tells the customer what it finds instead of trying again. After Altegio returns an id, flip the row to confirmed. If the call fails, the row stays pending and a scheduled sweep retries once with the same key, which is safe precisely because the key is the same.

Then the part that bites about a week after launch: the WhatsApp Cloud API only allows free-form messages inside the 24-hour window that opens when the customer writes to you. The “you are booked for 10:00 tomorrow” reminder lands outside it, so it needs an approved template, or it silently fails. Instagram has its own window. Plan that leg with the booking, not after.

Last one, and it is cheap: keep the model out of the state transitions. Four states (browsing, slot_offered, details_collected, confirmed) and a Code node that rejects a move unless the fields it needs are present. The model fills slots; it does not get to decide when a booking is done.

meta webhook
  -> respond 200 -> upsert message_id (unique) -> queue
      -> agent tool: get_services / get_free_slots   (read only)
      -> agent tool: reserve  -> insert pending row (unique booking_key)
                              -> POST book_record -> status=confirmed
      -> sweep (every 15m): pending older than 5m -> retry once, same key

Disclosure: I work with Pond AI. We build, run and maintain custom agents like this one, map the architecture for free before anything is committed and you keep that map either way, and a custom build carries a 7-day refund.

Are your reminders going out as templates already, or are you expecting to reply inside the window?

Hi,

I read your Altegio + WhatsApp/Instagram agent thread. The advice there is solid. If you’d rather have it built than build it yourself, I can take it on. One detail that’s easy to miss: Altegio’s booking endpoint should be called only after a fresh availability check in the same step, and the agent should confirm the slot back to the customer before booking. Otherwise two chats can grab the same time.

I build n8n agents with WhatsApp Cloud API, Instagram and booking APIs (Python too, if needed). Offer: price list, slot lookup and booking on WhatsApp first, then Instagram, for a fixed €750 on your self-hosted n8n. Free sample: a working price-list reply flow on your instance.

Do you already have WhatsApp Business API access approved?

Aria Tajeri

@dag07121991 if you’d like this built for you rather than building it yourself: I’d suggest a small paid first milestone before any WhatsApp or Instagram work. Two read-only tools in your self-hosted n8n, one returning your current Altegio price list and one returning free slots for a date and staff member, tested against a test branch or sample data you authorise. No booking writes yet.

I’d quote a fixed price for that once I’ve seen your Altegio API access and n8n setup, and you’d pay only after you’ve tried it. Is paid help what you’re after, and is API access ready?

Peter, The Trillium Company