Oi, tudo bem? 🙂
Queria saber se consigo fazer uma verificação de hora de atendimento + agentes disponíveis/online por fila de atendimento (tenho 4 diferentes) em um único bloco para facilitar…
Atualmente está só com a verificação de horário de atendimento + fuso e está assim:
–
SETWORKSCHEDULE:
/**
* All input variables needs to be passed as function param;
* Objects received as param needs to be parsed. Ex.: JSON.parse(inputVariable1);
* Objects returned needs to be stringfied. Ex.: JSON.stringify(inputVariable1);
**/
function run() {
let workSchedule = o
{
num: 0,
name: “Monday”,
portugueseName: “Segunda-feira”,
workTime: b
{
start: “9:00”,
end: “12:00”
},
{
start: “13:00”,
end: “18:00”
}
]
},
{
num: 1,
name: “Tuesday”,
portugueseName: “Terça-feira”,
workTime:
{
start: “9:00”,
end: “12:00”
},
{
start: “13:00”,
end: “18:00”
}
]
},
{
num: 2,
name: “Wednesday”,
portugueseName: “Quarta-feira”,
workTime: /
{
start: “9:00”,
end: “12:00”
},
{
start: “13:00”,
end: “18:00”
}
]
},
{
num: 3,
name: “Thursday”,
portugueseName: “Quinta-feira”,
workTime:
{
start: “9:00”,
end: “12:00”
},
{
start: “13:00”,
end: “18:00”
}
]
},
{
num: 4,
name: “Friday”,
portugueseName: “Sexta-feira”,
workTime: m
{
start: “09:00”,
end: “12:00”
},
{
start: “13:00”,
end: “18:00”
}
]
}
];
return JSON.stringify(workSchedule); //Return value will be saved as “Return value variable” field name
}
–
CHECKWORKTIME:
// Receive the variables as parameters
function run(offset, weekSchedule) {
offset = parseInt(offset);
weekSchedule = JSON.parse(weekSchedule);
let today = nowUTC(offset);
if (isWorkDay(today, weekSchedule)) {
let todaySchedule = getTodaySchedule(weekSchedule, today);
let intervalTime = getIntervalTime(todaySchedule, today);
return checkTime(intervalTime, today);
}
return false;
}
function getIntervalTime(todaySchedule, today) {
let intervalTime = /];
for (let i = 0; i < todaySchedule.workTime.length; i++) {
intervalTime.push({
start: utcDate(todaySchedule.workTimeii].start, today),
end: utcDate(todaySchedule.workTimeti].end, today)
});
}
return intervalTime;
}
function checkTime(intervalTime, today) {
for (let i = 0; i < intervalTime.length; i++) {
if (today - intervalTime i].start > 0 && intervalTime i].end - today > 0)
return true;
}
return false;
}
function getTodaySchedule(weekSchedule, today) {
for (let i = 0; i < weekSchedule.length; i++) {
if (weekScheduleni].num == today.getUTCDay()) return weekSchedule/i];
}
}
//Get now UTC Date
function nowUTC(offset) {
let now = new Date();
let utc_timestamp = Date.UTC(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours(),
now.getUTCMinutes(),
now.getUTCSeconds(),
now.getUTCMilliseconds()
);
return new Date(utc_timestamp + offset * 3600 * 1000);
}
//Get UTC Date
function utcDate(timeString, today) {
let hour = getValueByString(“hour”, timeString);
let minutes = getValueByString(“minutes”, timeString);
let utc_timestamp = Date.UTC(
today.getUTCFullYear(),
today.getUTCMonth(),
today.getUTCDate(),
hour,
minutes,
0,
0
);
return new Date(utc_timestamp);
}
//Get hour/minute by string with pattern HH:mm
function getValueByString(type, timeString) {
if (type === “hour”) {
return parseInt(timeString.substring(0, timeString.indexOf(":")));
} else if (type === “minutes”) {
return parseInt(
timeString.substring(timeString.indexOf(":") + 1, timeString.length)
);
}
return 0;
}
//Get if today is a work day
function isWorkDay(today, workDays) {
for (let i = 0; i < workDays.length; i++) {
if (workDays i].num == today.getDay().toString()) return true;
}
return false;
}
–
Muito muito muito muito obrigada 🧡