bf35d410a5bdffc9cf6909f4f5ee52f5abf97d51
[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 _0xce39=['./utils','../../../../config/logger','routing','string','number','priority\x20true\x20is\x20a\x20number','consequence','fromString','getMustacheRender','replace','error','[%s][GOTOIF]\x20%s','map','message','stop','priorityTrue','priorityFalse','condition','findIndex','rules','info','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','next','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','stringify','validate','lodash'];(function(_0xa464c9,_0x7c86d8){var _0x3d73c4=function(_0x5c2056){while(--_0x5c2056){_0xa464c9['push'](_0xa464c9['shift']());}};_0x3d73c4(++_0x7c86d8);}(_0xce39,0x10c));var _0x9ce3=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0xce39[_0x2641f9];return _0x585741;};'use strict';var schema=require(_0x9ce3('0x0'));var _=require(_0x9ce3('0x1'));var htmlToText=require('html-to-text');var utils=require(_0x9ce3('0x2'));var logger=require(_0x9ce3('0x3'))(_0x9ce3('0x4'));var gotoif=schema({'condition':{'type':_0x9ce3('0x5'),'required':!![],'message':'condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'priorityTrue':{'type':_0x9ce3('0x6'),'message':_0x9ce3('0x7')},'priorityFalse':{'type':_0x9ce3('0x6'),'message':'priority\x20false\x20is\x20a\x20number'}});exports[_0x9ce3('0x8')]=function(_0x4411e3,_0x1d42bf){return function(_0xc9561c){try{var _0x552de6={'condition':htmlToText[_0x9ce3('0x9')](utils[_0x9ce3('0xa')](_0x1d42bf[0x0],this),{'wordwrap':![]})[_0x9ce3('0xb')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x1d42bf[0x1],'priorityFalse':_0x1d42bf[0x2]};var _0x5699ab=gotoif[_0x9ce3('0x0')](_0x552de6,{'typecast':!![]});if(_0x5699ab['length']){logger[_0x9ce3('0xc')](_0x9ce3('0xd'),_0x4411e3,_[_0x9ce3('0xe')](_0x5699ab,_0x9ce3('0xf'))['join'](',\x20'));_0xc9561c[_0x9ce3('0x10')]();}else{try{var _0x538856=eval('('+_0x552de6['condition']+')');var _0x307c64=_0x538856?_0x552de6[_0x9ce3('0x11')]:_0x552de6[_0x9ce3('0x12')];logger['info']('[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s',_0x4411e3,_0x552de6[_0x9ce3('0x13')],_0x538856,_0x307c64||'next');if(_0x307c64){var _0x12db79=_[_0x9ce3('0x14')](_0xc9561c[_0x9ce3('0x15')](),{'p':_0x307c64});if(_0x12db79>=0x0){logger[_0x9ce3('0x16')](_0x9ce3('0x17'),_0x4411e3,_0x307c64||_0x9ce3('0x18'),_0x12db79);_0xc9561c[_0x9ce3('0x18')](_0x12db79);}else{logger['info'](_0x9ce3('0x19'),_0x4411e3,_0x307c64||'next');_0xc9561c['stop']();}}else{_0xc9561c[_0x9ce3('0x18')]();}}catch(_0x2645cd){logger[_0x9ce3('0xc')]('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x4411e3,_0x2645cd[_0x9ce3('0xf')]);_0xc9561c[_0x9ce3('0x10')]();}}}catch(_0x2c94a9){logger[_0x9ce3('0xc')](_0x9ce3('0xd'),_0x4411e3,JSON[_0x9ce3('0x1a')](_0x2c94a9));_0xc9561c['stop']();}};};