cddb2cc219cd29c2686066fdaf289871016e4a06
[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 _0x7a77=['stack','DELETE','error','body\x20has\x20been\x20passed\x20to\x20URLforward\x20in\x20a\x20wrong\x20format','body','info','%s\x20%s\x20sending\x20request\x20with\x20following\x20options:\x20%s','data2','then','isNil',',\x20request\x20body:\x20','object','stringify','format','%s\x20%s\x20succeeded\x20with\x20status:\x20%d\x20and\x20response:\x20%s','statusCode','catch','%s\x20%s\x20failed\x20with\x20status:\x20%d\x20and\x20error:\x20%s\x20%s','name','message','request-promise','lodash','trigger','data1','toUpperCase','render','data5','number','data6','parse'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x7a77,0x15e));var _0x77a7=function(_0x236712,_0x5c78df){_0x236712=_0x236712-0x0;var _0x2a472c=_0x7a77[_0x236712];return _0x2a472c;};'use strict';var rp=require(_0x77a7('0x0'));var util=require('util');var _=require(_0x77a7('0x1'));var Mustache=require('mustache');var logger=require('../../../../config/logger')(_0x77a7('0x2'));exports['exec']=function(_0x160d3f,_0x5bf92e){var _0x400aae,_0x124418;var _0x394c6e={'method':_0x160d3f[_0x77a7('0x3')][_0x77a7('0x4')](),'uri':Mustache[_0x77a7('0x5')](_0x160d3f['data2'],_0x5bf92e),'json':!![],'resolveWithFullResponse':!![],'timeout':typeof parseInt(_0x160d3f[_0x77a7('0x6')])===_0x77a7('0x7')&&parseInt(_0x160d3f[_0x77a7('0x6')])>=0x1&&parseInt(_0x160d3f[_0x77a7('0x6')])<=0xa?parseInt(_0x160d3f[_0x77a7('0x6')])*0x3e8:0x5*0x3e8};try{_0x394c6e['headers']=_0x160d3f[_0x77a7('0x8')]?JSON[_0x77a7('0x9')](Mustache[_0x77a7('0x5')](_0x160d3f[_0x77a7('0x8')],_0x5bf92e)):{};}catch(_0x5d32ba){logger['error'](_0x5d32ba[_0x77a7('0xa')]);}switch(_0x160d3f[_0x77a7('0x3')][_0x77a7('0x4')]()){case'GET':case _0x77a7('0xb'):_0x400aae=null;_0x394c6e['qs']=_0x5bf92e;break;case'POST':case'PUT':if(_0x160d3f['data7']){try{_0x400aae=JSON[_0x77a7('0x9')](Mustache[_0x77a7('0x5')](_0x160d3f['data7'],_0x5bf92e));_0x394c6e['body']=_0x400aae;}catch(_0x49ae5c){logger[_0x77a7('0xc')](_0x49ae5c['stack']);logger['error'](_0x77a7('0xd'));}}else{_0x400aae=_0x5bf92e;_0x394c6e[_0x77a7('0xe')]=_0x400aae;}break;}logger[_0x77a7('0xf')](util['format'](_0x77a7('0x10'),_0x160d3f[_0x77a7('0x3')],_0x160d3f[_0x77a7('0x11')],JSON['stringify'](_0x394c6e)));rp(_0x394c6e)[_0x77a7('0x12')](function(_0x56d7c3){_0x400aae=!_[_0x77a7('0x13')](_0x400aae)?_0x77a7('0x14')+_0x400aae:'';_0x124418=typeof _0x56d7c3[_0x77a7('0xe')]===_0x77a7('0x15')?JSON[_0x77a7('0x16')](_0x56d7c3[_0x77a7('0xe')]):_0x56d7c3[_0x77a7('0xe')];logger[_0x77a7('0xf')](util[_0x77a7('0x17')](_0x77a7('0x18'),_0x160d3f[_0x77a7('0x3')],_0x160d3f[_0x77a7('0x11')],_0x56d7c3[_0x77a7('0x19')],_0x124418));})[_0x77a7('0x1a')](function(_0x466800){logger[_0x77a7('0xc')](util[_0x77a7('0x17')](_0x77a7('0x1b'),_0x160d3f[_0x77a7('0x3')],_0x160d3f[_0x77a7('0x11')],_0x466800[_0x77a7('0x19')],_0x466800[_0x77a7('0x1c')],_0x466800[_0x77a7('0x1d')]));});};