Integration with existing usa number that only han...
# support
t
I want to build a system where in office hour human assistant answer calls and after office hours, when a user calls, it automatically transferred to vapi assistant to handle. Can anyone provide details how can I do that @Vapi
v
Hi there! 👋 I'd be happy to help you set up a system where calls are handled by human assistants during office hours and automatically transferred to a Vapi assistant after hours. Here's how you can build this system: ## 1. Create Two Assistants First, you'll need to create two different assistants: - A Business Hours Assistant (configured for human handling) - An After Hours Assistant (Vapi AI assistant) ## 2. Set Up a Server Endpoint for Time-Based Routing You'll need to create a server endpoint that determines which assistant to use based on the current time. Here's an example using JavaScript and Express:
Copy code
javascript
import express from 'express';

const app = express();
app.use(express.json());

const BUSINESS_HOURS = {
  timezone: 'America/New_York', // Change to your timezone
  weekdayStart: '09:00',
  weekdayEnd: '17:00',
  weekdayAssistantId: 'your-business-hours-assistant-id',
  weekendAssistantId: 'your-after-hours-assistant-id'
};

function isBusinessHours() {
  const now = new Date();
  const localTime = new Intl.DateTimeFormat('en-US', {
    timeZone: BUSINESS_HOURS.timezone,
    hour: 'numeric',
    minute: 'numeric',
    weekday: 'long',
    hour12: false
  });

  const localDateTime = localTime.format(now);
  const isWeekend = localDateTime.includes('Saturday') || localDateTime.includes('Sunday');

  if (isWeekend) return false;

  const currentTime = localDateTime.split(', ')[1];
  return currentTime >= BUSINESS_HOURS.weekdayStart && currentTime <= BUSINESS_HOURS.weekdayEnd;
}

app.post('/assistant-request', (req, res) => {
  const response = {
    assistantId: isBusinessHours()
      ? BUSINESS_HOURS.weekdayAssistantId
      : BUSINESS_HOURS.weekendAssistantId
  };

  res.json(response);
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});
This code checks if the current time is within business hours and returns the appropriate assistant ID based on that determination. [Source](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341224148667600976) ## 3. Configure Your Phone Number in Vapi Next, you'll need to configure your phone number in the Vapi dashboard: 1. Go to Phone Numbers in the Vapi dashboard 2. Select your phone number 3. Set the Server URL to your endpoint (e.g.,
https://your-domain.com/assistant-request
) 4. Remove any default assistant/squad assignment This configuration tells Vapi to check with your server to determine which assistant should handle each incoming call. [Source](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341224148667600976) ## 4. Import Your Existing USA Phone Number If you haven't already, you'll need to import your existing USA phone number into Vapi: - You can import phone numbers via the dashboard by navigating to the "Phone Numbers" section and clicking the "Import" button - For providers like Twilio, you'll need to input your Account SID and Auth Token - Alternatively, you can use the
/phone-numbers/import
endpoint [Source](https://docs.vapi.ai/quickstart/phone/inbound) With this setup, when someone calls: - During business hours: They'll be connected to your human assistant - Outside business hours or on weekends: They'll automatically be handled by your Vapi assistant Is there anything specific about this setup you'd like me to explain in more detail? Sources: - [Discord Thread on Time-Based Routing](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341224148667600976) - [Vapi Quickstart Guide for Inbound Calls](https://docs.vapi.ai/quickstart/phone/inbound) - [Discord Thread on Importing Phone Numbers](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1334941334368419850)
v
First, you have to check if your telephony supports this. Whenever a call comes in during office hours, it will be forwarded or taken or controlled by a human. When it is outside office hours, it should be forwarded to the VAPI. Now, the process or the logic of getting this in chat is only possible and handled by your telephony, so you have to check out with them. It's not something which you can do through VAPI.
5 Views