In “Tutorial – How to Use the Inbound Call Webhook & Dynamic Variables in Retell AI!” Henryk Brzozowski shows how Retell AI now lets you pick which voice agent handles inbound calls so you can adapt behavior by time of day, CRM conditions, country code, state, and other factors. This walkthrough explains why that control matters and how it helps you tailor responses and routing for smoother automation.
The video lays out each step with timestamps—from a brief overview and use-case demo to how the system works, securing the webhook, dynamic variables, and template setup—so you can jump to the segments that matter most to your use case. Follow the practical examples to configure agent selection and integrate the webhook into your workflows with confidence.
Overview of the Inbound Call Webhook in Retell AI
The inbound call webhook in Retell AI is the mechanism by which the platform notifies your systems the moment a call arrives and asks you how to handle it. You use this webhook to decide which voice agent should answer, what behavior that agent should exhibit, and whether to continue, transfer, or terminate the call. Think of it as the handoff point where Retell gives you full control to apply business logic and data-driven routing before the conversation begins.
Purpose and role of the inbound call webhook in Retell AI
The webhook’s purpose is to let you customize call routing and agent behavior dynamically. Instead of relying on a static configuration inside the Retell dashboard, you receive a payload describing the incoming call and any context (CRM metadata, channel, caller ID, etc.), and you respond with the agent choice and instructions. This enables complex, real-time decisions that reflect your business rules, CRM state, and contextual data.
High-level flow from call arrival to agent selection
When a call arrives, Retell invokes your configured webhook with a JSON payload that describes the call. Your endpoint processes that payload, applies your routing logic (time-of-day checks, CRM lookup, geographic rules, etc.), chooses an agent or fallback, and returns a response instructing Retell which voice agent to spin up and which dynamic variables or template to use. Retell then launches the selected agent and begins the voice interaction according to your returned configuration.
How the webhook interacts with voice agents and the Retell platform
Your webhook never has to host the voice agent itself — it simply tells Retell which agent to instantiate and what context to pass to it. The webhook can return agent ID, template ID, dynamic variables, and other metadata. Retell will merge your response with its internal routing logic, instantiate the chosen voice agent, and pass along the variables to shape prompts, tone, and behavior. If your webhook indicates termination or transfer, Retell will act accordingly (end the call, forward it, or hand it to a fallback).
Key terminology: webhook, agent, dynamic variable, payload
- Webhook: an HTTP endpoint you own that Retell calls to request routing instructions for an inbound call.
- Agent: a Retell voice AI persona or model configuration that handles the conversation (prompts, voice, behavior).
- Dynamic variable: a key/value that you pass to agents or templates to customize behavior (for example, greeting text, lead score, timezone).
- Payload: the JSON data Retell sends to your webhook describing the incoming call and associated metadata.
Use Cases and Demo Scenarios
This section shows practical situations where the inbound call webhook and dynamic variables add value. You’ll see how to use real-time context and external data to route calls intelligently.
Common business scenarios where inbound call webhook adds value
You’ll find the webhook useful for support routing, sales qualification, appointment confirmation, fraud prevention, and localized greetings. For example, you can route high-value prospects to senior sales agents, send calls outside business hours to voicemail or an after-hours agent, or present a customized script based on CRM fields like opportunity stage or product interest.
Time-of-day routing example and expected behavior
If a call arrives outside your normal business hours, your webhook can detect the timestamp and return a response that routes the call to an after-hours agent, plays a recorded message, or schedules a callback. Expected behavior: during business hours the call goes to live sales agents; after-hours the caller hears a friendly voice agent that offers call-back options or collects contact info.
CRM-driven routing example using contact and opportunity data
When Retell sends the webhook payload, include or look up the caller’s phone number in your CRM. If the contact has an open opportunity with high value or “hot” status, your webhook can choose a senior or specialized agent and pass dynamic variables like lead score and account name. Expected behavior: high-value leads get premium handling and personalized scripts drawn from your CRM fields.
Geographic routing example using country code and state
You can use the caller’s country code or state to route to local-language agents, region-specific teams, or to apply compliance scripts. For instance, callers from a specific country can be routed to a local agent with the appropriate accent and legal disclosures. Expected behavior: localized greetings, time-sensitive offers, and region-specific compliance statements.
Hybrid scenarios: combining business rules, CRM fields, and time
Most real-world flows combine multiple factors. Your webhook can first check time-of-day, then consult CRM for lead score, and finally apply geographic rules. For example, during peak hours route VIP customers to a senior agent; outside those hours route VIPs to an on-call specialist or schedule a callback. The webhook lets you express these layered rules and return the appropriate agent and variables.
How Retell AI Selects Agents
Understanding agent selection helps you design clear, predictable routing rules.
Agent types and capabilities in Retell AI
Retell supports different kinds of agents: scripted assistants, generative conversational agents, language/localization variants, and specialized bots (support, sales, compliance). Each agent has capabilities like voice selection, prompt templates, memory, and access to dynamic variables. You select the right type based on expected conversation complexity and required integrations.
Decision points that influence agent choice
Key decision points include call context (caller ID, callee number), time-of-day, CRM status (lead score, opportunity stage), geography (country/state), language preference, and business priorities (VIP escalation). Your webhook evaluates these to pick the best agent.
Priority, fallback, and conditional agent selection
You’ll typically implement a priority sequence: try the preferred agent first, then a backup, and finally a fallback agent that handles unexpected cases. Conditionals let you route specific calls (e.g., high-priority clients go to Agent A unless Agent A is busy, then Agent B). In your webhook response you can specify primary and fallback agents and even instruct Retell to try retries or route to voicemail.
How dynamic variables feed into agent selection logic
Dynamic variables carry the decision context: caller language, lead score, account tier, local time, etc. Your webhook either receives these variables in the inbound payload or computes/fetches them from external systems and returns them to Retell. The agent selection logic reads these variables and maps them to agent IDs, templates, and behavior modifiers.
Anatomy of the Inbound Call Webhook Payload
Familiarity with the payload fields ensures you know where to find crucial routing data.
Typical JSON structure received by your webhook endpoint
Retell sends a JSON object that usually includes call identifiers, timestamps, caller and callee info, and metadata. A simplified example looks like: { “call_id”: “abc123”, “timestamp”: “2025-01-01T14:30:00Z”, “caller”: { “number”: “+15551234567”, “name”: null }, “callee”: { “number”: “+15557654321” }, “metadata”: { “crm_contact_id”: “c_789”, “campaign”: “spring_launch” } } You’ll parse this payload to extract the fields you need for routing.
Important fields to read: caller, callee, timestamp, metadata
The caller.number is your primary key for CRM lookups and geolocation. The callee.number tells you which of your numbers was dialed if you own multiple lines. Timestamp is critical for time-based routing. Metadata often contains Retell-forwarded context, like the source campaign or previously stored dynamic variables.
Where dynamic variables appear in the payload
Retell includes dynamic variables under a metadata or dynamic_variables key (naming may vary). These are prepopulated by previous steps in your flow or by the dialing source. Your webhook should inspect these and may augment or override them before returning your response.
Custom metadata and how Retell forwards it
If your telephony provider or CRM adds custom tags, Retell will forward them in metadata. That allows you to carry contextual info — like salesperson ID or campaign tags — from the dialing source through to your routing logic. Use these tags for more nuanced agent selection.
Configuring Your Webhook Endpoint
Practical requirements and response expectations for your endpoint.
Required endpoint characteristics (HTTPS, reachable public URL)
Your endpoint must be a publicly reachable HTTPS URL with a valid certificate. Retell needs to POST data to it in real time, so it must be reachable from the public internet and respond timely. Local testing can be done with tunneling tools, but production endpoints should be resilient and hosted with redundancy.
Expected request headers and content types
Retell will typically send application/json content with headers indicating signature or authentication metadata (for example X-Retell-Signature or X-Retell-Timestamp). Inspect headers for authentication and use standard JSON parsing to handle the body.
How to respond to Retell to continue or terminate flow
Your response instructs Retell what to do next. To continue the flow, return a JSON object that includes the selected agent_id, template_id, and any dynamic_variables you want applied. To terminate or transfer, return an action field indicating termination, voicemail, or transfer target. If you can’t decide, return a fallback agent or an explicit error. Retell expects clear action directives.
Recommended response patterns and status codes
Return HTTP 200 with a well-formed JSON body for successful routing decisions. Use 4xx codes for client-side issues (bad request, unauthorized) and 5xx for server errors. If you return non-2xx, Retell may retry or fall back to default behavior; document and test how your configuration handles retries. Include an action field in the 200 response to avoid ambiguity.
Local development options: tunneling with ngrok and similar tools
For development, use ngrok or similar tunneling services to expose your local server to Retell. That lets you iterate quickly and inspect incoming payloads. Remember to secure your dev endpoint with temporary secrets and disable public tunnels after testing.
Securing the Webhook
Security is essential — you’re handling PII and controlling call routing.
Authentication options: shared secret, HMAC signatures, IP allowlist
Common options include a shared secret used to sign payloads (HMAC), a signature header you validate, and IP allowlists at your firewall to accept requests only from Retell IPs. Use a combination: validate HMAC signatures and maintain an IP allowlist for defense-in-depth.
How to validate the signature and protect against replay attacks
Retell can include a timestamp header and an HMAC signature computed over the body and timestamp. You should compute your own HMAC using the shared secret and compare in constant time. To avoid replay, accept signatures only if the timestamp is within an acceptable window (for example, 60 seconds) and maintain a short-lived nonce cache to detect duplicates.
Transport security: TLS configuration and certificate recommendations
Use strong TLS (currently TLS 1.2 or 1.3) with certificates from a trusted CA. Disable weak ciphers and ensure your server supports OCSP stapling and modern security headers. Regularly test your TLS configuration against best-practice checks.
Rate-limiting, throttling, and handling abusive traffic
Implement rate-limiting to avoid being overwhelmed by bursts or malicious traffic. Return a 429 status for client-side throttling and consider exponential backoff on retries. For abusive traffic, block offending IPs and alert your security team.
Key rotation strategies and secure storage of secrets
Rotate shared secrets on a schedule (for example quarterly) and keep a migration window to support both old and new keys during transition. Store secrets in secure vaults or environment managers rather than code or plaintext. Log and audit key usage where possible.
Dynamic Variables: Concepts and Syntax
Dynamic variables are the glue between your data and agent behavior.
Definition and purpose of dynamic variables in Retell
Dynamic variables are runtime key/value pairs that you pass into templates and agents to customize their prompts, behavior, and decisions. They let you personalize greetings, change script branches, and tailor agent tone without creating separate agent configurations.
Supported variable types and data formats
Retell supports strings, numbers, booleans, timestamps, and nested JSON-like objects for complex data. Use consistent formats (ISO 8601 for timestamps, E.164 for phone numbers) to avoid parsing errors in templates and agent logic.
Variable naming conventions and scoping rules
Use clear, lowercase names with underscores (for example lead_score, caller_country). Keep scope in mind: some variables are global to the call session, while others are template-scoped. Avoid collisions by prefixing custom variables (e.g., crm_lead_score) if Retell reserves common names.
How to reference dynamic variables in templates and routing rules
In templates and routing rules you reference variables using the platform’s placeholder syntax (for example {}). Use variables to customize spoken text, conditional branches, and agent selection logic. Ensure you escape or validate values before injecting them into prompts to avoid unexpected behavior.
Precedence rules when multiple variables overlap
When a variable is defined in multiple places (payload metadata, webhook response, template defaults), Retell typically applies a precedence order: explicit webhook-returned variables override payload-supplied variables, which override template defaults. Understand and test these precedence rules so you know which value wins.
Using Dynamic Variables to Route Calls
Concrete examples of variable-driven routing.
Examples: routing by time of day using variables
Compute local time from timestamp and caller timezone, then set a variable like business_hours = true/false. Use that variable to choose agent A (during hours) or agent B (after hours), and pass a greeting_time variable to the script so the agent can say “Good afternoon” or “Good evening.”
Examples: routing by CRM status or lead score
After receiving the call, do a CRM lookup based on caller number and return variables such as lead_score and opportunity_stage. If lead_score > 80 return agent_id = “senior_sales” and dynamic_variables.crm_lead_score = 95; otherwise return agent_id = “standard_sales.” This direct mapping gives you fine control over escalation.
Examples: routing by caller country code or state
Parse caller.number to extract the country code and set dynamic_variables.caller_country = “US” or dynamic_variables.caller_state = “CA”. Route to a localized agent and pass a template variable to include region-specific compliance text or offers tailored to that geography.
Combining multiple variables to create complex routing rules
Create compound rules like: if business_hours AND lead_score > 70 AND caller_country == “US” route to senior_sales; else if business_hours AND lead_score > 70 route to standard_sales; else route to after_hours_handler. Your webhook evaluates these conditions and returns the corresponding agent and variables.
Fallbacks and default variable values for robust routing
Always provide defaults for critical variables (for example lead_score = 0, caller_country = “UNKNOWN”) so agents can handle missing data. Include fallback agents in your response to ensure calls aren’t dropped if downstream systems fail.
Templates and Setup in Retell AI
Templates translate variables and agent logic into conversational behavior.
How templates use dynamic variables to customize agent behavior
Templates contain prompts with placeholders that get filled by dynamic variables at runtime. For example, a template greeting might read “Hello {}, this is {} calling about your {}.” Variables let one template serve many contexts without duplication.
Creating reusable templates for common call flows
Design templates for common flows like lead qualification, appointment confirmation, and support triage. Keep templates modular and parameterized so you can reuse them across agents and campaigns. This reduces duplication and accelerates iteration.
Configuring agent behavior per template: prompts, voice, tone
Each template can specify the agent prompt, voice selection, speech rate, and tone. Use variables to fine-tune the pitch and script content for different audiences: friendly or formal, sales or support, concise or verbose.
Steps to deploy and test a template in Retell
Create the template, assign it to a test agent, and use staging numbers or ngrok endpoints to simulate inbound calls. Test edge cases (missing variables, long names, unexpected characters) and verify how the agent renders the filled prompts. Iterate until you’re satisfied, then promote the template to production.
Managing templates across environments (dev, staging, prod)
Maintain separate templates or version branches per environment. Use naming conventions and version metadata so you know which template is live where. Automate promotion from staging to production with CI/CD practices when possible, and test rollback procedures.
Conclusion
A concise wrap-up and next steps to get you production-ready.
Recap of key steps to implement inbound call webhook and dynamic variables
To implement this system: expose a secure HTTPS webhook, parse the inbound payload, enrich with CRM and contextual data, evaluate your routing rules, return an agent selection and dynamic variables, and test thoroughly across scenarios. Secure the webhook with signatures and rate-limiting and plan for fallbacks.
Final best practice checklist before going live
Before going live, verify: HTTPS with strong TLS, signature verification implemented, replay protection enabled, fallback agent configured, template defaults set, CRM lookups performant, retry behavior tested, rate limits applied, and monitoring/alerting in place for errors and latency.
Next steps for further customization and optimization
After launch, iterate on prompts and routing logic based on call outcomes and analytics. Add more granular variables (customer lifetime value, product preferences). Introduce A/B testing of templates and collect agent performance metrics to optimize routing. Automate key rotation and integrate monitoring dashboards.
Pointers to Retell AI documentation and community resources
Consult the Retell AI documentation for exact payload formats, header names, and template syntax. Engage with the community and support channels provided by Retell to share patterns, get examples, and learn best practices from other users. These resources will speed your implementation and help you solve edge cases efficiently.
You’re now equipped to design an inbound call webhook that uses dynamic variables to select agents intelligently and securely. Start with simple rules, test thoroughly, and iterate — you’ll be routing calls with precision and personalization in no time.
If you want to implement Chat and Voice Agents into your business to reduce missed calls, book more appointments, save time, and make more revenue, book a discovery call here: https://brand.eliteaienterprises.com/widget/bookings/elite-ai-30-min-demo-call
