2095281acf99cee0369388ffbb93d2bd88099381
[motion2.git] / server / services / routing / server / applications / gotoif.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xde9d=['../../../../config/logger','routing','string','number','priority\x20true\x20is\x20a\x20number','consequence','fromString','replace','length','error','[%s][GOTOIF]\x20%s','map','message','join','stop','priorityFalse','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','condition','next','findIndex','rules','info','validate','./utils'];(function(_0x52ef2d,_0x462c7d){var _0x1f48c3=function(_0x2f1d00){while(--_0x2f1d00){_0x52ef2d['push'](_0x52ef2d['shift']());}};_0x1f48c3(++_0x462c7d);}(_0xde9d,0x11e));var _0xdde9=function(_0x17d9e3,_0x1f969c){_0x17d9e3=_0x17d9e3-0x0;var _0x14192d=_0xde9d[_0x17d9e3];return _0x14192d;};'use strict';var schema=require(_0xdde9('0x0'));var _=require('lodash');var htmlToText=require('html-to-text');var utils=require(_0xdde9('0x1'));var logger=require(_0xdde9('0x2'))(_0xdde9('0x3'));var gotoif=schema({'condition':{'type':_0xdde9('0x4'),'required':!![],'message':'condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'priorityTrue':{'type':_0xdde9('0x5'),'message':_0xdde9('0x6')},'priorityFalse':{'type':_0xdde9('0x5'),'message':'priority\x20false\x20is\x20a\x20number'}});exports[_0xdde9('0x7')]=function(_0x14baf8,_0x5a6d3c){return function(_0xc89050){try{var _0x17b6b8={'condition':htmlToText[_0xdde9('0x8')](utils['getMustacheRender'](_0x5a6d3c[0x0],this),{'wordwrap':![]})[_0xdde9('0x9')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x5a6d3c[0x1],'priorityFalse':_0x5a6d3c[0x2]};var _0x466303=gotoif['validate'](_0x17b6b8,{'typecast':!![]});if(_0x466303[_0xdde9('0xa')]){logger[_0xdde9('0xb')](_0xdde9('0xc'),_0x14baf8,_[_0xdde9('0xd')](_0x466303,_0xdde9('0xe'))[_0xdde9('0xf')](',\x20'));_0xc89050[_0xdde9('0x10')]();}else{try{var _0x150887=eval('('+_0x17b6b8['condition']+')');var _0x547159=_0x150887?_0x17b6b8['priorityTrue']:_0x17b6b8[_0xdde9('0x11')];logger['info'](_0xdde9('0x12'),_0x14baf8,_0x17b6b8[_0xdde9('0x13')],_0x150887,_0x547159||_0xdde9('0x14'));if(_0x547159){var _0x4c51e6=_[_0xdde9('0x15')](_0xc89050[_0xdde9('0x16')](),{'p':_0x547159});if(_0x4c51e6>=0x0){logger[_0xdde9('0x17')]('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x14baf8,_0x547159||_0xdde9('0x14'),_0x4c51e6);_0xc89050[_0xdde9('0x14')](_0x4c51e6);}else{logger[_0xdde9('0x17')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x14baf8,_0x547159||_0xdde9('0x14'));_0xc89050[_0xdde9('0x10')]();}}else{_0xc89050[_0xdde9('0x14')]();}}catch(_0x2899e6){logger[_0xdde9('0xb')]('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x14baf8,_0x2899e6['message']);_0xc89050['stop']();}}}catch(_0xe242a9){logger['error'](_0xdde9('0xc'),_0x14baf8,JSON['stringify'](_0xe242a9));_0xc89050[_0xdde9('0x10')]();}};};