26e031803d866897c6a751ac2c3a0b91dc176fb7
[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 _0xf330=['length','error','[%s][GOTOIF]\x20%s','join','stop','condition','priorityFalse','info','[%s][GOTOIF]\x20condition\x20%s\x20is\x20%s\x20try\x20goto\x20priority\x20%s','next','rules','[%s][GOTOIF]\x20priority\x20%s\x20found\x20at\x20index:\x20%s','[%s][GOTOIF]\x20eval\x20error:\x20%s','message','stringify','lodash','html-to-text','./utils','string','condition\x20is\x20a\x20string\x20and\x20it\x20is\x20required','priority\x20true\x20is\x20a\x20number','number','consequence','fromString','getMustacheRender','validate'];(function(_0x57b54c,_0x54ce0d){var _0x59cc19=function(_0xa33bc6){while(--_0xa33bc6){_0x57b54c['push'](_0x57b54c['shift']());}};_0x59cc19(++_0x54ce0d);}(_0xf330,0x161));var _0x0f33=function(_0x44c45d,_0x58b166){_0x44c45d=_0x44c45d-0x0;var _0x2b55ec=_0xf330[_0x44c45d];return _0x2b55ec;};'use strict';var schema=require('validate');var _=require(_0x0f33('0x0'));var htmlToText=require(_0x0f33('0x1'));var utils=require(_0x0f33('0x2'));var logger=require('../../../../config/logger')('routing');var gotoif=schema({'condition':{'type':_0x0f33('0x3'),'required':!![],'message':_0x0f33('0x4')},'priorityTrue':{'type':'number','message':_0x0f33('0x5')},'priorityFalse':{'type':_0x0f33('0x6'),'message':'priority\x20false\x20is\x20a\x20number'}});exports[_0x0f33('0x7')]=function(_0x7e6f4d,_0x5260d1){return function(_0x1f75fb){try{var _0x5cf953={'condition':htmlToText[_0x0f33('0x8')](utils[_0x0f33('0x9')](_0x5260d1[0x0],this),{'wordwrap':![]})['replace'](/<\/?[^>]+(>|$)/g,''),'priorityTrue':_0x5260d1[0x1],'priorityFalse':_0x5260d1[0x2]};var _0x120ed7=gotoif[_0x0f33('0xa')](_0x5cf953,{'typecast':!![]});if(_0x120ed7[_0x0f33('0xb')]){logger[_0x0f33('0xc')](_0x0f33('0xd'),_0x7e6f4d,_['map'](_0x120ed7,'message')[_0x0f33('0xe')](',\x20'));_0x1f75fb[_0x0f33('0xf')]();}else{try{var _0x1fffb5=eval('('+_0x5cf953[_0x0f33('0x10')]+')');var _0x35a2ec=_0x1fffb5?_0x5cf953['priorityTrue']:_0x5cf953[_0x0f33('0x11')];logger[_0x0f33('0x12')](_0x0f33('0x13'),_0x7e6f4d,_0x5cf953[_0x0f33('0x10')],_0x1fffb5,_0x35a2ec||_0x0f33('0x14'));if(_0x35a2ec){var _0x46825c=_['findIndex'](_0x1f75fb[_0x0f33('0x15')](),{'p':_0x35a2ec});if(_0x46825c>=0x0){logger[_0x0f33('0x12')](_0x0f33('0x16'),_0x7e6f4d,_0x35a2ec||_0x0f33('0x14'),_0x46825c);_0x1f75fb[_0x0f33('0x14')](_0x46825c);}else{logger[_0x0f33('0x12')]('[%s][GOTOIF]\x20priority\x20%s\x20not\x20found',_0x7e6f4d,_0x35a2ec||_0x0f33('0x14'));_0x1f75fb[_0x0f33('0xf')]();}}else{_0x1f75fb[_0x0f33('0x14')]();}}catch(_0x136efb){logger[_0x0f33('0xc')](_0x0f33('0x17'),_0x7e6f4d,_0x136efb[_0x0f33('0x18')]);_0x1f75fb[_0x0f33('0xf')]();}}}catch(_0x349972){logger['error'](_0x0f33('0xd'),_0x7e6f4d,JSON[_0x0f33('0x19')](_0x349972));_0x1f75fb[_0x0f33('0xf')]();}};};