Skip to content
Visual explainer 3h to learn 4 steps

Inbound call routing and an optional SIP voice lab

Diagram inbound call routing, test with a simulator or test number and synthetic callers, and verify signed provider events.

By Invicly Tech, , in n8n, AI Automation and Voice Agents. About 9 minutes to read.

Topic 28 of 43

In short

An inbound phone call reaches your agent through a chain: the caller's carrier, a SIP trunk, the voice provider, then a webhook to your server that accepts, rejects or transfers the call. This topic draws that path, tests it with a simulator or a test number, and keeps the call separate from the booking.

Think of it like this: A call is like a courier delivery: the phone line is the van, the webhook is the doorbell, and the booking is a separate order that only exists once someone signs for it.

Explained simply

When someone phones your assistant, the call does not go straight to your code. It goes from the caller's phone company to a SIP trunk, which is a virtual phone line over the internet. The trunk delivers the call to the voice provider.

The provider then tells your server about it with a webhook, which is a web request it sends to an address you chose. Your server looks at the request and decides: accept the call, reject it, or later transfer it to a person.

Because anyone can send a request to a public address, the provider signs each webhook. You check the signature before you trust it. You also check the timestamp and the event ID, so an old or repeated message does nothing.

A call and a booking are different things. The call is the live conversation. The booking is the business result, and it may be proposed, approved and written long after the call ended. Keep their records separate, or a dropped call will confuse your bookings.

Press Play on a diagram to walk through it one step at a time.

FlowInbound call path
  1. 1
    Caller

    Dials a test number

  2. 2
    Carrier and SIP trunk

    Routes the call to the provider

  3. 3
    Voice provider

    Sends a signed incoming-call webhook

  4. 4
    Your server

    Verifies, then accepts or rejects

  5. 5
    Voice session

    Agent talks to the caller

  6. 6
    Workflow

    Booking proposal in n8n

CompareCall state and booking state
Call state
  • Ringing, accepted, ended
  • Lasts minutes
  • Owned by the voice gateway
  • Holds the call ID
Booking state
  • Proposed, approved, written
  • Can last days
  • Owned by n8n and the store
  • Holds the proposal ID

In depth

The inbound path, step by step

The caller dials a number. The carrier sends the call over a SIP trunk to the provider's SIP address, which usually includes your project ID so it knows whose call this is. The provider sends your webhook an incoming-call event with an ID for that call. Your server verifies the signature and then calls the provider's accept action, setting the agent's instructions and voice. If you do not want the call, you call reject with a status code. Later you can transfer it to a person with a refer action or end it with hang up. Exact event and endpoint names change, so read the current provider docs before coding.

  • Decide quickly: the caller is waiting while the phone rings
  • The first accept or reject wins
  • Keep the call ID and store it with your own record
  • Transfer targets are SIP or tel addresses

Verifying signed webhooks

A signed webhook carries an ID, a timestamp and a signature, usually in headers. You compute the signature from the raw request body and your signing secret, then compare it to the one received. Use the raw bytes, not a re-serialised copy, or the check will fail. Reject requests whose timestamp is too old, and store event IDs you have processed so a retry does nothing. Many providers follow the Standard Webhooks style, and some official SDKs have a helper that does the check.

FlowWebhook checks, in order
  1. 1
    Read raw body

    Before any parsing

  2. 2
    Check signature

    Compare with your secret

  3. 3
    Check timestamp

    Reject old deliveries

  4. 4
    Check event ID

    Skip if already handled

  5. 5
    Act

    Accept, reject or record

Testing without a real phone number

A real inbound number and trunk usually cost money and need an account with a provider and sometimes a carrier. For learning, you do not need one. Write a small simulator that posts fake incoming-call events to your server, signed with a test secret, and that plays a recorded or synthetic audio clip as the caller. If your provider offers a test number, use it with a synthetic caller you control, never with a real person's number. Expected evidence: your logs show a verified event, an accept decision and a call record in your own store.

  • Simulator: signed fake events, no cost
  • Test number: optional and paid, check the provider's pricing
  • Use fictional names and numbers such as 555-0100

Call state versus booking state

Give each its own table and its own IDs. A call record holds the call ID, start and end time, outcome and handoff. A booking record holds the proposal, who approved it and whether the calendar was updated. Link them by a correlation ID. When a call drops after the proposal is sent, the booking can still complete. When the call ends with no proposal, there is no booking at all. This split also helps with replay and incident reviews.

Learn it in 4 short steps

About 45m each. Track them with a timer in your plan.

  1. 1
    Diagram the inbound call path~45m
  2. 2
    Use a simulator or test number~45m
  3. 3
    Verify signed provider webhooks~45m
  4. 4
    Separate call state from booking state~45m

Key points

  • SIP is the signalling protocol that sets up, changes and ends phone calls over IP. RFC 3261 defines it.
  • Verify every provider webhook signature and reject old or repeated deliveries before acting on it.
  • A call has its own state (ringing, accepted, ended). A booking has a different state (proposed, approved, written). Keep them in separate records.
  • Telephony needs a paid number or trunk. For learning, use a simulator, a recorded test call or synthetic callers.

Key terms

Tap a card to flip it. 0/5 known

Examples

Verify a webhook and skip duplicates

Scenario: your handler receives an incoming-call event. Steps: verify the signature on the raw body, reject old timestamps, check the event ID, then process. Expected evidence: sending the same event twice produces one accept and one ignored duplicate in the logs. Use a test signing secret only.

ts
app.post("/hooks/voice", express.raw({ type: "*/*" }), async (req, res) => {
  const ok = verifySignature(req.body, req.headers, process.env.WEBHOOK_SECRET);
  if (!ok) return res.sendStatus(400);
  const id = req.headers["webhook-id"] as string;
  if (await seen(id)) return res.sendStatus(200);
  await markSeen(id);
  const event = JSON.parse(req.body.toString());
  await handleIncoming(event);
  res.sendStatus(200);
});

A synthetic caller lab

Prerequisites: your webhook handler and a signing helper. Steps: write a script that builds a fake incoming-call event for Fabrikam Dental, signs it with the test secret and posts it. Then check that a call record appears. Cleanup: delete the test records. Rollback: stop the script and clear the seen-event table.

ts
const body = JSON.stringify({
  type: "incoming_call",
  data: { call_id: "call_test_001", from: "+15550100" },
});
const headers = signTest(body, "test-secret");
await fetch("http://localhost:3000/hooks/voice", {
  method: "POST",
  headers,
  body,
});

Quick reference

  • SIP sets up and ends calls over IP; RFC 3261 defines it.
  • Verify signature on the raw body, then timestamp, then event ID.
  • Return 2xx fast; do slow work after acknowledging.
  • Call state and booking state: separate records, linked by an ID.
  • Practise with a simulator and synthetic callers, not real numbers.
  • Event and endpoint names change: read the provider docs first.

Common mistakes

  • Trusting a webhook body without checking its signature and timestamp.
  • Treating a completed call as a confirmed booking.
  • Testing with real people's phone numbers or recordings instead of synthetic callers.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1What does a SIP trunk do?

Question 2

2Why use the raw request body when verifying a signature?

Question 3

3A webhook arrives twice with the same event ID. What should happen?

Question 4

4The caller hangs up before approval. What happens to the booking proposal?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Sketch the inbound path from caller to booking as a numbered list of six steps.

  2. Exercise 2medium

    Write the checks your webhook handler runs before acting, in order, with one reason for each.

  3. Exercise 3hard

    Design the tables for call state and booking state and show how a dropped call still lets a booking finish.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Do I need a real phone number to learn this?
No. A simulator that posts signed fake events and synthetic audio is enough to learn the whole flow.
What is a webhook?
A web request one service sends to your address when something happens, such as an incoming call.
Why should the webhook answer quickly?
Providers expect a fast reply and retry if they get none. Acknowledge first and do slow work afterwards.

Go deeper

ShareXLinkedInWhatsApp