84f5348df49aec8d354e2bb859fc9243f9a9a5fc
[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 _0xe7fb=['[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','info','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','[%s][GOTOIF]\x20eval\x20error:\x20%s','message','stringify','../../../../config/logger','routing','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20false\x20is\x20a\x20number','consequence','fromString','getMustacheRender','replace','validate','length','error','[%s][GOTOIF]\x20%s','map','join','stop','priorityFalse','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','condition','next','findIndex'];(function(_0xa464c9,_0x7c86d8){var _0x3d73c4=function(_0x5c2056){while(--_0x5c2056){_0xa464c9['push'](_0xa464c9['shift']());}};_0x3d73c4(++_0x7c86d8);}(_0xe7fb,0x165));var _0xbe7f=function(_0x5770bd,_0x4f1096){_0x5770bd=_0x5770bd-0x0;var _0x1a350c=_0xe7fb[_0x5770bd];return _0x1a350c;};'use strict';var schema=require('validate');var _=require('lodash');var htmlToText=require('html-to-text');var utils=require('./utils');var logger=require(_0xbe7f('0x0'))(_0xbe7f('0x1'));var gotoif=schema({'condition':{'type':'string','required':!![],'message':_0xbe7f('0x2')},'priorityTrue':{'type':_0xbe7f('0x3'),'message':'priority\x20true\x20is\x20a\x20number'},'priorityFalse':{'type':_0xbe7f('0x3'),'message':_0xbe7f('0x4')}});exports[_0xbe7f('0x5')]=function(_0x4dc215,_0xc094c8){return function(_0x18f255){try{var _0x2ba3a3={'condition':htmlToText[_0xbe7f('0x6')](utils[_0xbe7f('0x7')](_0xc094c8[0x0],this),{'wordwrap':![]})[_0xbe7f('0x8')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0xc094c8[0x1],'priorityFalse':_0xc094c8[0x2]};var _0x353c03=gotoif[_0xbe7f('0x9')](_0x2ba3a3,{'typecast':!![]});if(_0x353c03[_0xbe7f('0xa')]){logger[_0xbe7f('0xb')](_0xbe7f('0xc'),_0x4dc215,_[_0xbe7f('0xd')](_0x353c03,'message')[_0xbe7f('0xe')](',\x20'));_0x18f255[_0xbe7f('0xf')]();}else{try{var _0x4e5157=eval('('+_0x2ba3a3['condition']+')');var _0x35da12=_0x4e5157?_0x2ba3a3['priorityTrue']:_0x2ba3a3[_0xbe7f('0x10')];logger['info'](_0xbe7f('0x11'),_0x4dc215,_0x2ba3a3[_0xbe7f('0x12')],_0x4e5157,_0x35da12||_0xbe7f('0x13'));if(_0x35da12){var _0x3c37b3=_[_0xbe7f('0x14')](_0x18f255['rules'](),{'p':_0x35da12});if(_0x3c37b3>=0x0){logger['info'](_0xbe7f('0x15'),_0x4dc215,_0x35da12||_0xbe7f('0x13'),_0x3c37b3);_0x18f255[_0xbe7f('0x13')](_0x3c37b3);}else{logger[_0xbe7f('0x16')](_0xbe7f('0x17'),_0x4dc215,_0x35da12||'next');_0x18f255[_0xbe7f('0xf')]();}}else{_0x18f255[_0xbe7f('0x13')]();}}catch(_0x2c00c8){logger[_0xbe7f('0xb')](_0xbe7f('0x18'),_0x4dc215,_0x2c00c8[_0xbe7f('0x19')]);_0x18f255['stop']();}}}catch(_0x5ddea9){logger[_0xbe7f('0xb')](_0xbe7f('0xc'),_0x4dc215,JSON[_0xbe7f('0x1a')](_0x5ddea9));_0x18f255['stop']();}};};