https://retellai.com/?utm_source=discord&utm_medium=seo logo
Is there a way on a single prompt to have dynamic ...
# ❓・ai-evy-support
c
@AI Evy Is there a way on a single prompt to have dynamic introduction message based on dynamic variable i.e: If {{user_first_name}} is present then say Hi {{user_first_name}}, how are doing today? otherwise Hi, can I ask who is speaking?
a
Thanks for tagging me @Ciaran. I'll look through relevant sources and get back to you shortly.
### Answer Yes, you can handle conditional logic for dynamic variables directly in your prompt. When a dynamic variable has no assigned value, it remains in its raw form with the curly braces intact (e.g.,
{{user_first_name}}
) . [(1) ]() You can add conditional logic in your prompt like this:
Copy code
If {{user_first_name}} appears with curly braces, use a generic greeting.
Otherwise, greet the customer by name.
To check if a variable is set, you can also use the equation syntax in Conversation Flow conditions:
Copy code
Equation: {{user_name}} exists
Result: True if variable is set
For your specific use case, you could write something like this in your prompt:
Copy code
- If {{user_first_name}} appears with curly braces (meaning it's not set) , say: "Hi, can I ask who is speaking?"
- Otherwise, greet the user by saying: "Hi {{user_first_name}}, how are you doing today?"
This approach uses "defensive prompting" — designing prompts that work with or without variables.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
c
@AI Evy Is there no way to do this via a single prompt? I know you have the introduction message but if I put it in the single prompt box, it never actually says anything? This only other way is to maybe do something on call_inbound set {{introduction_message}} and have it dynamic?
a
Thanks for the follow-up, @Ciaran. I'll get back to you soon.
### Answer Yes, you're on the right track with the inbound webhook approach. For single prompt agents, the begin message field is separate from the prompt itself—putting conditional logic in the prompt box won't control the opening greeting. [(1) ]() For dynamic introduction messages, you can supply dynamic variables via the Inbound Call Webhook. This lets you set a variable like
{{introduction_message}}
at call start based on your logic. Here's how it works: 1. In your webhook response, you can dynamically set variables based on whether you have the caller's information:
Copy code
json
{
  "call_inbound": {
    "dynamic_variables": {
        "introduction_message": "Hi John, how are you doing today?"
    }
  }
}
[(2) ]() 2. Then use
{{introduction_message}}
in your begin message field. [(1) ]() 3. Your webhook logic determines whether to return a personalized greeting or a generic one before the call starts. The key limitation is that you cannot dynamically make the begin message field "not set" to have the AI generate its own opening—if you send null for a dynamic variable, it reads out the variable name. [(3) ]() So you'll need to explicitly set the full greeting text in your webhook response.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Dynamic Variables](https://discord.com/channels/1186424376300679209/1356680357084135558) [[3] Dynamic being_message using dynamic variables](https://discord.com/channels/1186424376300679209/1369082153131839558) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.