9dd700dff17038dd22670714b030c4d12eda16f0
[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 _0xfc0d=['../../../../config/logger','routing','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','priority\x20true\x20is\x20a\x20number','number','priority\x20false\x20is\x20a\x20number','consequence','fromString','getMustacheRender','length','error','[%s][GOTOIF]\x20%s','join','priorityTrue','priorityFalse','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','condition','next','findIndex','rules','info','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','message','stop','validate','html-to-text','./utils'];(function(_0x3147b7,_0x3c1426){var _0x18ec5e=function(_0x40ab3c){while(--_0x40ab3c){_0x3147b7['push'](_0x3147b7['shift']());}};_0x18ec5e(++_0x3c1426);}(_0xfc0d,0x1a1));var _0xdfc0=function(_0x596e12,_0x42f52b){_0x596e12=_0x596e12-0x0;var _0x445685=_0xfc0d[_0x596e12];return _0x445685;};'use strict';var schema=require(_0xdfc0('0x0'));var _=require('lodash');var htmlToText=require(_0xdfc0('0x1'));var utils=require(_0xdfc0('0x2'));var logger=require(_0xdfc0('0x3'))(_0xdfc0('0x4'));var gotoif=schema({'condition':{'type':_0xdfc0('0x5'),'required':!![],'message':_0xdfc0('0x6')},'priorityTrue':{'type':'number','message':_0xdfc0('0x7')},'priorityFalse':{'type':_0xdfc0('0x8'),'message':_0xdfc0('0x9')}});exports[_0xdfc0('0xa')]=function(_0x5cfca3,_0x312b24){return function(_0x38a0f8){try{var _0x5191e3={'condition':htmlToText[_0xdfc0('0xb')](utils[_0xdfc0('0xc')](_0x312b24[0x0],this),{'wordwrap':![]})['replace'](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x312b24[0x1],'priorityFalse':_0x312b24[0x2]};var _0xe35e58=gotoif[_0xdfc0('0x0')](_0x5191e3,{'typecast':!![]});if(_0xe35e58[_0xdfc0('0xd')]){logger[_0xdfc0('0xe')](_0xdfc0('0xf'),_0x5cfca3,_['map'](_0xe35e58,'message')[_0xdfc0('0x10')](',\x20'));_0x38a0f8['stop']();}else{try{var _0x249d8a=eval('('+_0x5191e3['condition']+')');var _0x389977=_0x249d8a?_0x5191e3[_0xdfc0('0x11')]:_0x5191e3[_0xdfc0('0x12')];logger['info'](_0xdfc0('0x13'),_0x5cfca3,_0x5191e3[_0xdfc0('0x14')],_0x249d8a,_0x389977||_0xdfc0('0x15'));if(_0x389977){var _0x4fdf28=_[_0xdfc0('0x16')](_0x38a0f8[_0xdfc0('0x17')](),{'p':_0x389977});if(_0x4fdf28>=0x0){logger['info']('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x5cfca3,_0x389977||_0xdfc0('0x15'),_0x4fdf28);_0x38a0f8['next'](_0x4fdf28);}else{logger[_0xdfc0('0x18')](_0xdfc0('0x19'),_0x5cfca3,_0x389977||'next');_0x38a0f8['stop']();}}else{_0x38a0f8[_0xdfc0('0x15')]();}}catch(_0x4ae2ec){logger[_0xdfc0('0xe')]('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x5cfca3,_0x4ae2ec[_0xdfc0('0x1a')]);_0x38a0f8['stop']();}}}catch(_0x562fb5){logger[_0xdfc0('0xe')]('[%s][GOTOIF]\x20%s',_0x5cfca3,JSON['stringify'](_0x562fb5));_0x38a0f8[_0xdfc0('0x1b')]();}};};