c3703903a9a3c0f23b1d762c8b83b91b3006b53e
[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 _0x8033=['condition','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','findIndex','rules','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','[%s][GOTOIF]\x20eval\x20error:\x20%s','stringify','html-to-text','./utils','../../../../config/logger','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20true\x20is\x20a\x20number','priority\x20false\x20is\x20a\x20number','consequence','getMustacheRender','replace','length','error','[%s][GOTOIF]\x20%s','map','message','join','stop'];(function(_0x53e4a1,_0x25404d){var _0x595089=function(_0x353d32){while(--_0x353d32){_0x53e4a1['push'](_0x53e4a1['shift']());}};_0x595089(++_0x25404d);}(_0x8033,0x183));var _0x3803=function(_0x465990,_0x3a3369){_0x465990=_0x465990-0x0;var _0x23966f=_0x8033[_0x465990];return _0x23966f;};'use strict';var schema=require('validate');var _=require('lodash');var htmlToText=require(_0x3803('0x0'));var utils=require(_0x3803('0x1'));var logger=require(_0x3803('0x2'))('routing');var gotoif=schema({'condition':{'type':_0x3803('0x3'),'required':!![],'message':_0x3803('0x4')},'priorityTrue':{'type':_0x3803('0x5'),'message':_0x3803('0x6')},'priorityFalse':{'type':'number','message':_0x3803('0x7')}});exports[_0x3803('0x8')]=function(_0x35bdae,_0x53366f){return function(_0x25e9b1){try{var _0x4dedd5={'condition':htmlToText['fromString'](utils[_0x3803('0x9')](_0x53366f[0x0],this),{'wordwrap':![]})[_0x3803('0xa')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x53366f[0x1],'priorityFalse':_0x53366f[0x2]};var _0x293c48=gotoif['validate'](_0x4dedd5,{'typecast':!![]});if(_0x293c48[_0x3803('0xb')]){logger[_0x3803('0xc')](_0x3803('0xd'),_0x35bdae,_[_0x3803('0xe')](_0x293c48,_0x3803('0xf'))[_0x3803('0x10')](',\x20'));_0x25e9b1[_0x3803('0x11')]();}else{try{var _0x52aaf6=eval('('+_0x4dedd5[_0x3803('0x12')]+')');var _0x501e65=_0x52aaf6?_0x4dedd5['priorityTrue']:_0x4dedd5['priorityFalse'];logger[_0x3803('0x13')](_0x3803('0x14'),_0x35bdae,_0x4dedd5[_0x3803('0x12')],_0x52aaf6,_0x501e65||_0x3803('0x15'));if(_0x501e65){var _0x2cc1f2=_[_0x3803('0x16')](_0x25e9b1[_0x3803('0x17')](),{'p':_0x501e65});if(_0x2cc1f2>=0x0){logger[_0x3803('0x13')]('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x35bdae,_0x501e65||_0x3803('0x15'),_0x2cc1f2);_0x25e9b1['next'](_0x2cc1f2);}else{logger[_0x3803('0x13')](_0x3803('0x18'),_0x35bdae,_0x501e65||_0x3803('0x15'));_0x25e9b1[_0x3803('0x11')]();}}else{_0x25e9b1['next']();}}catch(_0x59b8b4){logger['error'](_0x3803('0x19'),_0x35bdae,_0x59b8b4[_0x3803('0xf')]);_0x25e9b1[_0x3803('0x11')]();}}}catch(_0x2de82d){logger[_0x3803('0xc')]('[%s][GOTOIF]\x20%s',_0x35bdae,JSON[_0x3803('0x1a')](_0x2de82d));_0x25e9b1[_0x3803('0x11')]();}};};