df4d7d843089922e07e049b6e2c39974a38bd42e
[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 _0x6c58=['priorityTrue','priorityFalse','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','findIndex','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','error','[%s][GOTOIF]\x20eval\x20error:\x20%s','stringify','lodash','html-to-text','./utils','../../../../config/logger','routing','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','priority\x20true\x20is\x20a\x20number','fromString','getMustacheRender','replace','validate','length','[%s][GOTOIF]\x20%s','map','message','join','stop'];(function(_0x138d3d,_0x41a640){var _0x2e1cac=function(_0x1a2a8b){while(--_0x1a2a8b){_0x138d3d['push'](_0x138d3d['shift']());}};_0x2e1cac(++_0x41a640);}(_0x6c58,0x106));var _0x86c5=function(_0x40ac5e,_0x2de228){_0x40ac5e=_0x40ac5e-0x0;var _0x2839d6=_0x6c58[_0x40ac5e];return _0x2839d6;};'use strict';var schema=require('validate');var _=require(_0x86c5('0x0'));var htmlToText=require(_0x86c5('0x1'));var utils=require(_0x86c5('0x2'));var logger=require(_0x86c5('0x3'))(_0x86c5('0x4'));var gotoif=schema({'condition':{'type':_0x86c5('0x5'),'required':!![],'message':_0x86c5('0x6')},'priorityTrue':{'type':'number','message':_0x86c5('0x7')},'priorityFalse':{'type':'number','message':'priority\x20false\x20is\x20a\x20number'}});exports['consequence']=function(_0x37956d,_0x53fa8c){return function(_0x9fde52){try{var _0x5725eb={'condition':htmlToText[_0x86c5('0x8')](utils[_0x86c5('0x9')](_0x53fa8c[0x0],this),{'wordwrap':![]})[_0x86c5('0xa')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x53fa8c[0x1],'priorityFalse':_0x53fa8c[0x2]};var _0x27f094=gotoif[_0x86c5('0xb')](_0x5725eb,{'typecast':!![]});if(_0x27f094[_0x86c5('0xc')]){logger['error'](_0x86c5('0xd'),_0x37956d,_[_0x86c5('0xe')](_0x27f094,_0x86c5('0xf'))[_0x86c5('0x10')](',\x20'));_0x9fde52[_0x86c5('0x11')]();}else{try{var _0x475f37=eval('('+_0x5725eb['condition']+')');var _0x5df037=_0x475f37?_0x5725eb[_0x86c5('0x12')]:_0x5725eb[_0x86c5('0x13')];logger[_0x86c5('0x14')](_0x86c5('0x15'),_0x37956d,_0x5725eb['condition'],_0x475f37,_0x5df037||_0x86c5('0x16'));if(_0x5df037){var _0x167641=_[_0x86c5('0x17')](_0x9fde52['rules'](),{'p':_0x5df037});if(_0x167641>=0x0){logger[_0x86c5('0x14')]('[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s',_0x37956d,_0x5df037||'next',_0x167641);_0x9fde52[_0x86c5('0x16')](_0x167641);}else{logger[_0x86c5('0x14')](_0x86c5('0x18'),_0x37956d,_0x5df037||'next');_0x9fde52[_0x86c5('0x11')]();}}else{_0x9fde52[_0x86c5('0x16')]();}}catch(_0x47262c){logger[_0x86c5('0x19')](_0x86c5('0x1a'),_0x37956d,_0x47262c[_0x86c5('0xf')]);_0x9fde52['stop']();}}}catch(_0xce23ae){logger[_0x86c5('0x19')](_0x86c5('0xd'),_0x37956d,JSON[_0x86c5('0x1b')](_0xce23ae));_0x9fde52[_0x86c5('0x11')]();}};};