Built motion from commit efa66e19.|2.6.22
[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 _0x2248=['map','message','stop','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','error','[%s][GOTOIF]\x20eval\x20error:\x20%s','stringify','validate','html-to-text','./utils','../../../../config/logger','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20true\x20is\x20a\x20number','priority\x20false\x20is\x20a\x20number','consequence','fromString','[%s][GOTOIF]\x20%s'];(function(_0x5a5121,_0x503400){var _0x55315d=function(_0x31918c){while(--_0x31918c){_0x5a5121['push'](_0x5a5121['shift']());}};_0x55315d(++_0x503400);}(_0x2248,0xe7));var _0x8224=function(_0x384f45,_0x194342){_0x384f45=_0x384f45-0x0;var _0x32ccb7=_0x2248[_0x384f45];return _0x32ccb7;};'use strict';var schema=require(_0x8224('0x0'));var _=require('lodash');var htmlToText=require(_0x8224('0x1'));var utils=require(_0x8224('0x2'));var logger=require(_0x8224('0x3'))('routing');var gotoif=schema({'condition':{'type':_0x8224('0x4'),'required':!![],'message':_0x8224('0x5')},'priorityTrue':{'type':_0x8224('0x6'),'message':_0x8224('0x7')},'priorityFalse':{'type':'number','message':_0x8224('0x8')}});exports[_0x8224('0x9')]=function(_0x1789a6,_0xb8e973){return function(_0x172ef8){try{var _0x4d9adf={'condition':htmlToText[_0x8224('0xa')](utils['getMustacheRender'](_0xb8e973[0x0],this),{'wordwrap':![]})['replace'](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0xb8e973[0x1],'priorityFalse':_0xb8e973[0x2]};var _0xc8e83=gotoif[_0x8224('0x0')](_0x4d9adf,{'typecast':!![]});if(_0xc8e83['length']){logger['error'](_0x8224('0xb'),_0x1789a6,_[_0x8224('0xc')](_0xc8e83,_0x8224('0xd'))['join'](',\x20'));_0x172ef8[_0x8224('0xe')]();}else{try{var _0x39e55a=eval('('+_0x4d9adf[_0x8224('0xf')]+')');var _0x231de8=_0x39e55a?_0x4d9adf[_0x8224('0x10')]:_0x4d9adf[_0x8224('0x11')];logger[_0x8224('0x12')](_0x8224('0x13'),_0x1789a6,_0x4d9adf[_0x8224('0xf')],_0x39e55a,_0x231de8||_0x8224('0x14'));if(_0x231de8){var _0x1702fa=_[_0x8224('0x15')](_0x172ef8[_0x8224('0x16')](),{'p':_0x231de8});if(_0x1702fa>=0x0){logger[_0x8224('0x12')](_0x8224('0x17'),_0x1789a6,_0x231de8||_0x8224('0x14'),_0x1702fa);_0x172ef8[_0x8224('0x14')](_0x1702fa);}else{logger['info']('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x1789a6,_0x231de8||'next');_0x172ef8['stop']();}}else{_0x172ef8['next']();}}catch(_0x18255a){logger[_0x8224('0x18')](_0x8224('0x19'),_0x1789a6,_0x18255a[_0x8224('0xd')]);_0x172ef8[_0x8224('0xe')]();}}}catch(_0x5c1666){logger[_0x8224('0x18')](_0x8224('0xb'),_0x1789a6,JSON[_0x8224('0x1a')](_0x5c1666));_0x172ef8['stop']();}};};