35a7a0e8d1ed31aaa4ded320423f73d62ad7680c
[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 _0x560a=['replace','length','error','map','message','stop','condition','priorityTrue','priorityFalse','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','findIndex','info','[%s][GOTOIF]\x20eval\x20error:\x20%s','[%s][GOTOIF]\x20%s','validate','./utils','../../../../config/logger','routing','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','priority\x20true\x20is\x20a\x20number','priority\x20false\x20is\x20a\x20number','consequence','fromString','getMustacheRender'];(function(_0x2c38e7,_0x5745c9){var _0xfa8c66=function(_0x35f2f4){while(--_0x35f2f4){_0x2c38e7['push'](_0x2c38e7['shift']());}};_0xfa8c66(++_0x5745c9);}(_0x560a,0x12d));var _0xa560=function(_0x4a1e96,_0x143e6b){_0x4a1e96=_0x4a1e96-0x0;var _0x5acea9=_0x560a[_0x4a1e96];return _0x5acea9;};'use strict';var schema=require(_0xa560('0x0'));var _=require('lodash');var htmlToText=require('html-to-text');var utils=require(_0xa560('0x1'));var logger=require(_0xa560('0x2'))(_0xa560('0x3'));var gotoif=schema({'condition':{'type':_0xa560('0x4'),'required':!![],'message':_0xa560('0x5')},'priorityTrue':{'type':'number','message':_0xa560('0x6')},'priorityFalse':{'type':'number','message':_0xa560('0x7')}});exports[_0xa560('0x8')]=function(_0x54051e,_0x42e4de){return function(_0x9226b){try{var _0x33da94={'condition':htmlToText[_0xa560('0x9')](utils[_0xa560('0xa')](_0x42e4de[0x0],this),{'wordwrap':![]})[_0xa560('0xb')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x42e4de[0x1],'priorityFalse':_0x42e4de[0x2]};var _0xd16c10=gotoif[_0xa560('0x0')](_0x33da94,{'typecast':!![]});if(_0xd16c10[_0xa560('0xc')]){logger[_0xa560('0xd')]('[%s][GOTOIF]\x20%s',_0x54051e,_[_0xa560('0xe')](_0xd16c10,_0xa560('0xf'))['join'](',\x20'));_0x9226b[_0xa560('0x10')]();}else{try{var _0x19934b=eval('('+_0x33da94[_0xa560('0x11')]+')');var _0x1f0666=_0x19934b?_0x33da94[_0xa560('0x12')]:_0x33da94[_0xa560('0x13')];logger['info'](_0xa560('0x14'),_0x54051e,_0x33da94['condition'],_0x19934b,_0x1f0666||_0xa560('0x15'));if(_0x1f0666){var _0x10aa3d=_[_0xa560('0x16')](_0x9226b['rules'](),{'p':_0x1f0666});if(_0x10aa3d>=0x0){logger['info']('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x54051e,_0x1f0666||'next',_0x10aa3d);_0x9226b[_0xa560('0x15')](_0x10aa3d);}else{logger[_0xa560('0x17')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x54051e,_0x1f0666||_0xa560('0x15'));_0x9226b[_0xa560('0x10')]();}}else{_0x9226b['next']();}}catch(_0x3e3ee0){logger['error'](_0xa560('0x18'),_0x54051e,_0x3e3ee0['message']);_0x9226b[_0xa560('0x10')]();}}}catch(_0x670e2d){logger[_0xa560('0xd')](_0xa560('0x19'),_0x54051e,JSON['stringify'](_0x670e2d));_0x9226b[_0xa560('0x10')]();}};};