8d7a68afbdf3decbb9f5d987eca27dfffb82575d
[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 _0xddef=['[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','[%s][GOTOIF]\x20eval\x20error:\x20%s','html-to-text','string','number','priority\x20true\x20is\x20a\x20number','priority\x20false\x20is\x20a\x20number','consequence','fromString','getMustacheRender','replace','validate','length','error','map','message','stop','condition','priorityTrue','priorityFalse','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','findIndex','rules'];(function(_0x47c663,_0x2c3949){var _0x24f2b7=function(_0x178ea9){while(--_0x178ea9){_0x47c663['push'](_0x47c663['shift']());}};_0x24f2b7(++_0x2c3949);}(_0xddef,0xca));var _0xfdde=function(_0x584b9d,_0x1cb5c5){_0x584b9d=_0x584b9d-0x0;var _0x172053=_0xddef[_0x584b9d];return _0x172053;};'use strict';var schema=require('validate');var _=require('lodash');var htmlToText=require(_0xfdde('0x0'));var utils=require('./utils');var logger=require('../../../../config/logger')('routing');var gotoif=schema({'condition':{'type':_0xfdde('0x1'),'required':!![],'message':'condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'priorityTrue':{'type':_0xfdde('0x2'),'message':_0xfdde('0x3')},'priorityFalse':{'type':_0xfdde('0x2'),'message':_0xfdde('0x4')}});exports[_0xfdde('0x5')]=function(_0x49958b,_0x9bd434){return function(_0x9c3a7){try{var _0x9b83c3={'condition':htmlToText[_0xfdde('0x6')](utils[_0xfdde('0x7')](_0x9bd434[0x0],this),{'wordwrap':![]})[_0xfdde('0x8')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x9bd434[0x1],'priorityFalse':_0x9bd434[0x2]};var _0x2111fe=gotoif[_0xfdde('0x9')](_0x9b83c3,{'typecast':!![]});if(_0x2111fe[_0xfdde('0xa')]){logger[_0xfdde('0xb')]('[%s][GOTOIF]\x20%s',_0x49958b,_[_0xfdde('0xc')](_0x2111fe,_0xfdde('0xd'))['join'](',\x20'));_0x9c3a7[_0xfdde('0xe')]();}else{try{var _0xe92725=eval('('+_0x9b83c3[_0xfdde('0xf')]+')');var _0x5e175e=_0xe92725?_0x9b83c3[_0xfdde('0x10')]:_0x9b83c3[_0xfdde('0x11')];logger[_0xfdde('0x12')](_0xfdde('0x13'),_0x49958b,_0x9b83c3[_0xfdde('0xf')],_0xe92725,_0x5e175e||_0xfdde('0x14'));if(_0x5e175e){var _0x1fe747=_[_0xfdde('0x15')](_0x9c3a7[_0xfdde('0x16')](),{'p':_0x5e175e});if(_0x1fe747>=0x0){logger['info']('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x49958b,_0x5e175e||'next',_0x1fe747);_0x9c3a7['next'](_0x1fe747);}else{logger[_0xfdde('0x12')](_0xfdde('0x17'),_0x49958b,_0x5e175e||_0xfdde('0x14'));_0x9c3a7[_0xfdde('0xe')]();}}else{_0x9c3a7['next']();}}catch(_0x1d571e){logger[_0xfdde('0xb')](_0xfdde('0x18'),_0x49958b,_0x1d571e[_0xfdde('0xd')]);_0x9c3a7['stop']();}}}catch(_0x2cf5a3){logger[_0xfdde('0xb')]('[%s][GOTOIF]\x20%s',_0x49958b,JSON['stringify'](_0x2cf5a3));_0x9c3a7[_0xfdde('0xe')]();}};};