Built motion from commit 9d0783e6.|2.6.13
[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 _0x92a0=['string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20true\x20is\x20a\x20number','priority\x20false\x20is\x20a\x20number','consequence','fromString','error','[%s][GOTOIF]\x20%s','join','condition','priorityTrue','priorityFalse','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','rules','info','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','message','stop','stringify','validate','html-to-text','./utils','../../../../config/logger','routing'];(function(_0x35bf58,_0x320ba4){var _0x27e848=function(_0x1e07c1){while(--_0x1e07c1){_0x35bf58['push'](_0x35bf58['shift']());}};_0x27e848(++_0x320ba4);}(_0x92a0,0x13f));var _0x092a=function(_0x548483,_0x5e53ab){_0x548483=_0x548483-0x0;var _0x53afbd=_0x92a0[_0x548483];return _0x53afbd;};'use strict';var schema=require(_0x092a('0x0'));var _=require('lodash');var htmlToText=require(_0x092a('0x1'));var utils=require(_0x092a('0x2'));var logger=require(_0x092a('0x3'))(_0x092a('0x4'));var gotoif=schema({'condition':{'type':_0x092a('0x5'),'required':!![],'message':_0x092a('0x6')},'priorityTrue':{'type':_0x092a('0x7'),'message':_0x092a('0x8')},'priorityFalse':{'type':'number','message':_0x092a('0x9')}});exports[_0x092a('0xa')]=function(_0x446ff5,_0x29182f){return function(_0x4f36b2){try{var _0x2a0c6c={'condition':htmlToText[_0x092a('0xb')](utils['getMustacheRender'](_0x29182f[0x0],this),{'wordwrap':![]})['replace'](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x29182f[0x1],'priorityFalse':_0x29182f[0x2]};var _0x2ead2b=gotoif['validate'](_0x2a0c6c,{'typecast':!![]});if(_0x2ead2b['length']){logger[_0x092a('0xc')](_0x092a('0xd'),_0x446ff5,_['map'](_0x2ead2b,'message')[_0x092a('0xe')](',\x20'));_0x4f36b2['stop']();}else{try{var _0x398d8a=eval('('+_0x2a0c6c[_0x092a('0xf')]+')');var _0x46b557=_0x398d8a?_0x2a0c6c[_0x092a('0x10')]:_0x2a0c6c[_0x092a('0x11')];logger['info'](_0x092a('0x12'),_0x446ff5,_0x2a0c6c[_0x092a('0xf')],_0x398d8a,_0x46b557||_0x092a('0x13'));if(_0x46b557){var _0x1ee3aa=_['findIndex'](_0x4f36b2[_0x092a('0x14')](),{'p':_0x46b557});if(_0x1ee3aa>=0x0){logger[_0x092a('0x15')](_0x092a('0x16'),_0x446ff5,_0x46b557||_0x092a('0x13'),_0x1ee3aa);_0x4f36b2[_0x092a('0x13')](_0x1ee3aa);}else{logger[_0x092a('0x15')](_0x092a('0x17'),_0x446ff5,_0x46b557||_0x092a('0x13'));_0x4f36b2['stop']();}}else{_0x4f36b2[_0x092a('0x13')]();}}catch(_0x1c1713){logger[_0x092a('0xc')]('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x446ff5,_0x1c1713[_0x092a('0x18')]);_0x4f36b2[_0x092a('0x19')]();}}}catch(_0x28efd8){logger['error'](_0x092a('0xd'),_0x446ff5,JSON[_0x092a('0x1a')](_0x28efd8));_0x4f36b2['stop']();}};};