time aware assistant
# support
j
What is the best way to create a workflow or squad that is aware of time? I want to respond with Assistant A over weekends, with an automated message that the office is closed, and Assistant B at other times. I added "The current date and time is {{"now" | date: "%b %d, %Y, %I:%M %p", "Australia/Melbourne"}}" and system prompts to check against office hours. That seems to work in isolation, but I am not sure how to tie everything together.
f
I experience a similar issue where Vapi agent is able to contextually recognise time through {{now}}, but through conversation will schedule appointments on dates which dont exist (i.e. if today is Monday, 17th March the LLM will attempt to book a meeting for Tuesday the 20th of March)
b
You need to make a transient assistant and use automation platform (make, n8n) logic to return assistant A or B depending on the time.
k
Hey JacqBot, you need to assign a server URL to your phone number. Then, Vapi will make an assistant-request to your server URL, requesting the assistant at that time. You can return the assistant based on the datetime for working or non-working hours.
detailed-expl.
To have different assistants handle calls during business hours versus after hours/weekends, you'll need to: 1\. Create two assistants: - Business Hours Assistant - After Hours Assistant 2\. Set up a server endpoint that will determine which assistant to use based on the current time 3\. Configure your phone number to use this server URL
s
[Step-by-Step Implementation] 1. Create Your Server Endpoint Create an endpoint (e.g., /assistant-request) that returns the appropriate assistant based on the time:
Copy code
js

import express from 'express';

const app = express();

app.use(express.json());

const BUSINESS_HOURS = {

  timezone: 'Australia/Melbourne',

  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 melbourne = new Intl.DateTimeFormat('en-US', {

    timeZone: BUSINESS_HOURS.timezone,

    hour: 'numeric',

    minute: 'numeric',

    weekday: 'long',

    hour12: false

  });

  

  const localDateTime = melbourne.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');

});
2. Configure Your Phone Number In the Vapi dashboard: 1. Go to Phone Numbers 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 Now, when someone calls: - During business hours (9 AM - 5 PM Melbourne time, weekdays), they'll get your business hours assistant - Outside business hours or on weekends, they'll get your after-hours assistant
j
great thanks,. I will test this out
thanks @Shubham Bajaj @Bryce the solution works 100%.
3 Views