2a2dac18821e6c78bfbc7ef01a7943e9fbddd3ea
[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 _0xbaf1=['condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20true\x20is\x20a\x20number','priority\x20false\x20is\x20a\x20number','fromString','getMustacheRender','replace','length','error','[%s][GOTOIF]\x20%s','map','join','stop','condition','priorityTrue','priorityFalse','info','next','findIndex','rules','[%s][GOTOIF]\x20eval\x20error:\x20%s','message','stringify','validate','html-to-text','./utils','../../../../config/logger','routing','string'];(function(_0x49a283,_0x415e0c){var _0x44aadf=function(_0x3c7c72){while(--_0x3c7c72){_0x49a283['push'](_0x49a283['shift']());}};_0x44aadf(++_0x415e0c);}(_0xbaf1,0x1ca));var _0x1baf=function(_0x17eae8,_0x2bc1fa){_0x17eae8=_0x17eae8-0x0;var _0x5d6dcb=_0xbaf1[_0x17eae8];return _0x5d6dcb;};'use strict';var schema=require(_0x1baf('0x0'));var _=require('lodash');var htmlToText=require(_0x1baf('0x1'));var utils=require(_0x1baf('0x2'));var logger=require(_0x1baf('0x3'))(_0x1baf('0x4'));var gotoif=schema({'condition':{'type':_0x1baf('0x5'),'required':!![],'message':_0x1baf('0x6')},'priorityTrue':{'type':_0x1baf('0x7'),'message':_0x1baf('0x8')},'priorityFalse':{'type':'number','message':_0x1baf('0x9')}});exports['consequence']=function(_0x277874,_0x53b8ee){return function(_0x5d662b){try{var _0x3a50ea={'condition':htmlToText[_0x1baf('0xa')](utils[_0x1baf('0xb')](_0x53b8ee[0x0],this),{'wordwrap':![]})[_0x1baf('0xc')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x53b8ee[0x1],'priorityFalse':_0x53b8ee[0x2]};var _0x2361ae=gotoif[_0x1baf('0x0')](_0x3a50ea,{'typecast':!![]});if(_0x2361ae[_0x1baf('0xd')]){logger[_0x1baf('0xe')](_0x1baf('0xf'),_0x277874,_[_0x1baf('0x10')](_0x2361ae,'message')[_0x1baf('0x11')](',\x20'));_0x5d662b[_0x1baf('0x12')]();}else{try{var _0x2e77a0=eval('('+_0x3a50ea[_0x1baf('0x13')]+')');var _0x4b53ec=_0x2e77a0?_0x3a50ea[_0x1baf('0x14')]:_0x3a50ea[_0x1baf('0x15')];logger[_0x1baf('0x16')]('[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s',_0x277874,_0x3a50ea['condition'],_0x2e77a0,_0x4b53ec||_0x1baf('0x17'));if(_0x4b53ec){var _0x1d05a6=_[_0x1baf('0x18')](_0x5d662b[_0x1baf('0x19')](),{'p':_0x4b53ec});if(_0x1d05a6>=0x0){logger[_0x1baf('0x16')]('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x277874,_0x4b53ec||_0x1baf('0x17'),_0x1d05a6);_0x5d662b[_0x1baf('0x17')](_0x1d05a6);}else{logger[_0x1baf('0x16')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x277874,_0x4b53ec||_0x1baf('0x17'));_0x5d662b[_0x1baf('0x12')]();}}else{_0x5d662b[_0x1baf('0x17')]();}}catch(_0x5a0e04){logger['error'](_0x1baf('0x1a'),_0x277874,_0x5a0e04[_0x1baf('0x1b')]);_0x5d662b['stop']();}}}catch(_0x2c1052){logger[_0x1baf('0xe')](_0x1baf('0xf'),_0x277874,JSON[_0x1baf('0x1c')](_0x2c1052));_0x5d662b[_0x1baf('0x12')]();}};};