4fdb41a2cda234180abbc87256d84e8012ad30c7
[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 _0x8e45=['stringify','then','isNil','body','object','%s\x20%s\x20succeeded\x20with\x20status:\x20%d\x20and\x20response:\x20%s','catch','statusCode','name','message','request-promise','util','mustache','trigger','exec','data1','toUpperCase','render','data2','number','data5','headers','data6','error','stack','GET','POST','PUT','data7','info','format','%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s'];(function(_0x5a3785,_0x2de636){var _0x4d058a=function(_0x2852fc){while(--_0x2852fc){_0x5a3785['push'](_0x5a3785['shift']());}};_0x4d058a(++_0x2de636);}(_0x8e45,0x14a));var _0x58e4=function(_0x265ba0,_0xc84c77){_0x265ba0=_0x265ba0-0x0;var _0x43ce71=_0x8e45[_0x265ba0];return _0x43ce71;};'use strict';var rp=require(_0x58e4('0x0'));var util=require(_0x58e4('0x1'));var _=require('lodash');var Mustache=require(_0x58e4('0x2'));var logger=require('../../../../config/logger')(_0x58e4('0x3'));exports[_0x58e4('0x4')]=function(_0x289b64,_0x5ed9df){var _0x3805ef,_0x42fb7f;var _0x22b989={'method':_0x289b64[_0x58e4('0x5')][_0x58e4('0x6')](),'uri':Mustache[_0x58e4('0x7')](_0x289b64[_0x58e4('0x8')],_0x5ed9df),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0x289b64['data5'])===_0x58e4('0x9')&&parseInt(_0x289b64['data5'])>=0x1&&parseInt(_0x289b64[_0x58e4('0xa')])<=0xa?parseInt(_0x289b64[_0x58e4('0xa')])*0x3e8:0x5*0x3e8};try{_0x22b989[_0x58e4('0xb')]=_0x289b64[_0x58e4('0xc')]?JSON['parse'](Mustache[_0x58e4('0x7')](_0x289b64[_0x58e4('0xc')],_0x5ed9df)):{};}catch(_0x23b561){logger[_0x58e4('0xd')](_0x23b561[_0x58e4('0xe')]);}switch(_0x289b64[_0x58e4('0x5')][_0x58e4('0x6')]()){case _0x58e4('0xf'):case'DELETE':_0x3805ef=null;_0x22b989['qs']=_0x5ed9df;break;case _0x58e4('0x10'):case _0x58e4('0x11'):if(_0x289b64[_0x58e4('0x12')]){try{_0x3805ef=JSON['parse'](Mustache[_0x58e4('0x7')](_0x289b64[_0x58e4('0x12')],_0x5ed9df));_0x22b989['body']=_0x3805ef;}catch(_0x54d841){logger[_0x58e4('0xd')](_0x54d841[_0x58e4('0xe')]);logger[_0x58e4('0xd')]('body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format');}}else{_0x3805ef=_0x5ed9df;_0x22b989['body']=_0x3805ef;}break;}logger[_0x58e4('0x13')](util[_0x58e4('0x14')](_0x58e4('0x15'),_0x289b64[_0x58e4('0x5')],_0x289b64[_0x58e4('0x8')],JSON[_0x58e4('0x16')](_0x22b989)));rp(_0x22b989)[_0x58e4('0x17')](function(_0x344554){_0x3805ef=!_[_0x58e4('0x18')](_0x3805ef)?',\x20request\x20body:\x20'+_0x3805ef:'';_0x42fb7f=typeof _0x344554[_0x58e4('0x19')]===_0x58e4('0x1a')?JSON[_0x58e4('0x16')](_0x344554[_0x58e4('0x19')]):_0x344554[_0x58e4('0x19')];logger[_0x58e4('0x13')](util['format'](_0x58e4('0x1b'),_0x289b64[_0x58e4('0x5')],_0x289b64[_0x58e4('0x8')],_0x344554['statusCode'],_0x42fb7f));})[_0x58e4('0x1c')](function(_0x44d01d){logger[_0x58e4('0xd')](util[_0x58e4('0x14')]('%s\x20%s\x20failed\x20with\x20status:\x20%d\x20and\x20error:\x20%s\x20%s',_0x289b64[_0x58e4('0x5')],_0x289b64[_0x58e4('0x8')],_0x44d01d[_0x58e4('0x1d')],_0x44d01d[_0x58e4('0x1e')],_0x44d01d[_0x58e4('0x1f')]));});};