57da6561750b99f5ad33eab65a383f0b6c9745cd
[motion2.git] / server / services / ami / trigger / urlforward / index.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 _0x23b9=['statusCode','catch','%s\x20%s\x20failed\x20with\x20status:\x20%d\x20and\x20error:\x20%s\x20%s','name','message','util','lodash','../../../../config/logger','trigger','exec','data1','toUpperCase','render','data2','data5','number','headers','parse','data6','stack','GET','DELETE','data7','body','error','body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format','format','stringify','then','info'];(function(_0x12a554,_0x3d7ef8){var _0x244ba0=function(_0x5eb5ff){while(--_0x5eb5ff){_0x12a554['push'](_0x12a554['shift']());}};_0x244ba0(++_0x3d7ef8);}(_0x23b9,0x1e5));var _0x923b=function(_0x1b6349,_0x2116eb){_0x1b6349=_0x1b6349-0x0;var _0x4d0338=_0x23b9[_0x1b6349];return _0x4d0338;};'use strict';var rp=require('request-promise');var util=require(_0x923b('0x0'));var _=require(_0x923b('0x1'));var Mustache=require('mustache');var logger=require(_0x923b('0x2'))(_0x923b('0x3'));exports[_0x923b('0x4')]=function(_0x2b3cda,_0x42ef14){var _0x2e6084,_0x1a96c8;var _0x24f703={'method':_0x2b3cda[_0x923b('0x5')][_0x923b('0x6')](),'uri':Mustache[_0x923b('0x7')](_0x2b3cda[_0x923b('0x8')],_0x42ef14),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0x2b3cda[_0x923b('0x9')])===_0x923b('0xa')&&parseInt(_0x2b3cda[_0x923b('0x9')])>=0x1&&parseInt(_0x2b3cda[_0x923b('0x9')])<=0xa?parseInt(_0x2b3cda['data5'])*0x3e8:0x5*0x3e8};try{_0x24f703[_0x923b('0xb')]=_0x2b3cda['data6']?JSON[_0x923b('0xc')](Mustache[_0x923b('0x7')](_0x2b3cda[_0x923b('0xd')],_0x42ef14)):{};}catch(_0x4ad4fa){logger['error'](_0x4ad4fa[_0x923b('0xe')]);}switch(_0x2b3cda[_0x923b('0x5')][_0x923b('0x6')]()){case _0x923b('0xf'):case _0x923b('0x10'):_0x2e6084=null;_0x24f703['qs']=_0x42ef14;break;case'POST':case'PUT':if(_0x2b3cda['data7']){try{_0x2e6084=JSON[_0x923b('0xc')](Mustache['render'](_0x2b3cda[_0x923b('0x11')],_0x42ef14));_0x24f703[_0x923b('0x12')]=_0x2e6084;}catch(_0x1e0c09){logger[_0x923b('0x13')](_0x1e0c09[_0x923b('0xe')]);logger[_0x923b('0x13')](_0x923b('0x14'));}}else{_0x2e6084=_0x42ef14;_0x24f703[_0x923b('0x12')]=_0x2e6084;}break;}logger['info'](util[_0x923b('0x15')]('%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s',_0x2b3cda[_0x923b('0x5')],_0x2b3cda['data2'],JSON[_0x923b('0x16')](_0x24f703)));rp(_0x24f703)[_0x923b('0x17')](function(_0x404101){_0x2e6084=!_['isNil'](_0x2e6084)?',\x20request\x20body:\x20'+_0x2e6084:'';_0x1a96c8=typeof _0x404101[_0x923b('0x12')]==='object'?JSON[_0x923b('0x16')](_0x404101[_0x923b('0x12')]):_0x404101[_0x923b('0x12')];logger[_0x923b('0x18')](util['format']('%s\x20%s\x20succeeded\x20with\x20status:\x20%d\x20and\x20response:\x20%s',_0x2b3cda[_0x923b('0x5')],_0x2b3cda[_0x923b('0x8')],_0x404101[_0x923b('0x19')],_0x1a96c8));})[_0x923b('0x1a')](function(_0x4485a9){logger[_0x923b('0x13')](util[_0x923b('0x15')](_0x923b('0x1b'),_0x2b3cda['data1'],_0x2b3cda['data2'],_0x4485a9[_0x923b('0x19')],_0x4485a9[_0x923b('0x1c')],_0x4485a9[_0x923b('0x1d')]));});};