Send custom data in response of tool call and use ...
# support
d
I am creating a job scheduler in vapi for that I have created two apis (createJob and scheduleJob). I want to send job_id in the response of createJob tool alongwith toolCallId and result. Is it possible if yes, then how can i use that job_id in scheduleJob tool request later. https://cdn.discordapp.com/attachments/1280481026396913685/1280481027743289344/Screenshot_2024-09-03_161308.png?ex=66d83c63&is=66d6eae3&hm=e45a4902ca6e4e8ec0ac9b150525a2e95a1ab604f9fe6e8cc9427664ea1226f3&
v
@devMax Absolutely, you can include additional information such as
job_id
in the response of your
createJob
tool. When your server processes the
createJob
request, it should generate a
job_id
and include it in the response like this:
Copy code
json
{
    "results": [
        {
            "toolCallId": "X",
            "result": "Job created successfully",
            "job_id": "generatedJobId123"
        }
    ]
}
To use the
job_id
in the
scheduleJob
tool request, you would need to capture the
job_id
from the response of the
createJob
tool and then pass it as a parameter when calling the
scheduleJob
tool. Here's how you could do it: 1. Call the
createJob
tool and wait for the response. 2. Extract the
job_id
from the response. 3. Use the extracted
job_id
as a parameter when making the
scheduleJob
tool request. If you need to perform these actions programmatically within VAPI, you would typically have some logic in your application that handles the response from
createJob
and then uses the
job_id
in subsequent API calls. If you're looking to automate this process within VAPI itself, you would need to have a mechanism to store the
job_id
and retrieve it when needed for the
scheduleJob
call. If you have any specific implementation questions or need assistance with the code, please let me know, and I'd be happy to help further!
You can continue this conversation by mentioning me in the message.
d
can you please specify the way, i can extract that job_id in vapi and use it in later request
can you please specify the way, i can extract that job_id in vapi and use it in later request
v
@devMax Certainly! To extract the
job_id
from the response of the
createJob
tool and use it in a subsequent
scheduleJob
tool request within VAPI, you would typically follow these steps: 1. Call the
createJob
Tool:
- Make a request to the
createJob
tool and receive the response. 2. Extract the `job_id`: - Parse the response to find the
job_id
that was returned. This would usually involve handling the JSON response and extracting the value associated with the
job_id
key. 3. Store the `job_id`: - Temporarily store the
job_id
in a variable or a session if your VAPI environment supports it. 4. Call the
scheduleJob
Tool with the `job_id`:
- When making the request to the
scheduleJob
tool, include the
job_id
you extracted earlier as a parameter in the request. Here's a conceptual example of how you might handle this in code:
Copy code
javascript
// Example in JavaScript-like pseudocode

// Step 1: Call the createJob tool
createJob(parameters, function(createJobResponse) {
    // Step 2: Extract the job_id from the createJob response
    var jobId = createJobResponse.job_id;

    // Step 3: Store the job_id (this step may vary based on your environment)

    // Step 4: Call the scheduleJob tool with the job_id
    scheduleJob({ job_id: jobId }, function(scheduleJobResponse) {
        // Handle the response from the scheduleJob tool
    });
});
Since VAPI is an API, the actual implementation details will depend on the programming language and environment you're using to interact with VAPI. If you're using a server-side language like Python, JavaScript (Node.js), Ruby, etc., you would use the respective HTTP client libraries to make these API calls and handle the responses. If you need more specific guidance on how to implement this in your environment or if you're facing any issues, please provide more details about your setup, and I'll be happy to assist you further.
d
I want to schedule job independent of create job, there may be some jobs which is not scheduled to can i do that
v
@devMax Yes, you can certainly design your job creation and scheduling APIs to operate independently. This means you can create jobs without immediately scheduling them, and you can schedule jobs at a later time, separate from the job creation process. Here's how you can manage this: 1. Create Job: - Use the
createJob
API to create a new job. This API should return a
job_id
that uniquely identifies the job. 2. Store Job ID: - Store the
job_id
in a database or any persistent storage. This allows you to keep track of all created jobs, whether they are scheduled or not. 3. Schedule Job: - When you are ready to schedule a job, you can use the
scheduleJob
API. Provide the
job_id
of the job you want to schedule as a parameter to this API. 4. Retrieve Job ID: - To schedule a job that was created earlier, retrieve the
job_id
from your storage system. 5. Make the Schedule Job Request: - With the
job_id
retrieved, make a request to the
scheduleJob
API to schedule the job for execution. By keeping the job creation and scheduling processes separate, you have the flexibility to schedule jobs at any time after they have been created. This approach also allows you to manage jobs that may never be scheduled or that require special handling before scheduling. Remember to implement appropriate error handling and checks in your
scheduleJob
API to ensure that only valid, existing job IDs can be scheduled. This will prevent scheduling non-existent or already completed jobs. If you need further assistance with the implementation or have more questions about the process, feel free to ask!
d
how can i do it vapi iteself is it possible to do it using prompt
how can i do it vapi iteself is it possible to do it using prompt
v
@devMax In VAPI, if you want to schedule a job independently of creating a job, you would typically manage this through your application logic. However, if you're looking to handle this within VAPI using prompts, you would need to ensure that the
job_id
is stored and accessible for later use when you're ready to schedule the job. Here's a conceptual workflow on how you might achieve this: 1. Create Job: - Prompt the user to create a job using the
createJob
tool. - Once the job is created, the
createJob
tool should return a
job_id
. 2. Store Job ID: - You would need to store the
job_id
in a persistent storage system that your VAPI can access later. This could be a database or any other form of storage you have set up. 3. Schedule Job: - When you're ready to schedule a job, prompt the user to provide the
job_id
of the job they wish to schedule. - If the user doesn't have the
job_id
handy, you might need to implement a way for them to retrieve or list all unscheduled jobs to select from. 4. Call Schedule Job Tool: - Use the provided
job_id
to call the
scheduleJob
tool. Since VAPI itself doesn't maintain state or store data between calls, you would need to handle the storage and retrieval of
job_id
outside of VAPI. Your application logic would be responsible for managing the flow of data and ensuring that the correct
job_id
is used when scheduling jobs. If you're looking for a way to automate this process entirely within VAPI without any external application logic, that would not be possible since VAPI is designed to handle stateless API calls. You would need to implement the logic in your application that interacts with VAPI. If you have a specific scenario or setup in mind, please provide more details, and I can give you a more tailored response.
s
you have to map tool call result to a variable and then later used the mapped variable to send input parameter to the tool call.
d
Can I do it through the prompt, something like: Call the createJob tool and store the job_id from the reponse. Call the scheduleJob toll and send job_id from the createJob reponse in its request.
s
3 Views