Lucas van Staden
10/19/2024, 2:20 PMVapi
10/19/2024, 2:23 PMVapi
10/19/2024, 2:23 PMLucas van Staden
10/19/2024, 2:42 PMLucas van Staden
10/19/2024, 2:49 PMChowderr
10/19/2024, 5:54 PMChowderr
10/19/2024, 5:56 PMLucas van Staden
10/19/2024, 10:23 PMChowderr
10/19/2024, 10:24 PMChowderr
10/19/2024, 10:25 PMLucas van Staden
10/19/2024, 10:28 PMLucas van Staden
10/19/2024, 10:29 PMLucas van Staden
10/19/2024, 10:30 PMLucas van Staden
10/19/2024, 10:30 PMChowderr
10/19/2024, 10:31 PMLucas van Staden
10/19/2024, 10:31 PMLucas van Staden
10/19/2024, 10:31 PMLucas van Staden
10/19/2024, 10:32 PMChowderr
10/19/2024, 10:32 PMLucas van Staden
10/19/2024, 10:32 PM"call": {
"id": "-----",
"orgId": "--------",
"createdAt": "2024-09-11T09:35:20.286Z",
"updatedAt": "2024-09-11T09:35:20.286Z",
"type": "inboundPhoneCall",
"status": "ringing",
"phoneCallProvider": "twilio",
"phoneCallProviderId": "------",
"phoneCallTransport": "pstn",
"phoneNumberId": "-----",
"assistantId": null,
"squadId": null,
"customer": {
"number": "+6149999999"
}
},
Then in tha ssistant request one can divert all tool cals to another server, geo located closer to the inbound call,
$assistant['serverUrl'] = 'https://webhooks.server.com.au'
or if it was a USA phoen number
$assistant['serverUrl'] = 'https://webhooks.server.com'
and all tools will divert from then on to a server geographically located closer to them.
This is to allow the API endponts, which also communicate with various other API's to get faster results as they will be geographically closer to the vapi tool end point servers.
This can shave literally 5/6 seconds off api endpoint times to result back.Lucas van Staden
10/19/2024, 10:35 PMLucas van Staden
10/19/2024, 10:37 PMLucas van Staden
10/19/2024, 10:37 PMLucas van Staden
10/19/2024, 10:44 PMChowderr
10/19/2024, 11:07 PMLucas van Staden
10/19/2024, 11:09 PMLucas van Staden
10/19/2024, 11:11 PMChowderr
10/19/2024, 11:11 PMLucas van Staden
10/19/2024, 11:12 PMLucas van Staden
10/19/2024, 11:15 PMChowderr
10/19/2024, 11:16 PMLucas van Staden
10/19/2024, 11:16 PMChowderr
10/19/2024, 11:17 PMLucas van Staden
10/19/2024, 11:17 PMChowderr
10/19/2024, 11:18 PMLucas van Staden
10/19/2024, 11:18 PMLucas van Staden
10/19/2024, 11:19 PMLucas van Staden
10/19/2024, 11:20 PMLucas van Staden
10/19/2024, 11:23 PMLucas van Staden
10/19/2024, 11:23 PMChowderr
10/19/2024, 11:29 PMChowderr
10/19/2024, 11:30 PMLucas van Staden
10/20/2024, 2:42 AMLucas van Staden
10/20/2024, 2:57 AM"message": {
"type": "tool-calls",
"toolCalls": [
{
"id": "call_kzqrDE43sJq5SGtFFRmfnVLU",
"type": "function",
"function": {
"name": "createPatient",
"arguments": {
"name" : "koos",
"surname" : "kombuis",
"email" : "koos@gmail.com",
"dateOfBirth": "1972-12-27"
}
}
}
],
"toolCallList": [
....
Lucas van Staden
10/20/2024, 2:57 AM$app->post('/', function () use ($app) {
$is_genuine = isset(request()->body()['message']['type']); // replace later with some security confirm for keywords.
if (!$is_genuine) {
response()->status(401)->plain('Signature verification failed!');
}
$type = request()->body()['message']['type'];
switch ($type) {
case "tool-calls":
handle_request();
break;
case 'assistant-request':
$clientName = '';
$functions = new Functions();
$cliniko = $functions->getCliniko();
$vapi = new Vapi();
$now = gmdate("Y-m-d H:i:s", time());
$assistant = $vapi->getAssistant($_ENV['assistant_id']);
$assistantCustom = [
'voice' => $_ENV['assistant_voice_id'],
'name' => $_ENV['assistant_name'],
];
....
Lucas van Staden
10/20/2024, 2:59 AMfunction handle_request()
{
foreach (request()->body()['message']['toolCalls'] as $callData) {
$function = $callData['function']['name'];
$id = $callData['id'];
Leaf\Config::set([
'log.file' => $callData['id'] . '_' . $function . '.log',
'log.dir' => __DIR__ . '/logs/' . request()->body()['message']['call']['customer']['number'] . '/'
]);
app()->logger()->info(request()->body());
if (function_exists($function)) {
$function();
} else {
response()->status(404);
exit;
}
}
}
so there is a PHP function that matches the tool name exact, and the dynamic call of $function() uses the tool name to effect the call to the function
so, you don't need to have a separate end-point for every tool. The tools can use the globally configured server-url as what can be set on ORG/Phone/Assistant
This way I can also divert all tool calls to different servers (which is what will be done) as the api endpoints they call are located around the world, and it speeds up the tool results significantly.
The clinical database that is accessed uses sharding to separate data dependant on clinic location. so, if the API server for tools is hosted in Australia, and the client clinic is in USA, the delay for api calls from AU->USA ads abount 2/3s delay.Lucas van Staden
10/20/2024, 3:00 AMLucas van Staden
10/20/2024, 3:01 AMLucas van Staden
10/20/2024, 3:03 AMLucas van Staden
10/20/2024, 3:06 AMLucas van Staden
10/20/2024, 3:07 AMShubham Bajaj
10/23/2024, 12:46 PM