Built motion from commit 85328c08.|2.5.50
[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 _0x8fe1=['isNil',',\x20request\x20body:\x20','format','statusCode','catch','%s\x20%s\x20failed\x20with\x20status:\x20%d\x20and\x20error:\x20%s\x20%s','name','message','trigger','exec','data1','toUpperCase','render','number','data5','headers','data6','parse','error','stack','GET','POST','PUT','data7','body','info','%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s','data2','stringify','then'];(function(_0x5a4e94,_0x33778e){var _0x5ec4ad=function(_0x487838){while(--_0x487838){_0x5a4e94['push'](_0x5a4e94['shift']());}};_0x5ec4ad(++_0x33778e);}(_0x8fe1,0x116));var _0x18fe=function(_0xf16b1,_0x33c637){_0xf16b1=_0xf16b1-0x0;var _0x26f94d=_0x8fe1[_0xf16b1];return _0x26f94d;};'use strict';var rp=require('request-promise');var util=require('util');var _=require('lodash');var Mustache=require('mustache');var logger=require('../../../../config/logger')(_0x18fe('0x0'));exports[_0x18fe('0x1')]=function(_0x2f3297,_0x36e495){var _0xa5f429,_0x24339e;var _0x1634e1={'method':_0x2f3297[_0x18fe('0x2')][_0x18fe('0x3')](),'uri':Mustache[_0x18fe('0x4')](_0x2f3297['data2'],_0x36e495),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0x2f3297['data5'])===_0x18fe('0x5')&&parseInt(_0x2f3297[_0x18fe('0x6')])>=0x1&&parseInt(_0x2f3297['data5'])<=0xa?parseInt(_0x2f3297['data5'])*0x3e8:0x5*0x3e8};try{_0x1634e1[_0x18fe('0x7')]=_0x2f3297[_0x18fe('0x8')]?JSON[_0x18fe('0x9')](Mustache[_0x18fe('0x4')](_0x2f3297[_0x18fe('0x8')],_0x36e495)):{};}catch(_0x1a01ff){logger[_0x18fe('0xa')](_0x1a01ff[_0x18fe('0xb')]);}switch(_0x2f3297[_0x18fe('0x2')][_0x18fe('0x3')]()){case _0x18fe('0xc'):case'DELETE':_0xa5f429=null;_0x1634e1['qs']=_0x36e495;break;case _0x18fe('0xd'):case _0x18fe('0xe'):if(_0x2f3297[_0x18fe('0xf')]){try{_0xa5f429=JSON[_0x18fe('0x9')](Mustache[_0x18fe('0x4')](_0x2f3297[_0x18fe('0xf')],_0x36e495));_0x1634e1[_0x18fe('0x10')]=_0xa5f429;}catch(_0x4bb75a){logger[_0x18fe('0xa')](_0x4bb75a['stack']);logger[_0x18fe('0xa')]('body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format');}}else{_0xa5f429=_0x36e495;_0x1634e1[_0x18fe('0x10')]=_0xa5f429;}break;}logger[_0x18fe('0x11')](util['format'](_0x18fe('0x12'),_0x2f3297['data1'],_0x2f3297[_0x18fe('0x13')],JSON[_0x18fe('0x14')](_0x1634e1)));rp(_0x1634e1)[_0x18fe('0x15')](function(_0x201efb){_0xa5f429=!_[_0x18fe('0x16')](_0xa5f429)?_0x18fe('0x17')+_0xa5f429:'';_0x24339e=typeof _0x201efb[_0x18fe('0x10')]==='object'?JSON['stringify'](_0x201efb[_0x18fe('0x10')]):_0x201efb['body'];logger[_0x18fe('0x11')](util[_0x18fe('0x18')]('%s\x20%s\x20succeeded\x20with\x20status:\x20%d\x20and\x20response:\x20%s',_0x2f3297[_0x18fe('0x2')],_0x2f3297['data2'],_0x201efb[_0x18fe('0x19')],_0x24339e));})[_0x18fe('0x1a')](function(_0x1b01d0){logger['error'](util[_0x18fe('0x18')](_0x18fe('0x1b'),_0x2f3297[_0x18fe('0x2')],_0x2f3297[_0x18fe('0x13')],_0x1b01d0['statusCode'],_0x1b01d0[_0x18fe('0x1c')],_0x1b01d0[_0x18fe('0x1d')]));});};