Built motion from commit (unavailable).|2.5.4
[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 _0xf320=['[%s][GOTOIF]\x20%s','map','message','join','stop','condition','priorityTrue','priorityFalse','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','findIndex','rules','info','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','stringify','validate','./utils','../../../../config/logger','routing','string','number','priority\x20true\x20is\x20a\x20number','priority\x20false\x20is\x20a\x20number','getMustacheRender','replace','length','error'];(function(_0xa6ce28,_0x1f98da){var _0x40798a=function(_0x378aa7){while(--_0x378aa7){_0xa6ce28['push'](_0xa6ce28['shift']());}};_0x40798a(++_0x1f98da);}(_0xf320,0x11d));var _0x0f32=function(_0x34db17,_0x51dff0){_0x34db17=_0x34db17-0x0;var _0x5ba6b2=_0xf320[_0x34db17];return _0x5ba6b2;};'use strict';var schema=require(_0x0f32('0x0'));var _=require('lodash');var htmlToText=require('html-to-text');var utils=require(_0x0f32('0x1'));var logger=require(_0x0f32('0x2'))(_0x0f32('0x3'));var gotoif=schema({'condition':{'type':_0x0f32('0x4'),'required':!![],'message':'condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'priorityTrue':{'type':_0x0f32('0x5'),'message':_0x0f32('0x6')},'priorityFalse':{'type':'number','message':_0x0f32('0x7')}});exports['consequence']=function(_0x4952f4,_0xdb5d19){return function(_0x17289e){try{var _0x4dd99a={'condition':htmlToText['fromString'](utils[_0x0f32('0x8')](_0xdb5d19[0x0],this),{'wordwrap':![]})[_0x0f32('0x9')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0xdb5d19[0x1],'priorityFalse':_0xdb5d19[0x2]};var _0x3fed11=gotoif['validate'](_0x4dd99a,{'typecast':!![]});if(_0x3fed11[_0x0f32('0xa')]){logger[_0x0f32('0xb')](_0x0f32('0xc'),_0x4952f4,_[_0x0f32('0xd')](_0x3fed11,_0x0f32('0xe'))[_0x0f32('0xf')](',\x20'));_0x17289e[_0x0f32('0x10')]();}else{try{var _0x5eead8=eval('('+_0x4dd99a[_0x0f32('0x11')]+')');var _0x2eac4f=_0x5eead8?_0x4dd99a[_0x0f32('0x12')]:_0x4dd99a[_0x0f32('0x13')];logger['info'](_0x0f32('0x14'),_0x4952f4,_0x4dd99a['condition'],_0x5eead8,_0x2eac4f||_0x0f32('0x15'));if(_0x2eac4f){var _0x2d961a=_[_0x0f32('0x16')](_0x17289e[_0x0f32('0x17')](),{'p':_0x2eac4f});if(_0x2d961a>=0x0){logger[_0x0f32('0x18')]('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x4952f4,_0x2eac4f||_0x0f32('0x15'),_0x2d961a);_0x17289e['next'](_0x2d961a);}else{logger[_0x0f32('0x18')](_0x0f32('0x19'),_0x4952f4,_0x2eac4f||'next');_0x17289e[_0x0f32('0x10')]();}}else{_0x17289e[_0x0f32('0x15')]();}}catch(_0x516220){logger['error']('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x4952f4,_0x516220[_0x0f32('0xe')]);_0x17289e[_0x0f32('0x10')]();}}}catch(_0x326e56){logger['error'](_0x0f32('0xc'),_0x4952f4,JSON[_0x0f32('0x1a')](_0x326e56));_0x17289e[_0x0f32('0x10')]();}};};