Built motion from commit 25580385.|2.6.2
[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 _0x5424=['map','message','join','stop','priorityFalse','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','condition','next','findIndex','rules','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','[%s][GOTOIF]\x20eval\x20error:\x20%s','stringify','validate','./utils','../../../../config/logger','routing','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20false\x20is\x20a\x20number','consequence','fromString','getMustacheRender','replace','[%s][GOTOIF]\x20%s'];(function(_0x38d7d6,_0x3c52ca){var _0x4be128=function(_0x4725e2){while(--_0x4725e2){_0x38d7d6['push'](_0x38d7d6['shift']());}};_0x4be128(++_0x3c52ca);}(_0x5424,0x7a));var _0x4542=function(_0x5b4615,_0x3fad71){_0x5b4615=_0x5b4615-0x0;var _0x44eb78=_0x5424[_0x5b4615];return _0x44eb78;};'use strict';var schema=require(_0x4542('0x0'));var _=require('lodash');var htmlToText=require('html-to-text');var utils=require(_0x4542('0x1'));var logger=require(_0x4542('0x2'))(_0x4542('0x3'));var gotoif=schema({'condition':{'type':_0x4542('0x4'),'required':!![],'message':_0x4542('0x5')},'priorityTrue':{'type':'number','message':'priority\x20true\x20is\x20a\x20number'},'priorityFalse':{'type':_0x4542('0x6'),'message':_0x4542('0x7')}});exports[_0x4542('0x8')]=function(_0x4baf58,_0x1fdc10){return function(_0x4f4cb6){try{var _0x3c2c03={'condition':htmlToText[_0x4542('0x9')](utils[_0x4542('0xa')](_0x1fdc10[0x0],this),{'wordwrap':![]})[_0x4542('0xb')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x1fdc10[0x1],'priorityFalse':_0x1fdc10[0x2]};var _0x555a40=gotoif[_0x4542('0x0')](_0x3c2c03,{'typecast':!![]});if(_0x555a40['length']){logger['error'](_0x4542('0xc'),_0x4baf58,_[_0x4542('0xd')](_0x555a40,_0x4542('0xe'))[_0x4542('0xf')](',\x20'));_0x4f4cb6[_0x4542('0x10')]();}else{try{var _0x5769f0=eval('('+_0x3c2c03['condition']+')');var _0x247362=_0x5769f0?_0x3c2c03['priorityTrue']:_0x3c2c03[_0x4542('0x11')];logger[_0x4542('0x12')](_0x4542('0x13'),_0x4baf58,_0x3c2c03[_0x4542('0x14')],_0x5769f0,_0x247362||_0x4542('0x15'));if(_0x247362){var _0x1e342a=_[_0x4542('0x16')](_0x4f4cb6[_0x4542('0x17')](),{'p':_0x247362});if(_0x1e342a>=0x0){logger['info']('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x4baf58,_0x247362||_0x4542('0x15'),_0x1e342a);_0x4f4cb6[_0x4542('0x15')](_0x1e342a);}else{logger[_0x4542('0x12')](_0x4542('0x18'),_0x4baf58,_0x247362||_0x4542('0x15'));_0x4f4cb6[_0x4542('0x10')]();}}else{_0x4f4cb6[_0x4542('0x15')]();}}catch(_0x14168e){logger['error'](_0x4542('0x19'),_0x4baf58,_0x14168e['message']);_0x4f4cb6[_0x4542('0x10')]();}}}catch(_0x164302){logger['error'](_0x4542('0xc'),_0x4baf58,JSON[_0x4542('0x1a')](_0x164302));_0x4f4cb6['stop']();}};};