Built motion from commit 639a1a7f.|2.6.19
[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 _0x6c64=['info','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','stringify','validate','html-to-text','./utils','../../../../config/logger','routing','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20true\x20is\x20a\x20number','priority\x20false\x20is\x20a\x20number','getMustacheRender','replace','length','error','[%s][GOTOIF]\x20%s','map','message','stop','condition','priorityTrue','priorityFalse','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','findIndex','rules'];(function(_0x3822b1,_0x59a996){var _0xc31485=function(_0x5113e4){while(--_0x5113e4){_0x3822b1['push'](_0x3822b1['shift']());}};_0xc31485(++_0x59a996);}(_0x6c64,0x8a));var _0x46c6=function(_0x32ca64,_0x2bf03e){_0x32ca64=_0x32ca64-0x0;var _0x375492=_0x6c64[_0x32ca64];return _0x375492;};'use strict';var schema=require(_0x46c6('0x0'));var _=require('lodash');var htmlToText=require(_0x46c6('0x1'));var utils=require(_0x46c6('0x2'));var logger=require(_0x46c6('0x3'))(_0x46c6('0x4'));var gotoif=schema({'condition':{'type':'string','required':!![],'message':_0x46c6('0x5')},'priorityTrue':{'type':_0x46c6('0x6'),'message':_0x46c6('0x7')},'priorityFalse':{'type':_0x46c6('0x6'),'message':_0x46c6('0x8')}});exports['consequence']=function(_0x4deb8e,_0x190169){return function(_0x43db0d){try{var _0x3fad95={'condition':htmlToText['fromString'](utils[_0x46c6('0x9')](_0x190169[0x0],this),{'wordwrap':![]})[_0x46c6('0xa')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x190169[0x1],'priorityFalse':_0x190169[0x2]};var _0x60e7b6=gotoif[_0x46c6('0x0')](_0x3fad95,{'typecast':!![]});if(_0x60e7b6[_0x46c6('0xb')]){logger[_0x46c6('0xc')](_0x46c6('0xd'),_0x4deb8e,_[_0x46c6('0xe')](_0x60e7b6,_0x46c6('0xf'))['join'](',\x20'));_0x43db0d[_0x46c6('0x10')]();}else{try{var _0x45d718=eval('('+_0x3fad95[_0x46c6('0x11')]+')');var _0x2bbc4b=_0x45d718?_0x3fad95[_0x46c6('0x12')]:_0x3fad95[_0x46c6('0x13')];logger['info'](_0x46c6('0x14'),_0x4deb8e,_0x3fad95['condition'],_0x45d718,_0x2bbc4b||_0x46c6('0x15'));if(_0x2bbc4b){var _0x8b82a5=_[_0x46c6('0x16')](_0x43db0d[_0x46c6('0x17')](),{'p':_0x2bbc4b});if(_0x8b82a5>=0x0){logger['info']('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x4deb8e,_0x2bbc4b||'next',_0x8b82a5);_0x43db0d['next'](_0x8b82a5);}else{logger[_0x46c6('0x18')](_0x46c6('0x19'),_0x4deb8e,_0x2bbc4b||_0x46c6('0x15'));_0x43db0d[_0x46c6('0x10')]();}}else{_0x43db0d[_0x46c6('0x15')]();}}catch(_0x14770f){logger[_0x46c6('0xc')]('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x4deb8e,_0x14770f[_0x46c6('0xf')]);_0x43db0d['stop']();}}}catch(_0x4b3e7a){logger[_0x46c6('0xc')](_0x46c6('0xd'),_0x4deb8e,JSON[_0x46c6('0x1a')](_0x4b3e7a));_0x43db0d['stop']();}};};