e0ab40b46e9251f60715408c7289c95480b68a8f
[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 _0xb1b7=['parse','data6','error','GET','POST','data7','body','stack','info','format','stringify','then','isNil',',\x20request\x20body:\x20','object','%s\x20%s\x20succeeded\x20with\x20status:\x20%d\x20and\x20response:\x20%s','statusCode','catch','name','request-promise','util','../../../../config/logger','exec','data1','toUpperCase','render','data2','data5','headers'];(function(_0x5f3f88,_0x562baf){var _0xd08119=function(_0x42dbf7){while(--_0x42dbf7){_0x5f3f88['push'](_0x5f3f88['shift']());}};_0xd08119(++_0x562baf);}(_0xb1b7,0x135));var _0x7b1b=function(_0x11c820,_0x4f36bf){_0x11c820=_0x11c820-0x0;var _0xd21f79=_0xb1b7[_0x11c820];return _0xd21f79;};'use strict';var rp=require(_0x7b1b('0x0'));var util=require(_0x7b1b('0x1'));var _=require('lodash');var Mustache=require('mustache');var logger=require(_0x7b1b('0x2'))('trigger');exports[_0x7b1b('0x3')]=function(_0x347535,_0x5f3ba4){var _0x2cfdf1,_0x37a1b5;var _0x332913={'method':_0x347535[_0x7b1b('0x4')][_0x7b1b('0x5')](),'uri':Mustache[_0x7b1b('0x6')](_0x347535[_0x7b1b('0x7')],_0x5f3ba4),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0x347535[_0x7b1b('0x8')])==='number'&&parseInt(_0x347535[_0x7b1b('0x8')])>=0x1&&parseInt(_0x347535[_0x7b1b('0x8')])<=0xa?parseInt(_0x347535[_0x7b1b('0x8')])*0x3e8:0x5*0x3e8};try{_0x332913[_0x7b1b('0x9')]=_0x347535['data6']?JSON[_0x7b1b('0xa')](Mustache['render'](_0x347535[_0x7b1b('0xb')],_0x5f3ba4)):{};}catch(_0x4b9d4e){logger[_0x7b1b('0xc')](_0x4b9d4e['stack']);}switch(_0x347535['data1'][_0x7b1b('0x5')]()){case _0x7b1b('0xd'):case'DELETE':_0x2cfdf1=null;_0x332913['qs']=_0x5f3ba4;break;case _0x7b1b('0xe'):case'PUT':if(_0x347535[_0x7b1b('0xf')]){try{_0x2cfdf1=JSON['parse'](Mustache[_0x7b1b('0x6')](_0x347535['data7'],_0x5f3ba4));_0x332913[_0x7b1b('0x10')]=_0x2cfdf1;}catch(_0x41c505){logger['error'](_0x41c505[_0x7b1b('0x11')]);logger[_0x7b1b('0xc')]('body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format');}}else{_0x2cfdf1=_0x5f3ba4;_0x332913[_0x7b1b('0x10')]=_0x2cfdf1;}break;}logger[_0x7b1b('0x12')](util[_0x7b1b('0x13')]('%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s',_0x347535[_0x7b1b('0x4')],_0x347535[_0x7b1b('0x7')],JSON[_0x7b1b('0x14')](_0x332913)));rp(_0x332913)[_0x7b1b('0x15')](function(_0x1d8e75){_0x2cfdf1=!_[_0x7b1b('0x16')](_0x2cfdf1)?_0x7b1b('0x17')+_0x2cfdf1:'';_0x37a1b5=typeof _0x1d8e75[_0x7b1b('0x10')]===_0x7b1b('0x18')?JSON[_0x7b1b('0x14')](_0x1d8e75[_0x7b1b('0x10')]):_0x1d8e75[_0x7b1b('0x10')];logger['info'](util['format'](_0x7b1b('0x19'),_0x347535[_0x7b1b('0x4')],_0x347535[_0x7b1b('0x7')],_0x1d8e75[_0x7b1b('0x1a')],_0x37a1b5));})[_0x7b1b('0x1b')](function(_0x1aece1){logger[_0x7b1b('0xc')](util[_0x7b1b('0x13')]('%s\x20%s\x20failed\x20with\x20status:\x20%d\x20and\x20error:\x20%s\x20%s',_0x347535[_0x7b1b('0x4')],_0x347535[_0x7b1b('0x7')],_0x1aece1[_0x7b1b('0x1a')],_0x1aece1[_0x7b1b('0x1c')],_0x1aece1['message']));});};