Built motion from commit (unavailable).|2.5.29
[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 _0xad77=['condition','priorityFalse','info','next','findIndex','rules','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','error','[%s][GOTOIF]\x20eval\x20error:\x20%s','stringify','validate','./utils','../../../../config/logger','routing','string','number','priority\x20true\x20is\x20a\x20number','priority\x20false\x20is\x20a\x20number','consequence','getMustacheRender','length','[%s][GOTOIF]\x20%s','message','join','stop'];(function(_0x533e92,_0xf9623d){var _0xcb078d=function(_0x283a66){while(--_0x283a66){_0x533e92['push'](_0x533e92['shift']());}};_0xcb078d(++_0xf9623d);}(_0xad77,0x8d));var _0x7ad7=function(_0x3c8e36,_0x422420){_0x3c8e36=_0x3c8e36-0x0;var _0x31d8a5=_0xad77[_0x3c8e36];return _0x31d8a5;};'use strict';var schema=require(_0x7ad7('0x0'));var _=require('lodash');var htmlToText=require('html-to-text');var utils=require(_0x7ad7('0x1'));var logger=require(_0x7ad7('0x2'))(_0x7ad7('0x3'));var gotoif=schema({'condition':{'type':_0x7ad7('0x4'),'required':!![],'message':'condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'priorityTrue':{'type':_0x7ad7('0x5'),'message':_0x7ad7('0x6')},'priorityFalse':{'type':_0x7ad7('0x5'),'message':_0x7ad7('0x7')}});exports[_0x7ad7('0x8')]=function(_0x320f33,_0x56da7b){return function(_0x165c97){try{var _0x103576={'condition':htmlToText['fromString'](utils[_0x7ad7('0x9')](_0x56da7b[0x0],this),{'wordwrap':![]})['replace'](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x56da7b[0x1],'priorityFalse':_0x56da7b[0x2]};var _0x397a2f=gotoif[_0x7ad7('0x0')](_0x103576,{'typecast':!![]});if(_0x397a2f[_0x7ad7('0xa')]){logger['error'](_0x7ad7('0xb'),_0x320f33,_['map'](_0x397a2f,_0x7ad7('0xc'))[_0x7ad7('0xd')](',\x20'));_0x165c97[_0x7ad7('0xe')]();}else{try{var _0x5c9d9e=eval('('+_0x103576[_0x7ad7('0xf')]+')');var _0x185545=_0x5c9d9e?_0x103576['priorityTrue']:_0x103576[_0x7ad7('0x10')];logger[_0x7ad7('0x11')]('[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s',_0x320f33,_0x103576['condition'],_0x5c9d9e,_0x185545||_0x7ad7('0x12'));if(_0x185545){var _0x46ccac=_[_0x7ad7('0x13')](_0x165c97[_0x7ad7('0x14')](),{'p':_0x185545});if(_0x46ccac>=0x0){logger[_0x7ad7('0x11')](_0x7ad7('0x15'),_0x320f33,_0x185545||_0x7ad7('0x12'),_0x46ccac);_0x165c97['next'](_0x46ccac);}else{logger['info'](_0x7ad7('0x16'),_0x320f33,_0x185545||_0x7ad7('0x12'));_0x165c97[_0x7ad7('0xe')]();}}else{_0x165c97[_0x7ad7('0x12')]();}}catch(_0x5d600a){logger[_0x7ad7('0x17')](_0x7ad7('0x18'),_0x320f33,_0x5d600a[_0x7ad7('0xc')]);_0x165c97['stop']();}}}catch(_0x10b221){logger['error']('[%s][GOTOIF]\x20%s',_0x320f33,JSON[_0x7ad7('0x19')](_0x10b221));_0x165c97[_0x7ad7('0xe')]();}};};