ae79632dd8417fd808ff9174a0d037dd18bf78dc
[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 _0x759b=['PUT','data7','body','info','format','%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s','data2','stringify','then','isNil',',\x20request\x20body:\x20','object','statusCode','catch','%s\x20%s\x20failed\x20with\x20status:\x20%d\x20and\x20error:\x20%s\x20%s','message','request-promise','util','trigger','data1','toUpperCase','render','data5','number','headers','data6','parse','error','stack','GET','DELETE','POST'];(function(_0xef2a14,_0x4c359a){var _0x242a4d=function(_0x3227c9){while(--_0x3227c9){_0xef2a14['push'](_0xef2a14['shift']());}};_0x242a4d(++_0x4c359a);}(_0x759b,0x130));var _0xb759=function(_0x93d86c,_0x54e7ee){_0x93d86c=_0x93d86c-0x0;var _0x58e497=_0x759b[_0x93d86c];return _0x58e497;};'use strict';var rp=require(_0xb759('0x0'));var util=require(_0xb759('0x1'));var _=require('lodash');var Mustache=require('mustache');var logger=require('../../../../config/logger')(_0xb759('0x2'));exports['exec']=function(_0xed549d,_0x3a34eb){var _0x502b5a,_0x2264dc;var _0x3f682f={'method':_0xed549d[_0xb759('0x3')][_0xb759('0x4')](),'uri':Mustache[_0xb759('0x5')](_0xed549d['data2'],_0x3a34eb),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0xed549d[_0xb759('0x6')])===_0xb759('0x7')&&parseInt(_0xed549d[_0xb759('0x6')])>=0x1&&parseInt(_0xed549d[_0xb759('0x6')])<=0xa?parseInt(_0xed549d[_0xb759('0x6')])*0x3e8:0x5*0x3e8};try{_0x3f682f[_0xb759('0x8')]=_0xed549d[_0xb759('0x9')]?JSON[_0xb759('0xa')](Mustache['render'](_0xed549d[_0xb759('0x9')],_0x3a34eb)):{};}catch(_0x2e358b){logger[_0xb759('0xb')](_0x2e358b[_0xb759('0xc')]);}switch(_0xed549d[_0xb759('0x3')]['toUpperCase']()){case _0xb759('0xd'):case _0xb759('0xe'):_0x502b5a=null;_0x3f682f['qs']=_0x3a34eb;break;case _0xb759('0xf'):case _0xb759('0x10'):if(_0xed549d[_0xb759('0x11')]){try{_0x502b5a=JSON[_0xb759('0xa')](Mustache[_0xb759('0x5')](_0xed549d['data7'],_0x3a34eb));_0x3f682f[_0xb759('0x12')]=_0x502b5a;}catch(_0x4b9811){logger[_0xb759('0xb')](_0x4b9811[_0xb759('0xc')]);logger[_0xb759('0xb')]('body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format');}}else{_0x502b5a=_0x3a34eb;_0x3f682f['body']=_0x502b5a;}break;}logger[_0xb759('0x13')](util[_0xb759('0x14')](_0xb759('0x15'),_0xed549d[_0xb759('0x3')],_0xed549d[_0xb759('0x16')],JSON[_0xb759('0x17')](_0x3f682f)));rp(_0x3f682f)[_0xb759('0x18')](function(_0x1aef28){_0x502b5a=!_[_0xb759('0x19')](_0x502b5a)?_0xb759('0x1a')+_0x502b5a:'';_0x2264dc=typeof _0x1aef28[_0xb759('0x12')]===_0xb759('0x1b')?JSON[_0xb759('0x17')](_0x1aef28[_0xb759('0x12')]):_0x1aef28[_0xb759('0x12')];logger[_0xb759('0x13')](util[_0xb759('0x14')]('%s\x20%s\x20succeeded\x20with\x20status:\x20%d\x20and\x20response:\x20%s',_0xed549d[_0xb759('0x3')],_0xed549d[_0xb759('0x16')],_0x1aef28[_0xb759('0x1c')],_0x2264dc));})[_0xb759('0x1d')](function(_0x2c2cf5){logger['error'](util[_0xb759('0x14')](_0xb759('0x1e'),_0xed549d[_0xb759('0x3')],_0xed549d[_0xb759('0x16')],_0x2c2cf5[_0xb759('0x1c')],_0x2c2cf5['name'],_0x2c2cf5[_0xb759('0x1f')]));});};