Built motion from commit (unavailable).|2.5.27
[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 _0x15c9=['error','[%s][GOTOIF]\x20%s','stringify','lodash','html-to-text','./utils','../../../../config/logger','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','fromString','getMustacheRender','replace','validate','length','map','message','join','stop','condition','priorityTrue','info','next','findIndex','rules'];(function(_0x24679e,_0x22d9d7){var _0x291f21=function(_0x329529){while(--_0x329529){_0x24679e['push'](_0x24679e['shift']());}};_0x291f21(++_0x22d9d7);}(_0x15c9,0xb2));var _0x915c=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0x15c9[_0x2641f9];return _0x585741;};'use strict';var schema=require('validate');var _=require(_0x915c('0x0'));var htmlToText=require(_0x915c('0x1'));var utils=require(_0x915c('0x2'));var logger=require(_0x915c('0x3'))('routing');var gotoif=schema({'condition':{'type':_0x915c('0x4'),'required':!![],'message':_0x915c('0x5')},'priorityTrue':{'type':'number','message':'priority\x20true\x20is\x20a\x20number'},'priorityFalse':{'type':_0x915c('0x6'),'message':'priority\x20false\x20is\x20a\x20number'}});exports['consequence']=function(_0x5d20e2,_0x444112){return function(_0x2d958b){try{var _0x4aacd6={'condition':htmlToText[_0x915c('0x7')](utils[_0x915c('0x8')](_0x444112[0x0],this),{'wordwrap':![]})[_0x915c('0x9')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x444112[0x1],'priorityFalse':_0x444112[0x2]};var _0x5e95ba=gotoif[_0x915c('0xa')](_0x4aacd6,{'typecast':!![]});if(_0x5e95ba[_0x915c('0xb')]){logger['error']('[%s][GOTOIF]\x20%s',_0x5d20e2,_[_0x915c('0xc')](_0x5e95ba,_0x915c('0xd'))[_0x915c('0xe')](',\x20'));_0x2d958b[_0x915c('0xf')]();}else{try{var _0x467492=eval('('+_0x4aacd6[_0x915c('0x10')]+')');var _0x5077a4=_0x467492?_0x4aacd6[_0x915c('0x11')]:_0x4aacd6['priorityFalse'];logger[_0x915c('0x12')]('[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s',_0x5d20e2,_0x4aacd6[_0x915c('0x10')],_0x467492,_0x5077a4||_0x915c('0x13'));if(_0x5077a4){var _0x1a4ff9=_[_0x915c('0x14')](_0x2d958b[_0x915c('0x15')](),{'p':_0x5077a4});if(_0x1a4ff9>=0x0){logger['info']('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x5d20e2,_0x5077a4||'next',_0x1a4ff9);_0x2d958b[_0x915c('0x13')](_0x1a4ff9);}else{logger[_0x915c('0x12')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x5d20e2,_0x5077a4||_0x915c('0x13'));_0x2d958b[_0x915c('0xf')]();}}else{_0x2d958b[_0x915c('0x13')]();}}catch(_0x18f2f7){logger['error']('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x5d20e2,_0x18f2f7['message']);_0x2d958b[_0x915c('0xf')]();}}}catch(_0x312c24){logger[_0x915c('0x16')](_0x915c('0x17'),_0x5d20e2,JSON[_0x915c('0x18')](_0x312c24));_0x2d958b[_0x915c('0xf')]();}};};