Built motion from commit bbec7235.|2.6.20
[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 _0xa608=['condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','priority\x20true\x20is\x20a\x20number','number','consequence','fromString','getMustacheRender','replace','length','error','[%s][GOTOIF]\x20%s','map','join','condition','priorityTrue','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','[%s][GOTOIF]\x20eval\x20error:\x20%s','message','stop','stringify','validate','lodash','html-to-text','./utils','../../../../config/logger','string'];(function(_0x46f6d8,_0x2c8754){var _0x32455c=function(_0x129b93){while(--_0x129b93){_0x46f6d8['push'](_0x46f6d8['shift']());}};_0x32455c(++_0x2c8754);}(_0xa608,0x81));var _0x8a60=function(_0xdb1c42,_0x4d6ce0){_0xdb1c42=_0xdb1c42-0x0;var _0x51ee81=_0xa608[_0xdb1c42];return _0x51ee81;};'use strict';var schema=require(_0x8a60('0x0'));var _=require(_0x8a60('0x1'));var htmlToText=require(_0x8a60('0x2'));var utils=require(_0x8a60('0x3'));var logger=require(_0x8a60('0x4'))('routing');var gotoif=schema({'condition':{'type':_0x8a60('0x5'),'required':!![],'message':_0x8a60('0x6')},'priorityTrue':{'type':'number','message':_0x8a60('0x7')},'priorityFalse':{'type':_0x8a60('0x8'),'message':'priority\x20false\x20is\x20a\x20number'}});exports[_0x8a60('0x9')]=function(_0x54214c,_0x55cb70){return function(_0x3e9938){try{var _0x13036e={'condition':htmlToText[_0x8a60('0xa')](utils[_0x8a60('0xb')](_0x55cb70[0x0],this),{'wordwrap':![]})[_0x8a60('0xc')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x55cb70[0x1],'priorityFalse':_0x55cb70[0x2]};var _0xdc0c25=gotoif[_0x8a60('0x0')](_0x13036e,{'typecast':!![]});if(_0xdc0c25[_0x8a60('0xd')]){logger[_0x8a60('0xe')](_0x8a60('0xf'),_0x54214c,_[_0x8a60('0x10')](_0xdc0c25,'message')[_0x8a60('0x11')](',\x20'));_0x3e9938['stop']();}else{try{var _0x34dfa1=eval('('+_0x13036e[_0x8a60('0x12')]+')');var _0x32a319=_0x34dfa1?_0x13036e[_0x8a60('0x13')]:_0x13036e['priorityFalse'];logger[_0x8a60('0x14')](_0x8a60('0x15'),_0x54214c,_0x13036e[_0x8a60('0x12')],_0x34dfa1,_0x32a319||_0x8a60('0x16'));if(_0x32a319){var _0x1e19ea=_['findIndex'](_0x3e9938['rules'](),{'p':_0x32a319});if(_0x1e19ea>=0x0){logger['info']('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x54214c,_0x32a319||_0x8a60('0x16'),_0x1e19ea);_0x3e9938[_0x8a60('0x16')](_0x1e19ea);}else{logger[_0x8a60('0x14')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x54214c,_0x32a319||'next');_0x3e9938['stop']();}}else{_0x3e9938[_0x8a60('0x16')]();}}catch(_0x14e933){logger[_0x8a60('0xe')](_0x8a60('0x17'),_0x54214c,_0x14e933[_0x8a60('0x18')]);_0x3e9938[_0x8a60('0x19')]();}}}catch(_0x4487b4){logger[_0x8a60('0xe')](_0x8a60('0xf'),_0x54214c,JSON[_0x8a60('0x1a')](_0x4487b4));_0x3e9938[_0x8a60('0x19')]();}};};