16a42c98ece026bd91971313de17218028c7e498
[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 _0x6127=['findIndex','rules','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','stop','error','stringify','validate','lodash','html-to-text','./utils','../../../../config/logger','routing','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20false\x20is\x20a\x20number','consequence','fromString','getMustacheRender','length','[%s][GOTOIF]\x20%s','map','message','join','priorityTrue','priorityFalse','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','condition','next'];(function(_0xb37589,_0x27058d){var _0x42ce47=function(_0x35c9b3){while(--_0x35c9b3){_0xb37589['push'](_0xb37589['shift']());}};_0x42ce47(++_0x27058d);}(_0x6127,0x1d8));var _0x7612=function(_0x1ae125,_0x20820a){_0x1ae125=_0x1ae125-0x0;var _0x1f3b2b=_0x6127[_0x1ae125];return _0x1f3b2b;};'use strict';var schema=require(_0x7612('0x0'));var _=require(_0x7612('0x1'));var htmlToText=require(_0x7612('0x2'));var utils=require(_0x7612('0x3'));var logger=require(_0x7612('0x4'))(_0x7612('0x5'));var gotoif=schema({'condition':{'type':_0x7612('0x6'),'required':!![],'message':_0x7612('0x7')},'priorityTrue':{'type':_0x7612('0x8'),'message':'priority\x20true\x20is\x20a\x20number'},'priorityFalse':{'type':_0x7612('0x8'),'message':_0x7612('0x9')}});exports[_0x7612('0xa')]=function(_0x30ce55,_0x2cb65e){return function(_0x28974d){try{var _0x1f1d33={'condition':htmlToText[_0x7612('0xb')](utils[_0x7612('0xc')](_0x2cb65e[0x0],this),{'wordwrap':![]})['replace'](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x2cb65e[0x1],'priorityFalse':_0x2cb65e[0x2]};var _0x49c0bf=gotoif[_0x7612('0x0')](_0x1f1d33,{'typecast':!![]});if(_0x49c0bf[_0x7612('0xd')]){logger['error'](_0x7612('0xe'),_0x30ce55,_[_0x7612('0xf')](_0x49c0bf,_0x7612('0x10'))[_0x7612('0x11')](',\x20'));_0x28974d['stop']();}else{try{var _0x4e7cfe=eval('('+_0x1f1d33['condition']+')');var _0x366a09=_0x4e7cfe?_0x1f1d33[_0x7612('0x12')]:_0x1f1d33[_0x7612('0x13')];logger[_0x7612('0x14')](_0x7612('0x15'),_0x30ce55,_0x1f1d33[_0x7612('0x16')],_0x4e7cfe,_0x366a09||_0x7612('0x17'));if(_0x366a09){var _0xba3112=_[_0x7612('0x18')](_0x28974d[_0x7612('0x19')](),{'p':_0x366a09});if(_0xba3112>=0x0){logger[_0x7612('0x14')](_0x7612('0x1a'),_0x30ce55,_0x366a09||'next',_0xba3112);_0x28974d[_0x7612('0x17')](_0xba3112);}else{logger[_0x7612('0x14')](_0x7612('0x1b'),_0x30ce55,_0x366a09||'next');_0x28974d['stop']();}}else{_0x28974d[_0x7612('0x17')]();}}catch(_0x1c5b1e){logger['error']('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x30ce55,_0x1c5b1e[_0x7612('0x10')]);_0x28974d[_0x7612('0x1c')]();}}}catch(_0x1b7e6c){logger[_0x7612('0x1d')](_0x7612('0xe'),_0x30ce55,JSON[_0x7612('0x1e')](_0x1b7e6c));_0x28974d['stop']();}};};