Built motion from commit de2cb856.|2.0.31
[motion2.git] / server / services / ami / trigger / integration / desk.js
1 var _0xc194=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x72\x65\x71\x75\x65\x73\x74\x2D\x70\x72\x6F\x6D\x69\x73\x65","\x62\x6C\x75\x65\x62\x69\x72\x64","\x75\x74\x69\x6C","\x2E\x2F\x75\x74\x69\x6C","\x64\x65\x73\x6B","\x2E\x2E\x2F\x2E\x2E\x2F\x2E\x2E\x2F\x2E\x2E\x2F\x63\x6F\x6E\x66\x69\x67\x2F\x6C\x6F\x67\x67\x65\x72","\x6C\x6F\x63\x61\x6C\x68\x6F\x73\x74","\x73\x6F\x63\x6B\x65\x74\x2E\x69\x6F\x2D\x65\x6D\x69\x74\x74\x65\x72","\x65\x6D\x69\x74","\x74\x6F","\x61\x70\x70\x6C\x69\x63\x61\x74\x69\x6F\x6E\x2F\x6A\x73\x6F\x6E","\x25\x73\x2F\x75\x73\x65\x72\x73\x2F\x6D\x65","\x72\x65\x6D\x6F\x74\x65\x55\x72\x69","\x66\x6F\x72\x6D\x61\x74","\x74\x68\x65\x6E","\x74\x6F\x74\x61\x6C\x5F\x65\x6E\x74\x72\x69\x65\x73","\x65\x6E\x74\x72\x69\x65\x73","\x5F\x65\x6D\x62\x65\x64\x64\x65\x64","\x66\x69\x6E\x64","\x25\x73\x2F\x75\x73\x65\x72\x73","\x5B\x48\x54\x54\x50\x5D","\x73\x74\x72\x69\x6E\x67\x69\x66\x79","\x69\x6E\x66\x6F","\x47\x45\x54","\x64\x65\x66\x61\x75\x6C\x74\x73","\x61\x75\x74\x68\x54\x79\x70\x65","\x62\x61\x73\x69\x63","\x25\x73\x3A\x25\x73","\x75\x73\x65\x72\x6E\x61\x6D\x65","\x70\x61\x73\x73\x77\x6F\x72\x64","\x74\x6F\x6B\x65\x6E","\x25\x73\x2F\x74\x6F\x6B\x65\x6E\x3A\x25\x73","\x42\x61\x73\x69\x63\x20\x25\x73","\x62\x61\x73\x65\x36\x34","\x25\x73\x2F\x63\x75\x73\x74\x6F\x6D\x65\x72\x73","\x50\x4F\x53\x54","\x77\x6F\x72\x6B","\x25\x73\x2F\x63\x75\x73\x74\x6F\x6D\x65\x72\x73\x2F\x73\x65\x61\x72\x63\x68","\x6C\x65\x6E\x67\x74\x68","\x6D\x61\x70","\x74\x79\x70\x65","\x73\x74\x72\x69\x6E\x67","\x6E\x61\x6D\x65\x46\x69\x65\x6C\x64","\x63\x75\x73\x74\x6F\x6D\x46\x69\x65\x6C\x64","\x74\x6F\x4C\x6F\x77\x65\x72\x43\x61\x73\x65","\x63\x6F\x6E\x74\x65\x6E\x74","\x69\x64\x46\x69\x65\x6C\x64","\x63\x75\x73\x74\x6F\x6D\x5F\x66\x69\x65\x6C\x64\x73","\x76\x61\x72\x69\x61\x62\x6C\x65","\x76\x61\x72\x69\x61\x62\x6C\x65\x4E\x61\x6D\x65","\x63\x75\x73\x74\x6F\x6D\x56\x61\x72\x69\x61\x62\x6C\x65","\x56\x61\x72\x69\x61\x62\x6C\x65","\x6E\x61\x6D\x65","\x66\x6F\x72\x45\x61\x63\x68","\x70\x72\x69\x6F\x72\x69\x74\x79","\x20","\x67\x65\x74\x53\x74\x72\x69\x6E\x67","\x70\x68\x6F\x6E\x65","\x6E\x65\x77","\x63\x6F\x6E\x63\x61\x74","\x78\x43\x41\x4C\x4C\x59","\x4D\x6F\x74\x69\x6F\x6E","\x43\x54\x49","\x0A","\x2F\x61\x70\x69\x2F\x76\x32\x2F\x75\x73\x65\x72\x73\x2F\x25\x64","\x69\x64","\x75\x73\x65\x72","\x69\x6E","\x6D\x65\x72\x67\x65","\x25\x73\x2F\x63\x75\x73\x74\x6F\x6D\x65\x72\x73\x2F\x25\x64\x2F\x63\x61\x73\x65\x73","\x71\x75\x65\x75\x65","\x73\x74\x72\x69\x70\x54\x72\x61\x69\x6C\x69\x6E\x67\x53\x6C\x61\x73\x68","\x73\x65\x72\x76\x65\x72\x55\x72\x6C","\x72\x65\x63\x6F\x72\x64\x69\x6E\x67\x55\x52\x4C","\x6D\x6F\x6E\x69\x74\x6F\x72\x5F\x66\x6F\x72\x6D\x61\x74","\x25\x73\x2F\x61\x70\x69\x2F\x76\x6F\x69\x63\x65\x2F\x72\x65\x63\x6F\x72\x64\x69\x6E\x67\x73\x2F\x25\x73\x2F\x64\x6F\x77\x6E\x6C\x6F\x61\x64\x3F\x74\x79\x70\x65\x3D\x75\x6E\x69\x71\x75\x65\x69\x64","\x75\x6E\x69\x71\x75\x65\x69\x64","","\x41\x75\x74\x68\x6F\x72\x69\x7A\x61\x74\x69\x6F\x6E","\x65\x72\x72\x6F\x72","\x5B\x51\x55\x45\x55\x45\x5D","\x63\x61\x74\x63\x68","\x75\x73\x65\x72\x3A\x25\x73","\x74\x72\x69\x67\x67\x65\x72\x3A\x64\x65\x73\x6B\x3A\x64\x69\x73\x70\x6C\x61\x79","\x69\x6E\x74\x65\x67\x72\x61\x74\x69\x6F\x6E\x54\x61\x62","\x74\x72\x69\x67\x67\x65\x72\x3A\x62\x72\x6F\x77\x73\x65\x72\x3A\x75\x72\x6C","\x68\x74\x74\x70\x73\x3A\x2F\x2F\x78\x63\x61\x6C\x6C\x79\x2E\x64\x65\x73\x6B\x2E\x63\x6F\x6D\x2F\x77\x65\x62\x2F\x61\x67\x65\x6E\x74\x2F\x63\x61\x73\x65\x2F\x25\x64","\x6E\x65\x77\x54\x61\x62","\x44\x65\x73\x6B\x20\x61\x63\x63\x6F\x75\x6E\x74\x20\x74\x79\x70\x65\x20\x6E\x6F\x74\x20\x72\x65\x63\x6F\x67\x6E\x69\x7A\x65\x64","\x63\x61\x6C\x6C\x65\x72\x69\x64\x6E\x61\x6D\x65","\x63\x61\x6C\x6C\x65\x72\x69\x64\x6E\x75\x6D","\x65\x6D\x61\x69\x6C","\x6F\x75\x74\x62\x6F\x75\x6E\x64","\x5B\x4F\x55\x54\x42\x4F\x55\x4E\x44\x5D","\x25\x73\x2F\x61\x67\x65\x6E\x74\x2F\x74\x69\x63\x6B\x65\x74\x73\x2F\x25\x73","\x64\x65\x73\x74\x63\x61\x6C\x6C\x65\x72\x69\x64\x6E\x61\x6D\x65","\x64\x65\x73\x74\x63\x61\x6C\x6C\x65\x72\x69\x64\x6E\x75\x6D","\x61\x62\x61\x6E\x64\x6F\x6E\x65\x64","\x5B\x41\x42\x41\x4E\x44\x4F\x4E\x45\x44\x5D"];_0xc194[0];var _=require(_0xc194[1]);var rp=require(_0xc194[2]);var BPromise=require(_0xc194[3]);var util=require(_0xc194[4]);var intUtil=require(_0xc194[5]);var logger=require(_0xc194[7])(_0xc194[6]);var io=require(_0xc194[9])({host:_0xc194[8],port:6379});function emit(_0x1365x9,_0x1365xa,_0x1365xb){io[_0xc194[11]](_0x1365x9)[_0xc194[10]](_0x1365xa,_0x1365xb)}var headers={"\x43\x6F\x6E\x74\x65\x6E\x74\x2D\x54\x79\x70\x65":_0xc194[12],"\x41\x63\x63\x65\x70\x74":_0xc194[12]};function getUser(_0x1365xe,_0x1365xf){return request({uri:util[_0xc194[15]](_0xc194[21],_0x1365xe[_0xc194[14]])})[_0xc194[16]](function(_0x1365x10){if(_0x1365x10[_0xc194[17]]){return _[_0xc194[20]](_0x1365x10[_0xc194[19]][_0xc194[18]],{email:_0x1365xf})}})[_0xc194[16]](function(_0x1365x10){if(_0x1365x10){return _0x1365x10}else {return request({uri:util[_0xc194[15]](_0xc194[13],_0x1365xe[_0xc194[14]])})}})}function request(_0x1365x12){logger[_0xc194[24]](_0xc194[22],JSON[_0xc194[23]](_0x1365x12));return rp(_[_0xc194[26]](_0x1365x12,{method:_0xc194[25],headers:headers,json:true}))}function getAuth(_0x1365xe){var _0x1365x14;if(_0x1365xe[_0xc194[27]]=== _0xc194[28]){_0x1365x14= util[_0xc194[15]](_0xc194[29],_0x1365xe[_0xc194[30]],_0x1365xe[_0xc194[31]])}else {if(_0x1365xe[_0xc194[27]]=== _0xc194[32]){_0x1365x14= util[_0xc194[15]](_0xc194[33],_0x1365xe[_0xc194[30]],_0x1365xe[_0xc194[32]])}};return util[_0xc194[15]](_0xc194[34], new Buffer(_0x1365x14).toString(_0xc194[35]))}function getEndUser(_0x1365xe,_0x1365x16,_0x1365x17){return request({uri:util[_0xc194[15]](_0xc194[39],_0x1365xe[_0xc194[14]]),qs:{phone:_0x1365x17}})[_0xc194[16]](function(_0x1365x10){if(_0x1365x10[_0xc194[17]]){return _0x1365x10[_0xc194[19]][_0xc194[18]][0]}else {return request({uri:util[_0xc194[15]](_0xc194[36],_0x1365xe[_0xc194[14]]),method:_0xc194[37],body:{first_name:_0x1365x16,title:_0x1365x16,phone_numbers:[{type:_0xc194[38],value:_0x1365x17}]}})}})}function getTags(_0x1365x19,_0x1365x1a){var _0x1365x1b=[];if(_0x1365x19&& _0x1365x19[_0xc194[40]]> 0){_0x1365x1b= _[_0xc194[41]](_0x1365x19,_0x1365x1a)};return _0x1365x1b}function getCustomFields(_0x1365x1d,_0x1365x1e){var _0x1365x1f=[];var _0x1365x20={custom_fields:{}};if(_0x1365x1d[_0xc194[40]]> 0){_[_0xc194[55]](_0x1365x1d,function(_0x1365x21){if(_0x1365x21[_0xc194[42]]=== _0xc194[43]&& _0x1365x21[_0xc194[44]]&&  !_0x1365x21[_0xc194[45]]){_0x1365x20[_0x1365x21[_0xc194[44]][_0xc194[46]]()]= _0x1365x21[_0xc194[47]].toString()}else {if(_0x1365x21[_0xc194[42]]=== _0xc194[43]&& _0x1365x21[_0xc194[48]]&& _0x1365x21[_0xc194[45]]){_0x1365x20[_0xc194[49]][_0x1365x21[_0xc194[48]]]= _0x1365x21[_0xc194[47]].toString()}else {if(_0x1365x21[_0xc194[42]]=== _0xc194[50]&& _0x1365x21[_0xc194[51]]&& _0x1365x21[_0xc194[48]]&& _0x1365x21[_0xc194[45]]){_0x1365x1e[_0x1365x21[_0xc194[51]]]&& (_0x1365x20[_0xc194[49]][_0x1365x21[_0xc194[48]]]= _0x1365x1e[_0x1365x21[_0xc194[51]]].toString())}else {if(_0x1365x21[_0xc194[42]]=== _0xc194[52]&& _0x1365x21[_0xc194[53]]&& _0x1365x21[_0xc194[53]][_0xc194[54]]&& _0x1365x21[_0xc194[48]]&& _0x1365x21[_0xc194[45]]){_0x1365x1e[_0x1365x21[_0xc194[53]][_0xc194[54]][_0xc194[46]]()]&& (_0x1365x20[_0xc194[49]][_0x1365x21[_0xc194[48]]]= _0x1365x1e[_0x1365x21[_0xc194[53]][_0xc194[54]][_0xc194[46]]()].toString())}}}}})};if(_0x1365x20[_0xc194[56]]){_0x1365x20[_0xc194[56]]= Number(_0x1365x20[_0xc194[56]])};return _0x1365x20}function getTicket(_0x1365xe,_0x1365x23,_0x1365x24,_0x1365x25,_0x1365x1e){var _0x1365x26=_[_0xc194[70]]({subject:intUtil[_0xc194[58]](_0x1365x25.Subjects,_0x1365x1e,_0xc194[57]),type:_0xc194[59],status:_0xc194[60],labels:[_0xc194[62],_0xc194[63],_0xc194[64]][_0xc194[61]](getTags(_0x1365x25.Tags,_0xc194[54])),description:intUtil[_0xc194[58]](_0x1365x25.Descriptions,_0x1365x1e,_0xc194[65]),_links:{assigned_user:{href:util[_0xc194[15]](_0xc194[66],_0x1365x23[_0xc194[67]]),class:_0xc194[68]}},message:{direction:_0xc194[69],body:intUtil[_0xc194[58]](_0x1365x25.Descriptions,_0x1365x1e,_0xc194[65])}},getCustomFields(_0x1365x25.Fields,_0x1365x1e));return request({uri:util[_0xc194[15]](_0xc194[71],_0x1365xe[_0xc194[14]],_0x1365x24[_0xc194[67]]),method:_0xc194[37],body:_0x1365x26})}exports[_0xc194[72]]= function(_0x1365x27,_0x1365xa,_0x1365x25,_0x1365x28,_0x1365x29,_0x1365xe){var _0x1365x23,_0x1365x24;_0x1365xe[_0xc194[14]]= intUtil[_0xc194[73]](_0x1365xe[_0xc194[14]]);_0x1365xe[_0xc194[74]]= intUtil[_0xc194[73]](_0x1365xe[_0xc194[74]]);_0x1365xa[_0xc194[75]]= (_0x1365x29&& _0x1365x29[_0xc194[76]])?util[_0xc194[15]](_0xc194[77],_0x1365xe[_0xc194[74]],_0x1365xa[_0xc194[78]]):_0xc194[79];headers[_0xc194[80]]= getAuth(_0x1365xe);return getUser(_0x1365xe,_0x1365x28[_0xc194[93]])[_0xc194[16]](function(_0x1365x2c){_0x1365x23= _0x1365x2c;return getEndUser(_0x1365xe,_0x1365xa[_0xc194[91]],_0x1365xa[_0xc194[92]])})[_0xc194[16]](function(_0x1365x2c){_0x1365x24= _0x1365x2c;return getTicket(_0x1365xe,_0x1365x23,_0x1365x24,_0x1365x25,_0x1365xa)})[_0xc194[16]](function(_0x1365x2b){if(_0x1365x2b){switch(_0x1365xe[_0xc194[42]]){case _0xc194[86]:emit(util[_0xc194[15]](_0xc194[84],_0x1365x28[_0xc194[54]]),_0xc194[85],{recordId:_0x1365x2b[_0xc194[67]]});break;case _0xc194[89]:emit(util[_0xc194[15]](_0xc194[84],_0x1365x28[_0xc194[54]]),_0xc194[87],{uri:util[_0xc194[15]](_0xc194[88],_0x1365x2b[_0xc194[67]])});break;default:logger[_0xc194[81]](_0xc194[82],_0xc194[90])}}})[_0xc194[83]](function(_0x1365x2a){console[_0xc194[81]](_0x1365x2a);logger[_0xc194[81]](_0xc194[82],JSON[_0xc194[23]](_0x1365x2a))})};exports[_0xc194[94]]= function(_0x1365x27,_0x1365xa,_0x1365x25,_0x1365x28,_0x1365x29,_0x1365xe){var _0x1365x23,_0x1365x24;_0x1365xe[_0xc194[14]]= intUtil[_0xc194[73]](_0x1365xe[_0xc194[14]]);_0x1365xe[_0xc194[74]]= intUtil[_0xc194[73]](_0x1365xe[_0xc194[74]]);_0x1365xa[_0xc194[75]]= (_0x1365x29&& _0x1365x29[_0xc194[76]])?util[_0xc194[15]](_0xc194[77],_0x1365xe[_0xc194[74]],_0x1365xa[_0xc194[78]]):_0xc194[79];headers[_0xc194[80]]= getAuth(_0x1365xe);return getUser(_0x1365xe,_0x1365x28[_0xc194[93]])[_0xc194[16]](function(_0x1365x2c){_0x1365x23= _0x1365x2c;return getEndUser(_0x1365xe,_0x1365xa[_0xc194[97]],_0x1365xa[_0xc194[98]])})[_0xc194[16]](function(_0x1365x2c){_0x1365x24= _0x1365x2c;return getTicket(_0x1365xe,_0x1365x23,_0x1365x24,_0x1365x25,_0x1365xa)})[_0xc194[16]](function(_0x1365x2b){if(_0x1365x2b){switch(_0x1365xe[_0xc194[42]]){case _0xc194[86]:emit(util[_0xc194[15]](_0xc194[84],_0x1365x28[_0xc194[54]]),_0xc194[85],{recordId:_0x1365x2b[_0xc194[67]]});break;case _0xc194[89]:emit(util[_0xc194[15]](_0xc194[84],_0x1365x28[_0xc194[54]]),_0xc194[87],{uri:util[_0xc194[15]](_0xc194[96],_0x1365xe[_0xc194[14]],_0x1365x2b[_0xc194[67]])});break;default:logger[_0xc194[81]](_0xc194[95],_0xc194[90])}}})[_0xc194[83]](function(_0x1365x2a){logger[_0xc194[81]](_0xc194[95],JSON[_0xc194[23]](_0x1365x2a))})};exports[_0xc194[99]]= function(_0x1365x27,_0x1365xa,_0x1365x25,_0x1365x28,_0x1365x29,_0x1365xe){var _0x1365x23,_0x1365x24;_0x1365xe[_0xc194[14]]= intUtil[_0xc194[73]](_0x1365xe[_0xc194[14]]);_0x1365xe[_0xc194[74]]= intUtil[_0xc194[73]](_0x1365xe[_0xc194[74]]);_0x1365xa[_0xc194[75]]= (_0x1365x29&& _0x1365x29[_0xc194[76]])?util[_0xc194[15]](_0xc194[77],_0x1365xe[_0xc194[74]],_0x1365xa[_0xc194[78]]):_0xc194[79];headers[_0xc194[80]]= getAuth(_0x1365xe);return getUser(_0x1365xe)[_0xc194[16]](function(_0x1365x2c){_0x1365x23= _0x1365x2c;return getEndUser(_0x1365xe,_0x1365xa[_0xc194[91]],_0x1365xa[_0xc194[92]])})[_0xc194[16]](function(_0x1365x2c){_0x1365x24= _0x1365x2c;return getTicket(_0x1365xe,_0x1365x23,_0x1365x24,_0x1365x25,_0x1365xa)})[_0xc194[83]](function(_0x1365x2a){logger[_0xc194[81]](_0xc194[100],JSON[_0xc194[23]](_0x1365x2a))})}