4a4a0baca31332ac03cd849df399460c2714257a
[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 _0x4c14=['string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','fromString','getMustacheRender','length','error','[%s][GOTOIF]\x20%s','message','join','stop','condition','priorityFalse','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','rules','stringify','validate','lodash','html-to-text','./utils','routing'];(function(_0x1e71a7,_0x37dc43){var _0x1644e4=function(_0x2418a5){while(--_0x2418a5){_0x1e71a7['push'](_0x1e71a7['shift']());}};_0x1644e4(++_0x37dc43);}(_0x4c14,0x187));var _0x44c1=function(_0x426c55,_0x2356eb){_0x426c55=_0x426c55-0x0;var _0x55f62f=_0x4c14[_0x426c55];return _0x55f62f;};'use strict';var schema=require(_0x44c1('0x0'));var _=require(_0x44c1('0x1'));var htmlToText=require(_0x44c1('0x2'));var utils=require(_0x44c1('0x3'));var logger=require('../../../../config/logger')(_0x44c1('0x4'));var gotoif=schema({'condition':{'type':_0x44c1('0x5'),'required':!![],'message':_0x44c1('0x6')},'priorityTrue':{'type':'number','message':'priority\x20true\x20is\x20a\x20number'},'priorityFalse':{'type':'number','message':'priority\x20false\x20is\x20a\x20number'}});exports['consequence']=function(_0x46effe,_0x1d290e){return function(_0x35e30e){try{var _0x392d8f={'condition':htmlToText[_0x44c1('0x7')](utils[_0x44c1('0x8')](_0x1d290e[0x0],this),{'wordwrap':![]})['replace'](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x1d290e[0x1],'priorityFalse':_0x1d290e[0x2]};var _0x53d277=gotoif['validate'](_0x392d8f,{'typecast':!![]});if(_0x53d277[_0x44c1('0x9')]){logger[_0x44c1('0xa')](_0x44c1('0xb'),_0x46effe,_['map'](_0x53d277,_0x44c1('0xc'))[_0x44c1('0xd')](',\x20'));_0x35e30e[_0x44c1('0xe')]();}else{try{var _0x591061=eval('('+_0x392d8f[_0x44c1('0xf')]+')');var _0x242ae5=_0x591061?_0x392d8f['priorityTrue']:_0x392d8f[_0x44c1('0x10')];logger[_0x44c1('0x11')](_0x44c1('0x12'),_0x46effe,_0x392d8f[_0x44c1('0xf')],_0x591061,_0x242ae5||_0x44c1('0x13'));if(_0x242ae5){var _0x46959a=_['findIndex'](_0x35e30e[_0x44c1('0x14')](),{'p':_0x242ae5});if(_0x46959a>=0x0){logger['info']('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x46effe,_0x242ae5||_0x44c1('0x13'),_0x46959a);_0x35e30e[_0x44c1('0x13')](_0x46959a);}else{logger[_0x44c1('0x11')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x46effe,_0x242ae5||_0x44c1('0x13'));_0x35e30e[_0x44c1('0xe')]();}}else{_0x35e30e['next']();}}catch(_0x5afcaf){logger[_0x44c1('0xa')]('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x46effe,_0x5afcaf['message']);_0x35e30e['stop']();}}}catch(_0xde23d8){logger['error'](_0x44c1('0xb'),_0x46effe,JSON[_0x44c1('0x15')](_0xde23d8));_0x35e30e['stop']();}};};