ea17954e204133cc6afe379ee2b3679cfafe758b
[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 _0x4221=['rules','info','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','stringify','validate','./utils','../../../../config/logger','routing','string','number','priority\x20false\x20is\x20a\x20number','consequence','fromString','replace','error','[%s][GOTOIF]\x20%s','map','message','stop','condition','priorityTrue','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','findIndex'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0x4221,0x94));var _0x1422=function(_0x1084b7,_0x3c1bc8){_0x1084b7=_0x1084b7-0x0;var _0x2132f6=_0x4221[_0x1084b7];return _0x2132f6;};'use strict';var schema=require(_0x1422('0x0'));var _=require('lodash');var htmlToText=require('html-to-text');var utils=require(_0x1422('0x1'));var logger=require(_0x1422('0x2'))(_0x1422('0x3'));var gotoif=schema({'condition':{'type':_0x1422('0x4'),'required':!![],'message':'condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'priorityTrue':{'type':_0x1422('0x5'),'message':'priority\x20true\x20is\x20a\x20number'},'priorityFalse':{'type':'number','message':_0x1422('0x6')}});exports[_0x1422('0x7')]=function(_0x17581b,_0x533606){return function(_0xf37a19){try{var _0x548632={'condition':htmlToText[_0x1422('0x8')](utils['getMustacheRender'](_0x533606[0x0],this),{'wordwrap':![]})[_0x1422('0x9')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x533606[0x1],'priorityFalse':_0x533606[0x2]};var _0x22e562=gotoif[_0x1422('0x0')](_0x548632,{'typecast':!![]});if(_0x22e562['length']){logger[_0x1422('0xa')](_0x1422('0xb'),_0x17581b,_[_0x1422('0xc')](_0x22e562,_0x1422('0xd'))['join'](',\x20'));_0xf37a19[_0x1422('0xe')]();}else{try{var _0x5c6c2e=eval('('+_0x548632[_0x1422('0xf')]+')');var _0x4d5664=_0x5c6c2e?_0x548632[_0x1422('0x10')]:_0x548632['priorityFalse'];logger['info'](_0x1422('0x11'),_0x17581b,_0x548632[_0x1422('0xf')],_0x5c6c2e,_0x4d5664||_0x1422('0x12'));if(_0x4d5664){var _0x19da94=_[_0x1422('0x13')](_0xf37a19[_0x1422('0x14')](),{'p':_0x4d5664});if(_0x19da94>=0x0){logger[_0x1422('0x15')](_0x1422('0x16'),_0x17581b,_0x4d5664||_0x1422('0x12'),_0x19da94);_0xf37a19[_0x1422('0x12')](_0x19da94);}else{logger[_0x1422('0x15')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x17581b,_0x4d5664||_0x1422('0x12'));_0xf37a19[_0x1422('0xe')]();}}else{_0xf37a19[_0x1422('0x12')]();}}catch(_0x36ca8b){logger[_0x1422('0xa')]('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x17581b,_0x36ca8b[_0x1422('0xd')]);_0xf37a19[_0x1422('0xe')]();}}}catch(_0xc1c972){logger[_0x1422('0xa')](_0x1422('0xb'),_0x17581b,JSON[_0x1422('0x17')](_0xc1c972));_0xf37a19[_0x1422('0xe')]();}};};