Built motion from commit 3c2ce842.|2.6.31
[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 _0x5769=['fromString','replace','length','error','map','join','condition','priorityTrue','priorityFalse','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','findIndex','rules','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','stop','[%s][GOTOIF]\x20%s','stringify','validate','html-to-text','../../../../config/logger','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number'];(function(_0x1c73ee,_0x19c0fc){var _0x3b88d4=function(_0xa471cf){while(--_0xa471cf){_0x1c73ee['push'](_0x1c73ee['shift']());}};_0x3b88d4(++_0x19c0fc);}(_0x5769,0x162));var _0x9576=function(_0x181600,_0x817634){_0x181600=_0x181600-0x0;var _0x3b65b6=_0x5769[_0x181600];return _0x3b65b6;};'use strict';var schema=require(_0x9576('0x0'));var _=require('lodash');var htmlToText=require(_0x9576('0x1'));var utils=require('./utils');var logger=require(_0x9576('0x2'))('routing');var gotoif=schema({'condition':{'type':_0x9576('0x3'),'required':!![],'message':_0x9576('0x4')},'priorityTrue':{'type':_0x9576('0x5'),'message':'priority\x20true\x20is\x20a\x20number'},'priorityFalse':{'type':_0x9576('0x5'),'message':'priority\x20false\x20is\x20a\x20number'}});exports['consequence']=function(_0x1dc682,_0x4b390a){return function(_0x3c1db1){try{var _0x4f229a={'condition':htmlToText[_0x9576('0x6')](utils['getMustacheRender'](_0x4b390a[0x0],this),{'wordwrap':![]})[_0x9576('0x7')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x4b390a[0x1],'priorityFalse':_0x4b390a[0x2]};var _0x12785b=gotoif[_0x9576('0x0')](_0x4f229a,{'typecast':!![]});if(_0x12785b[_0x9576('0x8')]){logger[_0x9576('0x9')]('[%s][GOTOIF]\x20%s',_0x1dc682,_[_0x9576('0xa')](_0x12785b,'message')[_0x9576('0xb')](',\x20'));_0x3c1db1['stop']();}else{try{var _0x1bd010=eval('('+_0x4f229a[_0x9576('0xc')]+')');var _0x52a1ce=_0x1bd010?_0x4f229a[_0x9576('0xd')]:_0x4f229a[_0x9576('0xe')];logger[_0x9576('0xf')](_0x9576('0x10'),_0x1dc682,_0x4f229a[_0x9576('0xc')],_0x1bd010,_0x52a1ce||_0x9576('0x11'));if(_0x52a1ce){var _0x19beb0=_[_0x9576('0x12')](_0x3c1db1[_0x9576('0x13')](),{'p':_0x52a1ce});if(_0x19beb0>=0x0){logger[_0x9576('0xf')](_0x9576('0x14'),_0x1dc682,_0x52a1ce||_0x9576('0x11'),_0x19beb0);_0x3c1db1['next'](_0x19beb0);}else{logger['info']('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x1dc682,_0x52a1ce||_0x9576('0x11'));_0x3c1db1[_0x9576('0x15')]();}}else{_0x3c1db1[_0x9576('0x11')]();}}catch(_0xf273d3){logger['error']('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x1dc682,_0xf273d3['message']);_0x3c1db1[_0x9576('0x15')]();}}}catch(_0x3ffe3a){logger[_0x9576('0x9')](_0x9576('0x16'),_0x1dc682,JSON[_0x9576('0x17')](_0x3ffe3a));_0x3c1db1[_0x9576('0x15')]();}};};