f840b9dbffe0046516e0befda7a0afa42a0636f1
[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 _0xda47=['toUpperCase','render','data2','data5','number','headers','data6','parse','stack','DELETE','PUT','data7','body','error','info','format','%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s','stringify','then','isNil',',\x20request\x20body:\x20','catch','%s\x20%s\x20failed\x20with\x20status:\x20%d\x20and\x20error:\x20%s\x20%s','statusCode','name','message','util','lodash','trigger','data1'];(function(_0x65d12e,_0x4b0a30){var _0x4274e0=function(_0x121624){while(--_0x121624){_0x65d12e['push'](_0x65d12e['shift']());}};_0x4274e0(++_0x4b0a30);}(_0xda47,0xce));var _0x7da4=function(_0x5d6c3e,_0x409a3e){_0x5d6c3e=_0x5d6c3e-0x0;var _0x44ecb7=_0xda47[_0x5d6c3e];return _0x44ecb7;};'use strict';var rp=require('request-promise');var util=require(_0x7da4('0x0'));var _=require(_0x7da4('0x1'));var Mustache=require('mustache');var logger=require('../../../../config/logger')(_0x7da4('0x2'));exports['exec']=function(_0x33efb2,_0x57dccf){var _0x578c46,_0x49bb64;var _0x16afc8={'method':_0x33efb2[_0x7da4('0x3')][_0x7da4('0x4')](),'uri':Mustache[_0x7da4('0x5')](_0x33efb2[_0x7da4('0x6')],_0x57dccf),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0x33efb2[_0x7da4('0x7')])===_0x7da4('0x8')&&parseInt(_0x33efb2[_0x7da4('0x7')])>=0x1&&parseInt(_0x33efb2[_0x7da4('0x7')])<=0xa?parseInt(_0x33efb2['data5'])*0x3e8:0x5*0x3e8};try{_0x16afc8[_0x7da4('0x9')]=_0x33efb2[_0x7da4('0xa')]?JSON[_0x7da4('0xb')](Mustache[_0x7da4('0x5')](_0x33efb2[_0x7da4('0xa')],_0x57dccf)):{};}catch(_0x422c47){logger['error'](_0x422c47[_0x7da4('0xc')]);}switch(_0x33efb2[_0x7da4('0x3')][_0x7da4('0x4')]()){case'GET':case _0x7da4('0xd'):_0x578c46=null;_0x16afc8['qs']=_0x57dccf;break;case'POST':case _0x7da4('0xe'):if(_0x33efb2[_0x7da4('0xf')]){try{_0x578c46=JSON[_0x7da4('0xb')](Mustache[_0x7da4('0x5')](_0x33efb2['data7'],_0x57dccf));_0x16afc8[_0x7da4('0x10')]=_0x578c46;}catch(_0x15fcf5){logger[_0x7da4('0x11')](_0x15fcf5[_0x7da4('0xc')]);logger['error']('body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format');}}else{_0x578c46=_0x57dccf;_0x16afc8[_0x7da4('0x10')]=_0x578c46;}break;}logger[_0x7da4('0x12')](util[_0x7da4('0x13')](_0x7da4('0x14'),_0x33efb2[_0x7da4('0x3')],_0x33efb2[_0x7da4('0x6')],JSON[_0x7da4('0x15')](_0x16afc8)));rp(_0x16afc8)[_0x7da4('0x16')](function(_0x1d48ec){_0x578c46=!_[_0x7da4('0x17')](_0x578c46)?_0x7da4('0x18')+_0x578c46:'';_0x49bb64=typeof _0x1d48ec['body']==='object'?JSON['stringify'](_0x1d48ec[_0x7da4('0x10')]):_0x1d48ec[_0x7da4('0x10')];logger[_0x7da4('0x12')](util[_0x7da4('0x13')]('%s\x20%s\x20succeeded\x20with\x20status:\x20%d\x20and\x20response:\x20%s',_0x33efb2[_0x7da4('0x3')],_0x33efb2[_0x7da4('0x6')],_0x1d48ec['statusCode'],_0x49bb64));})[_0x7da4('0x19')](function(_0x4e2c0f){logger['error'](util['format'](_0x7da4('0x1a'),_0x33efb2[_0x7da4('0x3')],_0x33efb2['data2'],_0x4e2c0f[_0x7da4('0x1b')],_0x4e2c0f[_0x7da4('0x1c')],_0x4e2c0f[_0x7da4('0x1d')]));});};