61e3dfabcc6fac8227221d770a84ffe226344884
[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 _0x0bb1=['info','next','findIndex','rules','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','[%s][GOTOIF]\x20eval\x20error:\x20%s','stringify','validate','lodash','./utils','routing','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','consequence','fromString','getMustacheRender','replace','error','[%s][GOTOIF]\x20%s','map','message','join','stop','priorityTrue','priorityFalse'];(function(_0x562e1e,_0x324936){var _0x9e7cc9=function(_0x1193ff){while(--_0x1193ff){_0x562e1e['push'](_0x562e1e['shift']());}};_0x9e7cc9(++_0x324936);}(_0x0bb1,0x13f));var _0x10bb=function(_0x1406c8,_0x40a801){_0x1406c8=_0x1406c8-0x0;var _0x3ec6f8=_0x0bb1[_0x1406c8];return _0x3ec6f8;};'use strict';var schema=require(_0x10bb('0x0'));var _=require(_0x10bb('0x1'));var htmlToText=require('html-to-text');var utils=require(_0x10bb('0x2'));var logger=require('../../../../config/logger')(_0x10bb('0x3'));var gotoif=schema({'condition':{'type':_0x10bb('0x4'),'required':!![],'message':_0x10bb('0x5')},'priorityTrue':{'type':_0x10bb('0x6'),'message':'priority\x20true\x20is\x20a\x20number'},'priorityFalse':{'type':_0x10bb('0x6'),'message':'priority\x20false\x20is\x20a\x20number'}});exports[_0x10bb('0x7')]=function(_0x51880c,_0x2c8e16){return function(_0x2264f0){try{var _0x505f72={'condition':htmlToText[_0x10bb('0x8')](utils[_0x10bb('0x9')](_0x2c8e16[0x0],this),{'wordwrap':![]})[_0x10bb('0xa')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x2c8e16[0x1],'priorityFalse':_0x2c8e16[0x2]};var _0x20fefb=gotoif['validate'](_0x505f72,{'typecast':!![]});if(_0x20fefb['length']){logger[_0x10bb('0xb')](_0x10bb('0xc'),_0x51880c,_[_0x10bb('0xd')](_0x20fefb,_0x10bb('0xe'))[_0x10bb('0xf')](',\x20'));_0x2264f0[_0x10bb('0x10')]();}else{try{var _0x17a338=eval('('+_0x505f72['condition']+')');var _0x25b886=_0x17a338?_0x505f72[_0x10bb('0x11')]:_0x505f72[_0x10bb('0x12')];logger[_0x10bb('0x13')]('[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s',_0x51880c,_0x505f72['condition'],_0x17a338,_0x25b886||_0x10bb('0x14'));if(_0x25b886){var _0x527516=_[_0x10bb('0x15')](_0x2264f0[_0x10bb('0x16')](),{'p':_0x25b886});if(_0x527516>=0x0){logger[_0x10bb('0x13')](_0x10bb('0x17'),_0x51880c,_0x25b886||_0x10bb('0x14'),_0x527516);_0x2264f0['next'](_0x527516);}else{logger[_0x10bb('0x13')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x51880c,_0x25b886||_0x10bb('0x14'));_0x2264f0['stop']();}}else{_0x2264f0['next']();}}catch(_0x52503e){logger[_0x10bb('0xb')](_0x10bb('0x18'),_0x51880c,_0x52503e['message']);_0x2264f0[_0x10bb('0x10')]();}}}catch(_0x23b776){logger['error'](_0x10bb('0xc'),_0x51880c,JSON[_0x10bb('0x19')](_0x23b776));_0x2264f0[_0x10bb('0x10')]();}};};