32801793bf4078ed01786dec608ae9a2ebfc59c2
[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 _0x355c=['%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','name','request-promise','lodash','mustache','exec','data1','toUpperCase','render','data2','data5','number','data6','error','stack','GET','POST','data7','parse','body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format','format','%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s','stringify','isNil',',\x20request\x20body:\x20','body','info'];(function(_0x55abd9,_0x1148af){var _0x3e5669=function(_0x6f2105){while(--_0x6f2105){_0x55abd9['push'](_0x55abd9['shift']());}};_0x3e5669(++_0x1148af);}(_0x355c,0x16d));var _0xc355=function(_0x5b7e20,_0x17cfec){_0x5b7e20=_0x5b7e20-0x0;var _0x57eddf=_0x355c[_0x5b7e20];return _0x57eddf;};'use strict';var rp=require(_0xc355('0x0'));var util=require('util');var _=require(_0xc355('0x1'));var Mustache=require(_0xc355('0x2'));var logger=require('../../../../config/logger')('trigger');exports[_0xc355('0x3')]=function(_0x5f1e43,_0x3c6b04){var _0x3d5223,_0x316995;var _0x301361={'method':_0x5f1e43[_0xc355('0x4')][_0xc355('0x5')](),'uri':Mustache[_0xc355('0x6')](_0x5f1e43[_0xc355('0x7')],_0x3c6b04),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0x5f1e43[_0xc355('0x8')])===_0xc355('0x9')&&parseInt(_0x5f1e43[_0xc355('0x8')])>=0x1&&parseInt(_0x5f1e43[_0xc355('0x8')])<=0xa?parseInt(_0x5f1e43[_0xc355('0x8')])*0x3e8:0x5*0x3e8};try{_0x301361['headers']=_0x5f1e43[_0xc355('0xa')]?JSON['parse'](Mustache[_0xc355('0x6')](_0x5f1e43[_0xc355('0xa')],_0x3c6b04)):{};}catch(_0x475e80){logger[_0xc355('0xb')](_0x475e80[_0xc355('0xc')]);}switch(_0x5f1e43['data1']['toUpperCase']()){case _0xc355('0xd'):case'DELETE':_0x3d5223=null;_0x301361['qs']=_0x3c6b04;break;case _0xc355('0xe'):case'PUT':if(_0x5f1e43[_0xc355('0xf')]){try{_0x3d5223=JSON[_0xc355('0x10')](Mustache[_0xc355('0x6')](_0x5f1e43[_0xc355('0xf')],_0x3c6b04));_0x301361['body']=_0x3d5223;}catch(_0x643b15){logger[_0xc355('0xb')](_0x643b15[_0xc355('0xc')]);logger['error'](_0xc355('0x11'));}}else{_0x3d5223=_0x3c6b04;_0x301361['body']=_0x3d5223;}break;}logger['info'](util[_0xc355('0x12')](_0xc355('0x13'),_0x5f1e43[_0xc355('0x4')],_0x5f1e43['data2'],JSON[_0xc355('0x14')](_0x301361)));rp(_0x301361)['then'](function(_0xd8509e){_0x3d5223=!_[_0xc355('0x15')](_0x3d5223)?_0xc355('0x16')+_0x3d5223:'';_0x316995=typeof _0xd8509e[_0xc355('0x17')]==='object'?JSON[_0xc355('0x14')](_0xd8509e[_0xc355('0x17')]):_0xd8509e['body'];logger[_0xc355('0x18')](util[_0xc355('0x12')](_0xc355('0x19'),_0x5f1e43[_0xc355('0x4')],_0x5f1e43[_0xc355('0x7')],_0xd8509e[_0xc355('0x1a')],_0x316995));})[_0xc355('0x1b')](function(_0x24b119){logger[_0xc355('0xb')](util[_0xc355('0x12')](_0xc355('0x1c'),_0x5f1e43[_0xc355('0x4')],_0x5f1e43[_0xc355('0x7')],_0x24b119['statusCode'],_0x24b119[_0xc355('0x1d')],_0x24b119['message']));});};