Built motion from commit f74363e9.|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 _0x9aae=['PUT','data7','render','body','error','info','then','isNil',',\x20request\x20body:\x20','object','stringify','%s\x20%s\x20succeeded\x20with\x20status:\x20%d\x20and\x20response:\x20%s','catch','format','%s\x20%s\x20failed\x20with\x20status:\x20%d\x20and\x20error:\x20%s\x20%s','statusCode','util','lodash','mustache','../../../../config/logger','trigger','exec','data1','toUpperCase','data2','data5','number','data6','parse','GET','DELETE','POST'];(function(_0x394056,_0x2452e8){var _0x1ffe71=function(_0x3b4f6b){while(--_0x3b4f6b){_0x394056['push'](_0x394056['shift']());}};_0x1ffe71(++_0x2452e8);}(_0x9aae,0xb0));var _0xe9aa=function(_0x50e40c,_0xa74c27){_0x50e40c=_0x50e40c-0x0;var _0x1cdf49=_0x9aae[_0x50e40c];return _0x1cdf49;};'use strict';var rp=require('request-promise');var util=require(_0xe9aa('0x0'));var _=require(_0xe9aa('0x1'));var Mustache=require(_0xe9aa('0x2'));var logger=require(_0xe9aa('0x3'))(_0xe9aa('0x4'));exports[_0xe9aa('0x5')]=function(_0x88e7f1,_0x40a4fe){var _0x5d84ff,_0x41f1f6;var _0x3c76fe={'method':_0x88e7f1[_0xe9aa('0x6')][_0xe9aa('0x7')](),'uri':Mustache['render'](_0x88e7f1[_0xe9aa('0x8')],_0x40a4fe),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0x88e7f1[_0xe9aa('0x9')])===_0xe9aa('0xa')&&parseInt(_0x88e7f1[_0xe9aa('0x9')])>=0x1&&parseInt(_0x88e7f1['data5'])<=0xa?parseInt(_0x88e7f1[_0xe9aa('0x9')])*0x3e8:0x5*0x3e8};try{_0x3c76fe['headers']=_0x88e7f1[_0xe9aa('0xb')]?JSON[_0xe9aa('0xc')](Mustache['render'](_0x88e7f1['data6'],_0x40a4fe)):{};}catch(_0x28a083){logger['error'](_0x28a083['stack']);}switch(_0x88e7f1[_0xe9aa('0x6')][_0xe9aa('0x7')]()){case _0xe9aa('0xd'):case _0xe9aa('0xe'):_0x5d84ff=null;_0x3c76fe['qs']=_0x40a4fe;break;case _0xe9aa('0xf'):case _0xe9aa('0x10'):if(_0x88e7f1[_0xe9aa('0x11')]){try{_0x5d84ff=JSON[_0xe9aa('0xc')](Mustache[_0xe9aa('0x12')](_0x88e7f1[_0xe9aa('0x11')],_0x40a4fe));_0x3c76fe[_0xe9aa('0x13')]=_0x5d84ff;}catch(_0x477c85){logger[_0xe9aa('0x14')](_0x477c85['stack']);logger[_0xe9aa('0x14')]('body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format');}}else{_0x5d84ff=_0x40a4fe;_0x3c76fe[_0xe9aa('0x13')]=_0x5d84ff;}break;}logger[_0xe9aa('0x15')](util['format']('%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s',_0x88e7f1[_0xe9aa('0x6')],_0x88e7f1[_0xe9aa('0x8')],JSON['stringify'](_0x3c76fe)));rp(_0x3c76fe)[_0xe9aa('0x16')](function(_0x24fa6c){_0x5d84ff=!_[_0xe9aa('0x17')](_0x5d84ff)?_0xe9aa('0x18')+_0x5d84ff:'';_0x41f1f6=typeof _0x24fa6c['body']===_0xe9aa('0x19')?JSON[_0xe9aa('0x1a')](_0x24fa6c['body']):_0x24fa6c[_0xe9aa('0x13')];logger['info'](util['format'](_0xe9aa('0x1b'),_0x88e7f1[_0xe9aa('0x6')],_0x88e7f1[_0xe9aa('0x8')],_0x24fa6c['statusCode'],_0x41f1f6));})[_0xe9aa('0x1c')](function(_0x3c805d){logger[_0xe9aa('0x14')](util[_0xe9aa('0x1d')](_0xe9aa('0x1e'),_0x88e7f1[_0xe9aa('0x6')],_0x88e7f1[_0xe9aa('0x8')],_0x3c805d[_0xe9aa('0x1f')],_0x3c805d['name'],_0x3c805d['message']));});};