5a08480148159ed987d52fdeefa0baac2159233f
[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 _0x1a50=['join','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','condition','next','findIndex','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','error','stop','validate','lodash','./utils','../../../../config/logger','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','priority\x20true\x20is\x20a\x20number','number','consequence','fromString','length','[%s][GOTOIF]\x20%s','map','message'];(function(_0x3847e6,_0x4b3321){var _0x55e21c=function(_0xf65a1e){while(--_0xf65a1e){_0x3847e6['push'](_0x3847e6['shift']());}};_0x55e21c(++_0x4b3321);}(_0x1a50,0x142));var _0x01a5=function(_0x2c27c6,_0xb57741){_0x2c27c6=_0x2c27c6-0x0;var _0x43e0a3=_0x1a50[_0x2c27c6];return _0x43e0a3;};'use strict';var schema=require(_0x01a5('0x0'));var _=require(_0x01a5('0x1'));var htmlToText=require('html-to-text');var utils=require(_0x01a5('0x2'));var logger=require(_0x01a5('0x3'))('routing');var gotoif=schema({'condition':{'type':_0x01a5('0x4'),'required':!![],'message':_0x01a5('0x5')},'priorityTrue':{'type':'number','message':_0x01a5('0x6')},'priorityFalse':{'type':_0x01a5('0x7'),'message':'priority\x20false\x20is\x20a\x20number'}});exports[_0x01a5('0x8')]=function(_0x41d852,_0x52fdcb){return function(_0x3d0c05){try{var _0x484afe={'condition':htmlToText[_0x01a5('0x9')](utils['getMustacheRender'](_0x52fdcb[0x0],this),{'wordwrap':![]})['replace'](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x52fdcb[0x1],'priorityFalse':_0x52fdcb[0x2]};var _0x36d3e9=gotoif[_0x01a5('0x0')](_0x484afe,{'typecast':!![]});if(_0x36d3e9[_0x01a5('0xa')]){logger['error'](_0x01a5('0xb'),_0x41d852,_[_0x01a5('0xc')](_0x36d3e9,_0x01a5('0xd'))[_0x01a5('0xe')](',\x20'));_0x3d0c05['stop']();}else{try{var _0x58ad23=eval('('+_0x484afe['condition']+')');var _0x41e68c=_0x58ad23?_0x484afe['priorityTrue']:_0x484afe['priorityFalse'];logger[_0x01a5('0xf')](_0x01a5('0x10'),_0x41d852,_0x484afe[_0x01a5('0x11')],_0x58ad23,_0x41e68c||_0x01a5('0x12'));if(_0x41e68c){var _0x2bfd96=_[_0x01a5('0x13')](_0x3d0c05['rules'](),{'p':_0x41e68c});if(_0x2bfd96>=0x0){logger['info'](_0x01a5('0x14'),_0x41d852,_0x41e68c||_0x01a5('0x12'),_0x2bfd96);_0x3d0c05[_0x01a5('0x12')](_0x2bfd96);}else{logger[_0x01a5('0xf')](_0x01a5('0x15'),_0x41d852,_0x41e68c||_0x01a5('0x12'));_0x3d0c05['stop']();}}else{_0x3d0c05[_0x01a5('0x12')]();}}catch(_0x33170a){logger[_0x01a5('0x16')]('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x41d852,_0x33170a[_0x01a5('0xd')]);_0x3d0c05[_0x01a5('0x17')]();}}}catch(_0x54fd82){logger[_0x01a5('0x16')](_0x01a5('0xb'),_0x41d852,JSON['stringify'](_0x54fd82));_0x3d0c05[_0x01a5('0x17')]();}};};