https://retellai.com/?utm_source=discord&utm_medium=seo logo
Is there a way to initiate a live chat via the jav...
# ❓・ai-evy-support
c
@AI Evy Is there a way to initiate a live chat via the javascript and giving it context about why the conversation might've started? Currently somebody messages in, we tell them to talk to us on live chat.
a
Thanks for tagging me @Ciaran. I'll look through relevant sources and get back to you shortly.
### Answer The sources here cover web calls (voice, using the Web SDK) rather than a text-based live chat widget [(1) ]() . For web calls, you can pass context when creating the call using
retell_llm_dynamic_variables
, which are string key-value pairs injected into the agent's prompt and tool descriptions [(1) ]() [(2) ]() :
Copy code
javascript
import { RetellClient } from "retell-client-js-sdk";
const client = new RetellClient({ key: "public_key_YOUR_PUBLIC_KEY" }) ;
let call;
function startCall() {
 if (call && call.status !== "ended") return;
 call = client.createWebCall({
 agent_id: "agent_oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD",
 retell_llm_dynamic_variables: { customer_name: "John Doe" },
 metadata: { internal_customer_id: "cust_123" },
 hooks: {
 onStatus: (status) => console.log("Call status:", status) ,
 onEnd: () => console.log("Call ended") ,
 onError: (error) => console.error("Call error:", error) ,
 },
 }) ;
}
​ To learn more, see the sources I considered: [[1] Make a web call](https://docs.retellai.com/deploy/web-call) [[2] Dynamic variables](https://docs.retellai.com/build/dynamic-variables) [[3] Text conversation with Retell agent](https://discord.com/channels/1186424376300679209/1250561381325869076) ​
[(1) ]() You'd use
retell_llm_dynamic_variables
for values the agent should reference in the conversation (e.g., why the customer is reaching out) , and
metadata
for values you only need to look up later . These variables can then be referenced in the agent's prompt or opening message using
{{variable_name}}
syntax [(2) ]() . However, based on a Discord discussion in the sources, fully text-based (chat) conversations with agents were, as of that discussion, not something Retell supported — this was raised as a feature request, with no confirmed timeline for multi-channel (text and voice) agent support [(3) ]() . So if by "live chat" you mean a text-chat widget specifically (rather than a web voice call) , the sources don't confirm this is currently available; the
createWebCall()
method documented is for browser-based voice calls [(1) ]() . If you meant initiating a web call (voice) with context, the code above applies. If you specifically need text-based chat, I don't have documentation confirming that capability exists.
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
c
@AI Evy This is for live chat... What I was thinking was setting a variable and then maybe giving the agent context about the {{reason_for_chat}} or something?
a
Thanks for the follow-up, @Ciaran. I'll get back to you soon.
​ To learn more, see the sources I considered: [[1] Dynamic variables](https://docs.retellai.com/build/dynamic-variables) [[2] Dynamic Variable in chat is going unrecognized](https://discord.com/channels/1186424376300679209/1467628427434524966) [[3] Dynamic Variables](https://discord.com/channels/1186424376300679209/1340177140204699649) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
### Answer Yes, that approach works. When creating a chat, pass
retell_llm_dynamic_variables
with a
reason_for_chat
key, and reference it as
{{reason_for_chat}}
in your agent's prompt or opening message [(1) ]() . For chats specifically, you pass
retell_llm_dynamic_variables
when creating a chat :
Copy code
Web calls and chats: Pass retell_llm_dynamic_variables when creating a web call or chat.
Make sure the variable name matches exactly what you reference in the prompt — this was flagged as a common issue [(2) ]() : > Make sure the variable name matches exactly when passed via retell_llm_dynamic_variables You must use double curly braces to reference the variable in the prompt; referencing it without
{{}}
won't work : > You must use the double curly braces are required. You cannot reference variables without them. If you want the agent to have this context but never say it out loud to the user, you'd write your prompt so it treats
{{reason_for_chat}}
as internal context, not something to repeat back — this pattern of using an internal-only variable was discussed with a similar "lead_type" variable, where the variable was kept internal and not shared with the user [(3) ]() : > Note that the lead type is internal, and I don't want the agent to share that information with the user. Worth noting: in that same discussion, there was an inconsistency where the agent picked up the internal variable correctly when it was also included in the welcome message, but not otherwise, even with prompt instructions referencing it directly. This wasn't clearly resolved in the thread . So it's worth testing that your
{{reason_for_chat}}
variable is actually being picked up by having it appear somewhere testable (like temporarily in the opening message) before relying on it purely in hidden prompt instructions.