dynamic variable
# support
e
i created a function and hosted it, now i want to call it using the get request, in my case i have a variable named name that contains name of ppl; i want to pass this dynamic variable to the url get request when i have a name x i call it with this https://function.modal.run?data=x now i want to pass the variable, how? the function takes a name and store it in a file. i got the name from the user speech
v
Hi @ema, I'm an AI assistant for Vapi. I'll analyze available sources and get back to you shortly.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Get Call]() * [Dynamic Variables]() * [Server URLs]() * [Tools Calling]() -----------------------------
d integration with external functions, especially through setting server URLs and handling function calls [(2)]() [(3)]() , you would typically pass such dynamic data within the context of these interactions rather than directly manipulating the GET request URL within the Vapi platform. For calling a hosted function with dynamic parameters obtained from speech, consider using Vapi's server URL or function calling capabilities to interact with your external service, passing the "name" as part of the payload in a POST request instead of directly appending it to a GET request URL. Remember to review Vapi's documentation on dynamic variables [(1)]() , server URLs [(2)]() , and possibly function calling [(3)]() for more detailed guidance tailored to your specific use case.
### Answer To pass a dynamic variable, such as a name obtained from user speech, to your hosted function via a GET request in Vapi, you can utilize the concept of dynamic variables in your assistant's setup. While the direct manipulation of URLs to include dynamic variables in the form of GET request parameters isn't explicitly detailed in the Vapi documentation, you can use dynamic variables within Vapi to personalize the assistant's messages or actions based on user input or context from the conversation [(1)]() . In your case, you aim to send the "name" obtained from user speech to your function. Assuming you're capturing this "name" during the conversation and want to pass it as a parameter to your function, you should first ensure that your assistant is designed to capture and store such variables. This can be achieved by incorporating the dynamic variable functionality during the assistant setup. Here's an abstract example of how you might structure your assistant to use dynamic variables: 1. Define a variable in your assistant's message or action where the "name" is captured. 2. Use the captured "name" in the subsequent API call as part of the assistant’s logic to call your function. While the Vapi documentation doesn't provide a direct example of modifying a GET request URL with dynamic variables, the closest related feature is dynamic variables in assistant interactions. These allow customization of messages based on variables like the current time or user-specific details, which are set programmatically. Given this information, to achieve your goal, you would: 1. Capture the "name" within the Vapi assistant conversation flow. 2. Use the captured "name" as a dynamic variable to customize the next steps in your flow, such as calling a function or sending a message. Since Vapi allows for customization an
e
and if i have a post request with https://function.modal.run/? with "curl -X POST -H 'Content-Type: application/json' --data-binary '{"data": "x"}'" how can i put this into the url server in the function i defined
v
Thanks for the follow-up, @ema. I'll get back to you soon.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Outbound Calls from Python]() * [Create Assistant]() * [Create Phone Call]() * [Tools Calling]() -----------------------------
### Answer To integrate a POST request with dynamic data into your Vapi server URL or in a function call, you would typically structure your application to handle incoming requests and extract the necessary information from the payload. However, the direct execution of a
curl
command or the inclusion of
curl
syntax within the Vapi server URL or function setup is not directly supported or mentioned within the provided documentation. For executing a POST request that includes JSON data (like
{"data": "x"}
) from within Vapi to an external URL or service, you should design your function to accept JSON payloads and then extract the data server-side. When calling this function from within Vapi, you would use the function calling or server URL mechanism to trigger this request, passing along any necessary parameters as part of the request body. Given the requirement to send data to
https://function.modal.run/?
with a JSON payload, you would: 1. Define a function or set up a server URL in Vapi that is triggered during a conversation or upon a specific event. 2. Ensure your external function/service is capable of handling POST requests and extracting the JSON payload. 3. Within Vapi, use the assistant or workflow setup to make a POST request to your external URL, passing parameters as needed. Remember, the specifics of how you configure the assistant to make a POST request to your function would depend on the details of your Vapi setup and how you've designed your external function to process incoming requests. If you're looking for a way to programmatically construct and send these requests based on dynamic user input (like a name), consider utilizing Vapi's capabilities for function calling with dynamic variables that can be captured during a conversation. Due to the lack of direct examples in the provided documentation about embedding a
curl
command or its
equivalent directly within Vapi, it's advised to consult the official Vapi documentation or support resources for guidance on integrating external HTTP requests within your Vapi application.
m
Use string interpolation or concatenation in your code to construct the URL dynamically based on the variable's value.
let name = "Alice"; // This variable is dynamic let url = `https://function.modal.run/?data=${name}`; // Now you can use the url to make the GET request
for a post you'll want to send the data in the body of the request
e
but how can i put the name Alice into the variable, the name is extracted from the user when he is talking
the variable is dynamic, it takes the name of the user
m
Make a function that grabs the speakers name once the model asks for it, sends it to your server, on your server assign whatever it received to x and then do whatever you want with it after
Let me know if you'd like more specific code examples
e
can you give me a n example
yes please
for the function that take the name of the speaker, i guess it does need to be coded? is it just by creating a function and give it a property named name, and in the prompt i specify that when the user say his name, call that function?
how to control the assistant using json files from an editor?
v
Thanks for the follow-up, @ema. I'll get back to you soon.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Get Call]() * [Create Assistant]() * [Server Events]() * [Connecting Your Custom LLM to Vapi: A Comprehensive Guide]() -----------------------------
### Answer Sorry, I wasn't able to find any information about your question. You can get more help at [Contact Us](support@vapi.ai)
s
@ema you still need any help?
e
yes, i see in the documentation some json files, i still do not know how to use them
s
can you point me to that doc?
e
i have a custom funtion hosted and i use its url in the dashboard, but the problem is i still blocked to implement a function that will set the name of the speaker in a variable and then give this variable to the get request
s
First of all, during a custom function call only post request is given and you just need to follow this pattern given in the doc
I will send you my implementation of tool-calling
Copy code
json
"tools": [
            {
                "type": "function",
                "async": false,
                "server": {
                    "url": "Your Webhook URL"
                },
                "function": {
                    "name": "get_current_time",
                    "parameters": {
                        "type": "object",
                        "properties": {}
                    },
                    "description": "Provide the current time."
                },
                "messages": [
                    {
                        "type": "request-response-delayed",
                        "content": "It is taking a little longer time to get the content please wait."
                    },
                    {
                        "type": "request-start",
                        "content": "Making an HTTP Request Please Wait"
                    },
                    {
                        "type": "request-complete",
                        "content": "Here is the Response Sir"
                    },
                    {
                        "type": "request-failed",
                        "content": "Something went wrong."
                    }
                ]
            }
        ]
e
meaning i can't make it as : https://function.modal.run/?data=x
s
Nope.
e
okay, so i have to just put the url without sending data in it. so i have a variable defined in the function in the dashboard and i want it to get the name of the speaker then runnig the url with this data
s
create a custom function and pass the name in body
e
how can i use that exactly?
the name is said by the user, it's dynamic
s
Please watch some video tutorial https://docs.vapi.ai/community/videos
e
Hi, i already done the serveless function i have a code right now like this import requests url = 'https://function/' data = {'nom': 'X Y'} response = requests.post(url, json=data) print(response.status_code) print(response.json()) how can i run it into vapi
v
Please tag me in threads that I was a part of from the start.
e
.
v
Please tag me in threads that I was a part of from the start.
e
@Vapi Support
v
Please tag me in threads that I was a part of from the start.