d003c458c91d5231598cfdaab5d7410cd924d1d9
[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 _0x54b4=['./utils','../../../../config/logger','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20true\x20is\x20a\x20number','consequence','fromString','getMustacheRender','replace','length','error','[%s][GOTOIF]\x20%s','message','join','stop','condition','info','next','findIndex','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','stringify','validate','html-to-text'];(function(_0x4c5eac,_0x2e687e){var _0x5a71a9=function(_0x36f220){while(--_0x36f220){_0x4c5eac['push'](_0x4c5eac['shift']());}};_0x5a71a9(++_0x2e687e);}(_0x54b4,0xad));var _0x454b=function(_0x45dbe6,_0x2dc5fc){_0x45dbe6=_0x45dbe6-0x0;var _0x416dc9=_0x54b4[_0x45dbe6];return _0x416dc9;};'use strict';var schema=require(_0x454b('0x0'));var _=require('lodash');var htmlToText=require(_0x454b('0x1'));var utils=require(_0x454b('0x2'));var logger=require(_0x454b('0x3'))('routing');var gotoif=schema({'condition':{'type':_0x454b('0x4'),'required':!![],'message':_0x454b('0x5')},'priorityTrue':{'type':_0x454b('0x6'),'message':_0x454b('0x7')},'priorityFalse':{'type':_0x454b('0x6'),'message':'priority\x20false\x20is\x20a\x20number'}});exports[_0x454b('0x8')]=function(_0x556992,_0x2a5444){return function(_0x1afb17){try{var _0x25b37c={'condition':htmlToText[_0x454b('0x9')](utils[_0x454b('0xa')](_0x2a5444[0x0],this),{'wordwrap':![]})[_0x454b('0xb')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x2a5444[0x1],'priorityFalse':_0x2a5444[0x2]};var _0x293c4f=gotoif['validate'](_0x25b37c,{'typecast':!![]});if(_0x293c4f[_0x454b('0xc')]){logger[_0x454b('0xd')](_0x454b('0xe'),_0x556992,_['map'](_0x293c4f,_0x454b('0xf'))[_0x454b('0x10')](',\x20'));_0x1afb17[_0x454b('0x11')]();}else{try{var _0x5e8dac=eval('('+_0x25b37c[_0x454b('0x12')]+')');var _0x1cce0b=_0x5e8dac?_0x25b37c['priorityTrue']:_0x25b37c['priorityFalse'];logger[_0x454b('0x13')]('[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s',_0x556992,_0x25b37c[_0x454b('0x12')],_0x5e8dac,_0x1cce0b||_0x454b('0x14'));if(_0x1cce0b){var _0x2fecd3=_[_0x454b('0x15')](_0x1afb17['rules'](),{'p':_0x1cce0b});if(_0x2fecd3>=0x0){logger['info'](_0x454b('0x16'),_0x556992,_0x1cce0b||_0x454b('0x14'),_0x2fecd3);_0x1afb17[_0x454b('0x14')](_0x2fecd3);}else{logger[_0x454b('0x13')](_0x454b('0x17'),_0x556992,_0x1cce0b||_0x454b('0x14'));_0x1afb17['stop']();}}else{_0x1afb17[_0x454b('0x14')]();}}catch(_0x3c586a){logger[_0x454b('0xd')]('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x556992,_0x3c586a[_0x454b('0xf')]);_0x1afb17[_0x454b('0x11')]();}}}catch(_0x46b373){logger[_0x454b('0xd')](_0x454b('0xe'),_0x556992,JSON[_0x454b('0x18')](_0x46b373));_0x1afb17['stop']();}};};