4fb3cdde253ebecebd75f9b829795e0406b338ef
[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 _0x2114=['findIndex','rules','next','[%s][GOTOIF]\x20eval\x20error:\x20%s','stringify','validate','lodash','html-to-text','../../../../config/logger','routing','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20true\x20is\x20a\x20number','fromString','getMustacheRender','replace','length','error','[%s][GOTOIF]\x20%s','map','message','join','stop','condition','priorityTrue','priorityFalse','info'];(function(_0xc43657,_0x17b2d8){var _0x6eca29=function(_0x2a3cf0){while(--_0x2a3cf0){_0xc43657['push'](_0xc43657['shift']());}};_0x6eca29(++_0x17b2d8);}(_0x2114,0x149));var _0x4211=function(_0xd0a847,_0x72562b){_0xd0a847=_0xd0a847-0x0;var _0x2536ec=_0x2114[_0xd0a847];return _0x2536ec;};'use strict';var schema=require(_0x4211('0x0'));var _=require(_0x4211('0x1'));var htmlToText=require(_0x4211('0x2'));var utils=require('./utils');var logger=require(_0x4211('0x3'))(_0x4211('0x4'));var gotoif=schema({'condition':{'type':'string','required':!![],'message':_0x4211('0x5')},'priorityTrue':{'type':_0x4211('0x6'),'message':_0x4211('0x7')},'priorityFalse':{'type':_0x4211('0x6'),'message':'priority\x20false\x20is\x20a\x20number'}});exports['consequence']=function(_0x4f5e6d,_0x33c3fe){return function(_0x78caa4){try{var _0x2c06e1={'condition':htmlToText[_0x4211('0x8')](utils[_0x4211('0x9')](_0x33c3fe[0x0],this),{'wordwrap':![]})[_0x4211('0xa')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x33c3fe[0x1],'priorityFalse':_0x33c3fe[0x2]};var _0x4c710b=gotoif['validate'](_0x2c06e1,{'typecast':!![]});if(_0x4c710b[_0x4211('0xb')]){logger[_0x4211('0xc')](_0x4211('0xd'),_0x4f5e6d,_[_0x4211('0xe')](_0x4c710b,_0x4211('0xf'))[_0x4211('0x10')](',\x20'));_0x78caa4[_0x4211('0x11')]();}else{try{var _0xdb4fd1=eval('('+_0x2c06e1[_0x4211('0x12')]+')');var _0x11a9ce=_0xdb4fd1?_0x2c06e1[_0x4211('0x13')]:_0x2c06e1[_0x4211('0x14')];logger[_0x4211('0x15')]('[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s',_0x4f5e6d,_0x2c06e1[_0x4211('0x12')],_0xdb4fd1,_0x11a9ce||'next');if(_0x11a9ce){var _0x5cdfcf=_[_0x4211('0x16')](_0x78caa4[_0x4211('0x17')](),{'p':_0x11a9ce});if(_0x5cdfcf>=0x0){logger[_0x4211('0x15')]('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x4f5e6d,_0x11a9ce||_0x4211('0x18'),_0x5cdfcf);_0x78caa4['next'](_0x5cdfcf);}else{logger[_0x4211('0x15')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x4f5e6d,_0x11a9ce||_0x4211('0x18'));_0x78caa4[_0x4211('0x11')]();}}else{_0x78caa4[_0x4211('0x18')]();}}catch(_0x43c23c){logger[_0x4211('0xc')](_0x4211('0x19'),_0x4f5e6d,_0x43c23c['message']);_0x78caa4[_0x4211('0x11')]();}}}catch(_0x5e0666){logger[_0x4211('0xc')](_0x4211('0xd'),_0x4f5e6d,JSON[_0x4211('0x1a')](_0x5e0666));_0x78caa4[_0x4211('0x11')]();}};};