99c7fafce6eed920da1a084a6711a2d939bdc266
[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 _0xbe87=['error','[%s][GOTOIF]\x20%s','map','message','stop','condition','priorityTrue','priorityFalse','info','next','rules','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','[%s][GOTOIF]\x20priority\x20%s\x20not\x20found','[%s][GOTOIF]\x20eval\x20error:\x20%s','validate','html-to-text','./utils','../../../../config/logger','routing','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','priority\x20false\x20is\x20a\x20number','consequence','fromString','getMustacheRender','replace','length'];(function(_0x3bc730,_0xa7112b){var _0x4a7d76=function(_0xcd585){while(--_0xcd585){_0x3bc730['push'](_0x3bc730['shift']());}};_0x4a7d76(++_0xa7112b);}(_0xbe87,0x7e));var _0x7be8=function(_0x146ab9,_0x3d5bbe){_0x146ab9=_0x146ab9-0x0;var _0x1f192f=_0xbe87[_0x146ab9];return _0x1f192f;};'use strict';var schema=require(_0x7be8('0x0'));var _=require('lodash');var htmlToText=require(_0x7be8('0x1'));var utils=require(_0x7be8('0x2'));var logger=require(_0x7be8('0x3'))(_0x7be8('0x4'));var gotoif=schema({'condition':{'type':_0x7be8('0x5'),'required':!![],'message':_0x7be8('0x6')},'priorityTrue':{'type':'number','message':'priority\x20true\x20is\x20a\x20number'},'priorityFalse':{'type':_0x7be8('0x7'),'message':_0x7be8('0x8')}});exports[_0x7be8('0x9')]=function(_0x5792a0,_0x436edd){return function(_0x4ac9fa){try{var _0x27ba42={'condition':htmlToText[_0x7be8('0xa')](utils[_0x7be8('0xb')](_0x436edd[0x0],this),{'wordwrap':![]})[_0x7be8('0xc')](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x436edd[0x1],'priorityFalse':_0x436edd[0x2]};var _0x2937a3=gotoif[_0x7be8('0x0')](_0x27ba42,{'typecast':!![]});if(_0x2937a3[_0x7be8('0xd')]){logger[_0x7be8('0xe')](_0x7be8('0xf'),_0x5792a0,_[_0x7be8('0x10')](_0x2937a3,_0x7be8('0x11'))['join'](',\x20'));_0x4ac9fa[_0x7be8('0x12')]();}else{try{var _0x1d5f5b=eval('('+_0x27ba42[_0x7be8('0x13')]+')');var _0x5b27bc=_0x1d5f5b?_0x27ba42[_0x7be8('0x14')]:_0x27ba42[_0x7be8('0x15')];logger[_0x7be8('0x16')]('[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s',_0x5792a0,_0x27ba42[_0x7be8('0x13')],_0x1d5f5b,_0x5b27bc||_0x7be8('0x17'));if(_0x5b27bc){var _0x10f772=_['findIndex'](_0x4ac9fa[_0x7be8('0x18')](),{'p':_0x5b27bc});if(_0x10f772>=0x0){logger['info'](_0x7be8('0x19'),_0x5792a0,_0x5b27bc||'next',_0x10f772);_0x4ac9fa[_0x7be8('0x17')](_0x10f772);}else{logger[_0x7be8('0x16')](_0x7be8('0x1a'),_0x5792a0,_0x5b27bc||_0x7be8('0x17'));_0x4ac9fa[_0x7be8('0x12')]();}}else{_0x4ac9fa[_0x7be8('0x17')]();}}catch(_0x40a270){logger['error'](_0x7be8('0x1b'),_0x5792a0,_0x40a270['message']);_0x4ac9fa[_0x7be8('0x12')]();}}}catch(_0x4585bd){logger[_0x7be8('0xe')]('[%s][GOTOIF]\x20%s',_0x5792a0,JSON['stringify'](_0x4585bd));_0x4ac9fa['stop']();}};};