b24a767f765cf53ed1b50bcaec78ebd81696b631
[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 _0x0bc4=['../../../../config/logger','routing','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20true\x20is\x20a\x20number','consequence','fromString','getMustacheRender','replace','validate','error','[%s][GOTOIF]\x20%s','map','message','join','priorityTrue','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','condition','next','findIndex','rules','info','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','stop','[%s][GOTOIF]\x20eval\x20error:\x20%s','stringify','lodash','html-to-text','./utils'];(function(_0x4b055c,_0x4b870b){var _0x4b62bb=function(_0x4884c2){while(--_0x4884c2){_0x4b055c['push'](_0x4b055c['shift']());}};_0x4b62bb(++_0x4b870b);}(_0x0bc4,0x165));var _0x40bc=function(_0x35ab35,_0x68ad16){_0x35ab35=_0x35ab35-0x0;var _0x1544be=_0x0bc4[_0x35ab35];return _0x1544be;};'use strict';var schema=require('validate');var _=require(_0x40bc('0x0'));var htmlToText=require(_0x40bc('0x1'));var utils=require(_0x40bc('0x2'));var logger=require(_0x40bc('0x3'))(_0x40bc('0x4'));var gotoif=schema({'condition':{'type':_0x40bc('0x5'),'required':!![],'message':_0x40bc('0x6')},'priorityTrue':{'type':_0x40bc('0x7'),'message':_0x40bc('0x8')},'priorityFalse':{'type':_0x40bc('0x7'),'message':'priority\x20false\x20is\x20a\x20number'}});exports[_0x40bc('0x9')]=function(_0x55df98,_0x4cf130){return function(_0x1838a7){try{var _0x7f38e2={'condition':htmlToText[_0x40bc('0xa')](utils[_0x40bc('0xb')](_0x4cf130[0x0],this),{'wordwrap':![]})[_0x40bc('0xc')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x4cf130[0x1],'priorityFalse':_0x4cf130[0x2]};var _0x294ab3=gotoif[_0x40bc('0xd')](_0x7f38e2,{'typecast':!![]});if(_0x294ab3['length']){logger[_0x40bc('0xe')](_0x40bc('0xf'),_0x55df98,_[_0x40bc('0x10')](_0x294ab3,_0x40bc('0x11'))[_0x40bc('0x12')](',\x20'));_0x1838a7['stop']();}else{try{var _0x57642f=eval('('+_0x7f38e2['condition']+')');var _0x44fda1=_0x57642f?_0x7f38e2[_0x40bc('0x13')]:_0x7f38e2['priorityFalse'];logger['info'](_0x40bc('0x14'),_0x55df98,_0x7f38e2[_0x40bc('0x15')],_0x57642f,_0x44fda1||_0x40bc('0x16'));if(_0x44fda1){var _0x5e50bb=_[_0x40bc('0x17')](_0x1838a7[_0x40bc('0x18')](),{'p':_0x44fda1});if(_0x5e50bb>=0x0){logger[_0x40bc('0x19')](_0x40bc('0x1a'),_0x55df98,_0x44fda1||'next',_0x5e50bb);_0x1838a7['next'](_0x5e50bb);}else{logger[_0x40bc('0x19')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x55df98,_0x44fda1||_0x40bc('0x16'));_0x1838a7[_0x40bc('0x1b')]();}}else{_0x1838a7[_0x40bc('0x16')]();}}catch(_0x196cba){logger[_0x40bc('0xe')](_0x40bc('0x1c'),_0x55df98,_0x196cba[_0x40bc('0x11')]);_0x1838a7[_0x40bc('0x1b')]();}}}catch(_0xded37){logger[_0x40bc('0xe')]('[%s][GOTOIF]\x20%s',_0x55df98,JSON[_0x40bc('0x1d')](_0xded37));_0x1838a7['stop']();}};};