134d706d9c79b1152ba6069046cb3a427270c486
[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 _0xc25b=['trigger','exec','data1','toUpperCase','render','data2','data5','number','headers','data6','parse','stack','GET','POST','data7','body','error','body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format','info','format','%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s','stringify','then','isNil',',\x20request\x20body:\x20','%s\x20%s\x20succeeded\x20with\x20status:\x20%d\x20and\x20response:\x20%s','statusCode','catch','%s\x20%s\x20failed\x20with\x20status:\x20%d\x20and\x20error:\x20%s\x20%s','message','util','lodash','mustache'];(function(_0xfda486,_0x518041){var _0x20a9d5=function(_0x251386){while(--_0x251386){_0xfda486['push'](_0xfda486['shift']());}};_0x20a9d5(++_0x518041);}(_0xc25b,0x189));var _0xbc25=function(_0x30f57d,_0x2e6777){_0x30f57d=_0x30f57d-0x0;var _0x6f17a4=_0xc25b[_0x30f57d];return _0x6f17a4;};'use strict';var rp=require('request-promise');var util=require(_0xbc25('0x0'));var _=require(_0xbc25('0x1'));var Mustache=require(_0xbc25('0x2'));var logger=require('../../../../config/logger')(_0xbc25('0x3'));exports[_0xbc25('0x4')]=function(_0x46651c,_0x36930c){var _0x2b50f1,_0x447c0b;var _0x5eeb2c={'method':_0x46651c[_0xbc25('0x5')][_0xbc25('0x6')](),'uri':Mustache[_0xbc25('0x7')](_0x46651c[_0xbc25('0x8')],_0x36930c),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0x46651c[_0xbc25('0x9')])===_0xbc25('0xa')&&parseInt(_0x46651c[_0xbc25('0x9')])>=0x1&&parseInt(_0x46651c[_0xbc25('0x9')])<=0xa?parseInt(_0x46651c[_0xbc25('0x9')])*0x3e8:0x5*0x3e8};try{_0x5eeb2c[_0xbc25('0xb')]=_0x46651c[_0xbc25('0xc')]?JSON[_0xbc25('0xd')](Mustache[_0xbc25('0x7')](_0x46651c['data6'],_0x36930c)):{};}catch(_0x2011d4){logger['error'](_0x2011d4[_0xbc25('0xe')]);}switch(_0x46651c['data1']['toUpperCase']()){case _0xbc25('0xf'):case'DELETE':_0x2b50f1=null;_0x5eeb2c['qs']=_0x36930c;break;case _0xbc25('0x10'):case'PUT':if(_0x46651c[_0xbc25('0x11')]){try{_0x2b50f1=JSON[_0xbc25('0xd')](Mustache[_0xbc25('0x7')](_0x46651c[_0xbc25('0x11')],_0x36930c));_0x5eeb2c[_0xbc25('0x12')]=_0x2b50f1;}catch(_0x402411){logger[_0xbc25('0x13')](_0x402411[_0xbc25('0xe')]);logger[_0xbc25('0x13')](_0xbc25('0x14'));}}else{_0x2b50f1=_0x36930c;_0x5eeb2c[_0xbc25('0x12')]=_0x2b50f1;}break;}logger[_0xbc25('0x15')](util[_0xbc25('0x16')](_0xbc25('0x17'),_0x46651c[_0xbc25('0x5')],_0x46651c['data2'],JSON[_0xbc25('0x18')](_0x5eeb2c)));rp(_0x5eeb2c)[_0xbc25('0x19')](function(_0x4c1541){_0x2b50f1=!_[_0xbc25('0x1a')](_0x2b50f1)?_0xbc25('0x1b')+_0x2b50f1:'';_0x447c0b=typeof _0x4c1541[_0xbc25('0x12')]==='object'?JSON[_0xbc25('0x18')](_0x4c1541[_0xbc25('0x12')]):_0x4c1541[_0xbc25('0x12')];logger['info'](util[_0xbc25('0x16')](_0xbc25('0x1c'),_0x46651c[_0xbc25('0x5')],_0x46651c[_0xbc25('0x8')],_0x4c1541[_0xbc25('0x1d')],_0x447c0b));})[_0xbc25('0x1e')](function(_0x2f5818){logger[_0xbc25('0x13')](util[_0xbc25('0x16')](_0xbc25('0x1f'),_0x46651c['data1'],_0x46651c[_0xbc25('0x8')],_0x2f5818['statusCode'],_0x2f5818['name'],_0x2f5818[_0xbc25('0x20')]));});};