//https://roomos.cisco.com/doc/TechDocs/MacroTutorial#scheduling import xapi from 'xapi'; var On = "On"; xapi.Config.Macros.AutoStart .set(On); function schedule(time, action) { let [alarmH, alarmM] = time.split(':'); let now = new Date(); now = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds(); let difference = parseInt(alarmH) * 3600 + parseInt(alarmM) * 60 - now; if (difference <= 0) difference += 24 * 3600; return setTimeout(action, difference * 1000); } //https://github.com/CiscoDevNet/roomdevices-macros-samples/blob/master/Library%20-%20Send%20Webex%20Message/README.md const webexMsgUrl = "https://webexapis.com/v1/messages"; function sendMessage(token, toPersonEmail, roomId, markdown) { const headers = [ "Content-Type: application/json", "Authorization: Bearer " + token, ]; const body = Object.assign({ markdown }, toPersonEmail ? { toPersonEmail } : { roomId }); return xapi.Command.HttpClient.Post({ Header: headers, Url: webexMsgUrl }, JSON.stringify(body)); } const token = //yourToken; const Friday = 5; //sunday=0;monday=1;tuesday=2;wednesday=3;thursday=4;friday=5;saturday=6 const rebootTime = "21:00"; function reboot() { const weekDay = new Date().getDay(); var Restart = "Restart"; if (weekDay == Friday) { sendMessage(token, "matteo.battista@eventitelematici.com", null, "[Cisco] OK1 | Rebooting"); xapi.Command.SystemUnit.Boot( { Action: Restart, Force: true }); } schedule(rebootTime, reboot); } schedule(rebootTime, reboot);