https://retellai.com/?utm_source=discord&utm_medium=seo logo
can i create my own custom widget which uses a cha...
# ❓・ai-evy-support
e
@AI Evy can i create my own custom widget which uses a chat agent via an API?
a
Thanks for tagging me @Elders. I'll look through relevant sources and get back to you shortly.
### Answer Yes, you can create your own custom widget that uses a chat agent via the API. [(1) ]() [(2) ]() To create a chat session, you can use the Create Chat API endpoint. [(1) ]() Here's how it works:
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const chatResponse = await client.chat.create({ agent_id: 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD' }) ;
console.log(chatResponse.agent_id) ;
You'll first need to create a chat agent using the Create Chat Agent API. [(2) ]() The chat agent requires a response engine to be attached, which generates responses for the agent. The Create Chat API returns a chat object that includes details like
chat_id
,
agent_id
,
chat_status
, and other relevant information you can use in your custom widget. [(1) ]()
​ To learn more, see the sources I considered: [[1] Create Chat](https://docs.retellai.com/api-references/create-chat) [[2] Create Chat Agent](https://docs.retellai.com/api-references/create-chat-agent) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
e
@AI Evy where can I declare a dynamic vairable from my inbound webhook so that I can check what the customer's name is and use it in the greeting if its available?
a
Thanks for the follow-up, @Elders. I'll get back to you soon.
### Answer To declare dynamic variables from your inbound webhook for a chat agent, you need to return them in your webhook response under the
call_inbound
object with a
dynamic_variables
key. [(1) ]() [(2) ]() Your webhook response should look like this:
Copy code
json
{
  "call_inbound": {
    "dynamic_variables": {
      "customer_name": "John Doe",
      "user_email": "john@example.com"
    }
  }
}
Once you've set up your webhook to return dynamic variables this way, you can use them in your agent's prompt or begin message with the
{{variable_name}}
syntax. [(3) ]() For example, to greet the customer by name if available, you could use:
Copy code
Hello {{customer_name}}, thanks for reaching out!
If the customer name is not known, you can handle this in your webhook by returning an empty string or a default value, and then structure your prompt to check for this condition. [(4) ]() For example:
Copy code
Variable: 
Name: {{customer_name}}

Always say "Hello {{customer_name}}, nice of you to call, how can I help you?", if known.

If Name is empty: "Hello, I am your digital assistant. How can I help you?"
The inbound webhook should be configured at the phone number level in your dashboard or via the API. [(1) ]() [(2) ]()
​ To learn more, see the sources I considered: [[1] Inbound webhook](https://docs.retellai.com/features/inbound-call-webhook) [[2] Inbound webhook returns retell_llm_dynamic_variables but agent doesn't receive them](https://community.retellai.com/t/inbound-webhook-returns-retell-llm-dynamic-variables-but-agent-doesnt-receive-them/733) [[3] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[4] The agent does not address me personally by my name.](https://discord.com/channels/1186424376300679209/1317581097848274965) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.