Built motion from commit 0d14f64c.|2.6.34
[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 _0xc4ca=['mustache','../../../../config/logger','trigger','data1','toUpperCase','render','number','data5','headers','data6','error','stack','GET','POST','PUT','data7','parse','body','format','%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s','data2','stringify','then','isNil',',\x20request\x20body:\x20','object','info','statusCode','name','message','request-promise','util'];(function(_0x5661cf,_0x3f6960){var _0x2d6c33=function(_0x497e6a){while(--_0x497e6a){_0x5661cf['push'](_0x5661cf['shift']());}};_0x2d6c33(++_0x3f6960);}(_0xc4ca,0x11e));var _0xac4c=function(_0x45d55a,_0x1adad5){_0x45d55a=_0x45d55a-0x0;var _0x3ff504=_0xc4ca[_0x45d55a];return _0x3ff504;};'use strict';var rp=require(_0xac4c('0x0'));var util=require(_0xac4c('0x1'));var _=require('lodash');var Mustache=require(_0xac4c('0x2'));var logger=require(_0xac4c('0x3'))(_0xac4c('0x4'));exports['exec']=function(_0x302222,_0x1ecae7){var _0x505dca,_0x4b3262;var _0x481bde={'method':_0x302222[_0xac4c('0x5')][_0xac4c('0x6')](),'uri':Mustache[_0xac4c('0x7')](_0x302222['data2'],_0x1ecae7),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0x302222['data5'])===_0xac4c('0x8')&&parseInt(_0x302222[_0xac4c('0x9')])>=0x1&&parseInt(_0x302222['data5'])<=0xa?parseInt(_0x302222[_0xac4c('0x9')])*0x3e8:0x5*0x3e8};try{_0x481bde[_0xac4c('0xa')]=_0x302222[_0xac4c('0xb')]?JSON['parse'](Mustache[_0xac4c('0x7')](_0x302222['data6'],_0x1ecae7)):{};}catch(_0x4d5d3e){logger[_0xac4c('0xc')](_0x4d5d3e[_0xac4c('0xd')]);}switch(_0x302222[_0xac4c('0x5')][_0xac4c('0x6')]()){case _0xac4c('0xe'):case'DELETE':_0x505dca=null;_0x481bde['qs']=_0x1ecae7;break;case _0xac4c('0xf'):case _0xac4c('0x10'):if(_0x302222[_0xac4c('0x11')]){try{_0x505dca=JSON[_0xac4c('0x12')](Mustache['render'](_0x302222['data7'],_0x1ecae7));_0x481bde[_0xac4c('0x13')]=_0x505dca;}catch(_0x3ee796){logger['error'](_0x3ee796['stack']);logger[_0xac4c('0xc')]('body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format');}}else{_0x505dca=_0x1ecae7;_0x481bde[_0xac4c('0x13')]=_0x505dca;}break;}logger['info'](util[_0xac4c('0x14')](_0xac4c('0x15'),_0x302222['data1'],_0x302222[_0xac4c('0x16')],JSON[_0xac4c('0x17')](_0x481bde)));rp(_0x481bde)[_0xac4c('0x18')](function(_0x90ec0f){_0x505dca=!_[_0xac4c('0x19')](_0x505dca)?_0xac4c('0x1a')+_0x505dca:'';_0x4b3262=typeof _0x90ec0f[_0xac4c('0x13')]===_0xac4c('0x1b')?JSON[_0xac4c('0x17')](_0x90ec0f[_0xac4c('0x13')]):_0x90ec0f[_0xac4c('0x13')];logger[_0xac4c('0x1c')](util[_0xac4c('0x14')]('%s\x20%s\x20succeeded\x20with\x20status:\x20%d\x20and\x20response:\x20%s',_0x302222[_0xac4c('0x5')],_0x302222[_0xac4c('0x16')],_0x90ec0f[_0xac4c('0x1d')],_0x4b3262));})['catch'](function(_0x3a21a0){logger[_0xac4c('0xc')](util['format']('%s\x20%s\x20failed\x20with\x20status:\x20%d\x20and\x20error:\x20%s\x20%s',_0x302222[_0xac4c('0x5')],_0x302222[_0xac4c('0x16')],_0x3a21a0[_0xac4c('0x1d')],_0x3a21a0[_0xac4c('0x1e')],_0x3a21a0[_0xac4c('0x1f')]));});};