91491d8c2413867447709b47455f0ee328ebb8cd
[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 _0x4865=['lodash','html-to-text','../../../../config/logger','routing','priority\x20true\x20is\x20a\x20number','number','priority\x20false\x20is\x20a\x20number','consequence','getMustacheRender','replace','error','[%s][GOTOIF]\x20%s','map','condition','priorityTrue','priorityFalse','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','findIndex','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','stop','[%s][GOTOIF]\x20eval\x20error:\x20%s','stringify','validate'];(function(_0x915a15,_0x31b9d2){var _0x24f642=function(_0x575d4c){while(--_0x575d4c){_0x915a15['push'](_0x915a15['shift']());}};_0x24f642(++_0x31b9d2);}(_0x4865,0x1c1));var _0x5486=function(_0x4a9fb1,_0x273043){_0x4a9fb1=_0x4a9fb1-0x0;var _0x348672=_0x4865[_0x4a9fb1];return _0x348672;};'use strict';var schema=require(_0x5486('0x0'));var _=require(_0x5486('0x1'));var htmlToText=require(_0x5486('0x2'));var utils=require('./utils');var logger=require(_0x5486('0x3'))(_0x5486('0x4'));var gotoif=schema({'condition':{'type':'string','required':!![],'message':'condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'priorityTrue':{'type':'number','message':_0x5486('0x5')},'priorityFalse':{'type':_0x5486('0x6'),'message':_0x5486('0x7')}});exports[_0x5486('0x8')]=function(_0x107c75,_0x512c10){return function(_0x428163){try{var _0x41c998={'condition':htmlToText['fromString'](utils[_0x5486('0x9')](_0x512c10[0x0],this),{'wordwrap':![]})[_0x5486('0xa')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x512c10[0x1],'priorityFalse':_0x512c10[0x2]};var _0x89d698=gotoif['validate'](_0x41c998,{'typecast':!![]});if(_0x89d698['length']){logger[_0x5486('0xb')](_0x5486('0xc'),_0x107c75,_[_0x5486('0xd')](_0x89d698,'message')['join'](',\x20'));_0x428163['stop']();}else{try{var _0x3319aa=eval('('+_0x41c998[_0x5486('0xe')]+')');var _0x5c8082=_0x3319aa?_0x41c998[_0x5486('0xf')]:_0x41c998[_0x5486('0x10')];logger[_0x5486('0x11')](_0x5486('0x12'),_0x107c75,_0x41c998[_0x5486('0xe')],_0x3319aa,_0x5c8082||_0x5486('0x13'));if(_0x5c8082){var _0x31f006=_[_0x5486('0x14')](_0x428163['rules'](),{'p':_0x5c8082});if(_0x31f006>=0x0){logger[_0x5486('0x11')]('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x107c75,_0x5c8082||_0x5486('0x13'),_0x31f006);_0x428163[_0x5486('0x13')](_0x31f006);}else{logger['info'](_0x5486('0x15'),_0x107c75,_0x5c8082||_0x5486('0x13'));_0x428163[_0x5486('0x16')]();}}else{_0x428163[_0x5486('0x13')]();}}catch(_0x1cc9a0){logger[_0x5486('0xb')](_0x5486('0x17'),_0x107c75,_0x1cc9a0['message']);_0x428163[_0x5486('0x16')]();}}}catch(_0x3038b0){logger[_0x5486('0xb')](_0x5486('0xc'),_0x107c75,JSON[_0x5486('0x18')](_0x3038b0));_0x428163[_0x5486('0x16')]();}};};