e026ec5a09f3f6a251357a4126b71238017cbc20
[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 _0x12ff=['info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','findIndex','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','error','message','validate','html-to-text','./utils','../../../../config/logger','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20true\x20is\x20a\x20number','priority\x20false\x20is\x20a\x20number','fromString','getMustacheRender','replace','length','[%s][GOTOIF]\x20%s','map','stop','condition','priorityTrue'];(function(_0x32c36d,_0x426f5d){var _0xa933ab=function(_0x1a4cfe){while(--_0x1a4cfe){_0x32c36d['push'](_0x32c36d['shift']());}};_0xa933ab(++_0x426f5d);}(_0x12ff,0x9e));var _0xf12f=function(_0x30bef2,_0x3d4186){_0x30bef2=_0x30bef2-0x0;var _0x567d67=_0x12ff[_0x30bef2];return _0x567d67;};'use strict';var schema=require(_0xf12f('0x0'));var _=require('lodash');var htmlToText=require(_0xf12f('0x1'));var utils=require(_0xf12f('0x2'));var logger=require(_0xf12f('0x3'))('routing');var gotoif=schema({'condition':{'type':'string','required':!![],'message':_0xf12f('0x4')},'priorityTrue':{'type':_0xf12f('0x5'),'message':_0xf12f('0x6')},'priorityFalse':{'type':'number','message':_0xf12f('0x7')}});exports['consequence']=function(_0x10bce5,_0x58119e){return function(_0x528dc4){try{var _0x53125f={'condition':htmlToText[_0xf12f('0x8')](utils[_0xf12f('0x9')](_0x58119e[0x0],this),{'wordwrap':![]})[_0xf12f('0xa')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x58119e[0x1],'priorityFalse':_0x58119e[0x2]};var _0x422a75=gotoif[_0xf12f('0x0')](_0x53125f,{'typecast':!![]});if(_0x422a75[_0xf12f('0xb')]){logger['error'](_0xf12f('0xc'),_0x10bce5,_[_0xf12f('0xd')](_0x422a75,'message')['join'](',\x20'));_0x528dc4[_0xf12f('0xe')]();}else{try{var _0x928994=eval('('+_0x53125f[_0xf12f('0xf')]+')');var _0xaa6e5a=_0x928994?_0x53125f[_0xf12f('0x10')]:_0x53125f['priorityFalse'];logger[_0xf12f('0x11')](_0xf12f('0x12'),_0x10bce5,_0x53125f[_0xf12f('0xf')],_0x928994,_0xaa6e5a||_0xf12f('0x13'));if(_0xaa6e5a){var _0x450d0d=_[_0xf12f('0x14')](_0x528dc4['rules'](),{'p':_0xaa6e5a});if(_0x450d0d>=0x0){logger[_0xf12f('0x11')](_0xf12f('0x15'),_0x10bce5,_0xaa6e5a||'next',_0x450d0d);_0x528dc4[_0xf12f('0x13')](_0x450d0d);}else{logger[_0xf12f('0x11')](_0xf12f('0x16'),_0x10bce5,_0xaa6e5a||_0xf12f('0x13'));_0x528dc4[_0xf12f('0xe')]();}}else{_0x528dc4[_0xf12f('0x13')]();}}catch(_0x481580){logger[_0xf12f('0x17')]('[%s][GOTOIF]\x20eval\x20error:\x20%s',_0x10bce5,_0x481580[_0xf12f('0x18')]);_0x528dc4[_0xf12f('0xe')]();}}}catch(_0xf74abf){logger[_0xf12f('0x17')](_0xf12f('0xc'),_0x10bce5,JSON['stringify'](_0xf74abf));_0x528dc4[_0xf12f('0xe')]();}};};