18 var _0x54e8=['format','interaction','[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','null','acceptMessage','interface','channel','event','EventManager','acceptmessage','reject','[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','SIP/%s','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./openchannelMessage.socket','register','jayson/promise','client','http','info','request\x20sent','debug','OpenchannelMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','OpenchannelMessage,\x20%s,\x20%s','message','result','catch','end','status','json','count','offset','set','Content-Range','apply','then','destroy','sendStatus','stack','name','send','index','map','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','nolimit','limit','order','sort','where','pick','filters','filter','options','OpenchannelMessage','includeAll','include','findAll','show','params','rawAttributes','merge','create','body','update','find','describe','../../config/logger','openchannel-interactions','accept','openchannel','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','agent','get','OpenchannelInteraction','OpenchannelInteractionId','isNil','read1stAt'];(function(_0x1d3e62,_0x3a539e){var _0x1031d3=function(_0x5cf208){while(--_0x5cf208){_0x1d3e62['push'](_0x1d3e62['shift']());}};_0x1031d3(++_0x3a539e);}(_0x54e8,0x8a));var _0x854e=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x54e8[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x854e('0x0'));var rimraf=require(_0x854e('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x854e('0x2'));var rp=require(_0x854e('0x3'));var moment=require(_0x854e('0x4'));var BPromise=require(_0x854e('0x5'));var Mustache=require(_0x854e('0x6'));var util=require(_0x854e('0x7'));var path=require(_0x854e('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x854e('0x9'));var fs=require('fs');var fs_extra=require(_0x854e('0xa'));var _=require(_0x854e('0xb'));var squel=require(_0x854e('0xc'));var crypto=require(_0x854e('0xd'));var jsforce=require(_0x854e('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x854e('0xf'));var querystring=require(_0x854e('0x10'));var Papa=require(_0x854e('0x11'));var Redis=require(_0x854e('0x12'));var authService=require(_0x854e('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x854e('0x14'));var hardwareService=require(_0x854e('0x15'));var logger=require('../../config/logger')('api');var utils=require(_0x854e('0x16'));var config=require(_0x854e('0x17'));var licenseUtil=require(_0x854e('0x18'));var db=require(_0x854e('0x19'))['db'];config[_0x854e('0x1a')]=_[_0x854e('0x1b')](config[_0x854e('0x1a')],{'host':'localhost','port':0x18eb});var socket=require(_0x854e('0x1c'))(new Redis(config[_0x854e('0x1a')]));require(_0x854e('0x1d'))[_0x854e('0x1e')](socket);var jayson=require(_0x854e('0x1f'));var client=jayson[_0x854e('0x20')][_0x854e('0x21')]({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x1d5bcc,_0x38ce16,_0x565b7d,_0x1a156e){return new BPromise(function(_0x2e2e1d,_0x514925){var _0xa53799=_0x1a156e||client;return _0xa53799['request'](_0x1d5bcc,_0x565b7d)['then'](function(_0x53d30a){logger[_0x854e('0x22')]('OpenchannelMessage,\x20%s,\x20%s',_0x38ce16,_0x854e('0x23'));logger[_0x854e('0x24')](_0x854e('0x25'),_0x38ce16,'request\x20sent',JSON[_0x854e('0x26')](_0x53d30a));if(_0x53d30a['error']){if(_0x53d30a[_0x854e('0x27')][_0x854e('0x28')]===0x1f4){logger['error'](_0x854e('0x29'),_0x38ce16,_0x53d30a[_0x854e('0x27')][_0x854e('0x2a')]);return _0x514925(_0x53d30a[_0x854e('0x27')][_0x854e('0x2a')]);}logger[_0x854e('0x27')](_0x854e('0x29'),_0x38ce16,_0x53d30a[_0x854e('0x27')][_0x854e('0x2a')]);return _0x2e2e1d(_0x53d30a['error'][_0x854e('0x2a')]);}else{logger[_0x854e('0x22')](_0x854e('0x29'),_0x38ce16,_0x854e('0x23'));_0x2e2e1d(_0x53d30a[_0x854e('0x2b')][_0x854e('0x2a')]);}})[_0x854e('0x2c')](function(_0x573a27){logger['error'](_0x854e('0x29'),_0x38ce16,_0x573a27);_0x514925(_0x573a27);});});}function respondWithStatusCode(_0x6d8e31,_0x28ccfb){_0x28ccfb=_0x28ccfb||0xcc;return function(_0x33e379){if(_0x33e379){return _0x6d8e31['sendStatus'](_0x28ccfb);}return _0x6d8e31['status'](_0x28ccfb)[_0x854e('0x2d')]();};}function respondWithResult(_0x384d39,_0x3b28a7){_0x3b28a7=_0x3b28a7||0xc8;return function(_0x32b64b){if(_0x32b64b){return _0x384d39[_0x854e('0x2e')](_0x3b28a7)[_0x854e('0x2f')](_0x32b64b);}};}function respondWithFilteredResult(_0x37ce28,_0x33e9b3){return function(_0x2d0e1d){if(_0x2d0e1d){var _0x66dcc=_0x2d0e1d[_0x854e('0x30')],_0x3317e9=_0x33e9b3[_0x854e('0x31')],_0x3a0bef=_0x33e9b3[_0x854e('0x31')]+_0x33e9b3['limit'],_0xe0a05b;if(_0x3a0bef>=_0x66dcc){_0x3a0bef=_0x66dcc;_0xe0a05b=0xc8;}else{_0xe0a05b=0xce;}_0x37ce28[_0x854e('0x2e')](_0xe0a05b);return _0x37ce28[_0x854e('0x32')](_0x854e('0x33'),_0x3317e9+'-'+_0x3a0bef+'/'+_0x66dcc)[_0x854e('0x2f')](_0x2d0e1d);}return null;};}function patchUpdates(_0x58285c){return function(_0x5b62ac){try{jsonpatch[_0x854e('0x34')](_0x5b62ac,_0x58285c,!![]);}catch(_0x5b7e64){return BPromise['reject'](_0x5b7e64);}return _0x5b62ac['save']();};}function saveUpdates(_0x198598,_0x1352c8){return function(_0x11276e){if(_0x11276e){return _0x11276e['update'](_0x198598)[_0x854e('0x35')](function(_0x594aa0){return _0x594aa0;});}return null;};}function removeEntity(_0x54b461,_0x4237c8){return function(_0x3c87f6){if(_0x3c87f6){return _0x3c87f6[_0x854e('0x36')]()[_0x854e('0x35')](function(){_0x54b461[_0x854e('0x2e')](0xcc)[_0x854e('0x2d')]();});}};}function handleEntityNotFound(_0x205e47,_0x4b3d4a){return function(_0x1da725){if(!_0x1da725){_0x205e47[_0x854e('0x37')](0x194);}return _0x1da725;};}function handleError(_0x14c26c,_0x3b270a){_0x3b270a=_0x3b270a||0x1f4;return function(_0x55b61f){logger[_0x854e('0x27')](_0x55b61f[_0x854e('0x38')]);if(_0x55b61f[_0x854e('0x39')]){delete _0x55b61f[_0x854e('0x39')];}_0x14c26c[_0x854e('0x2e')](_0x3b270a)[_0x854e('0x3a')](_0x55b61f);};}exports[_0x854e('0x3b')]=function(_0x2906ab,_0x406b65){var _0x27ae69={},_0x1472e8={},_0x382134={'count':0x0,'rows':[]};var _0x355d66=_[_0x854e('0x3c')](db['OpenchannelMessage']['rawAttributes'],function(_0x53ee7b){return{'name':_0x53ee7b[_0x854e('0x3d')],'type':_0x53ee7b[_0x854e('0x3e')][_0x854e('0x3f')]};});_0x1472e8[_0x854e('0x40')]=_[_0x854e('0x3c')](_0x355d66,_0x854e('0x39'));_0x1472e8[_0x854e('0x41')]=_[_0x854e('0x42')](_0x2906ab[_0x854e('0x41')]);_0x1472e8['filters']=_[_0x854e('0x43')](_0x1472e8[_0x854e('0x40')],_0x1472e8[_0x854e('0x41')]);_0x27ae69[_0x854e('0x44')]=_[_0x854e('0x43')](_0x1472e8[_0x854e('0x40')],qs[_0x854e('0x45')](_0x2906ab[_0x854e('0x41')][_0x854e('0x45')]));_0x27ae69[_0x854e('0x44')]=_0x27ae69[_0x854e('0x44')][_0x854e('0x46')]?_0x27ae69[_0x854e('0x44')]:_0x1472e8['model'];if(!_0x2906ab['query']['hasOwnProperty'](_0x854e('0x47'))){_0x27ae69[_0x854e('0x48')]=qs['limit'](_0x2906ab[_0x854e('0x41')][_0x854e('0x48')]);_0x27ae69['offset']=qs[_0x854e('0x31')](_0x2906ab[_0x854e('0x41')][_0x854e('0x31')]);}_0x27ae69[_0x854e('0x49')]=qs[_0x854e('0x4a')](_0x2906ab['query']['sort']);_0x27ae69[_0x854e('0x4b')]=qs['filters'](_[_0x854e('0x4c')](_0x2906ab[_0x854e('0x41')],_0x1472e8[_0x854e('0x4d')]),_0x355d66);if(_0x2906ab[_0x854e('0x41')][_0x854e('0x4e')]){_0x27ae69['where']=_['merge'](_0x27ae69[_0x854e('0x4b')],{'$or':_[_0x854e('0x3c')](_0x355d66,function(_0x31e602){if(_0x31e602[_0x854e('0x3e')]!=='VIRTUAL'){var _0x43ee09={};_0x43ee09[_0x31e602[_0x854e('0x39')]]={'$like':'%'+_0x2906ab[_0x854e('0x41')][_0x854e('0x4e')]+'%'};return _0x43ee09;}})});}_0x27ae69=_['merge']({},_0x27ae69,_0x2906ab[_0x854e('0x4f')]);var _0x25c0a1={'where':_0x27ae69[_0x854e('0x4b')]};return db[_0x854e('0x50')]['count'](_0x25c0a1)[_0x854e('0x35')](function(_0x4adc6d){_0x382134['count']=_0x4adc6d;if(_0x2906ab[_0x854e('0x41')][_0x854e('0x51')]){_0x27ae69[_0x854e('0x52')]=[{'all':!![]}];}return db['OpenchannelMessage'][_0x854e('0x53')](_0x27ae69);})['then'](function(_0x78b3e2){_0x382134['rows']=_0x78b3e2;return _0x382134;})[_0x854e('0x35')](respondWithFilteredResult(_0x406b65,_0x27ae69))[_0x854e('0x2c')](handleError(_0x406b65,null));};exports[_0x854e('0x54')]=function(_0xe3e02d,_0x596d39){var _0x5a0145={'raw':!![],'where':{'id':_0xe3e02d[_0x854e('0x55')]['id']}},_0x7f2cf5={};_0x7f2cf5[_0x854e('0x40')]=_[_0x854e('0x42')](db[_0x854e('0x50')][_0x854e('0x56')]);_0x7f2cf5[_0x854e('0x41')]=_['keys'](_0xe3e02d['query']);_0x7f2cf5[_0x854e('0x4d')]=_[_0x854e('0x43')](_0x7f2cf5[_0x854e('0x40')],_0x7f2cf5['query']);_0x5a0145[_0x854e('0x44')]=_[_0x854e('0x43')](_0x7f2cf5[_0x854e('0x40')],qs[_0x854e('0x45')](_0xe3e02d[_0x854e('0x41')][_0x854e('0x45')]));_0x5a0145[_0x854e('0x44')]=_0x5a0145[_0x854e('0x44')][_0x854e('0x46')]?_0x5a0145[_0x854e('0x44')]:_0x7f2cf5[_0x854e('0x40')];if(_0xe3e02d[_0x854e('0x41')][_0x854e('0x51')]){_0x5a0145[_0x854e('0x52')]=[{'all':!![]}];}_0x5a0145=_[_0x854e('0x57')]({},_0x5a0145,_0xe3e02d[_0x854e('0x4f')]);return db[_0x854e('0x50')]['find'](_0x5a0145)[_0x854e('0x35')](handleEntityNotFound(_0x596d39,null))[_0x854e('0x35')](respondWithResult(_0x596d39,null))[_0x854e('0x2c')](handleError(_0x596d39,null));};exports[_0x854e('0x58')]=function(_0x4d1577,_0x16c9ad){return db[_0x854e('0x50')][_0x854e('0x58')](_0x4d1577[_0x854e('0x59')],{})[_0x854e('0x35')](respondWithResult(_0x16c9ad,0xc9))[_0x854e('0x2c')](handleError(_0x16c9ad,null));};exports[_0x854e('0x5a')]=function(_0x1671d2,_0x284597){if(_0x1671d2['body']['id']){delete _0x1671d2[_0x854e('0x59')]['id'];}return db[_0x854e('0x50')][_0x854e('0x5b')]({'where':{'id':_0x1671d2[_0x854e('0x55')]['id']}})['then'](handleEntityNotFound(_0x284597,null))[_0x854e('0x35')](saveUpdates(_0x1671d2[_0x854e('0x59')],null))[_0x854e('0x35')](respondWithResult(_0x284597,null))['catch'](handleError(_0x284597,null));};exports['destroy']=function(_0x11ff35,_0x134416){return db[_0x854e('0x50')]['find']({'where':{'id':_0x11ff35['params']['id']}})[_0x854e('0x35')](handleEntityNotFound(_0x134416,null))[_0x854e('0x35')](removeEntity(_0x134416,null))[_0x854e('0x2c')](handleError(_0x134416,null));};exports[_0x854e('0x5c')]=function(_0x3d545d,_0x241226){return db[_0x854e('0x50')]['describe']()['then'](respondWithResult(_0x241226,null))['catch'](handleError(_0x241226,null));};var interaction_log=require(_0x854e('0x5d'))(_0x854e('0x5e'));exports[_0x854e('0x5f')]=function(_0x226480,_0x14eedd,_0x4f49af){var _0x58feb6={'agent':{},'channel':_0x854e('0x60')};if(_0x226480['body']['id']){delete _0x226480['body']['id'];}_0x226480[_0x854e('0x59')]['read']=!![];_0x226480['body'][_0x854e('0x61')]=moment()['format'](_0x854e('0x62'));_0x226480['body'][_0x854e('0x63')]=_0x226480[_0x854e('0x59')][_0x854e('0x63')]||_0x226480['user']['id'];_0x58feb6[_0x854e('0x64')]['id']=_0x226480[_0x854e('0x59')][_0x854e('0x63')];return db[_0x854e('0x50')]['find']({'where':{'id':_0x226480[_0x854e('0x55')]['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':'Contact'}]})[_0x854e('0x35')](handleEntityNotFound(_0x14eedd,null))['then'](saveUpdates(_0x226480[_0x854e('0x59')],null))[_0x854e('0x35')](function(_0xa89c82){if(_0xa89c82){_0x58feb6['message']=_0xa89c82[_0x854e('0x65')]({'plain':!![]});return db[_0x854e('0x66')][_0x854e('0x5b')]({'where':{'id':_0xa89c82[_0x854e('0x67')]}});}return null;})['then'](handleEntityNotFound(_0x14eedd,null))[_0x854e('0x35')](function(_0x4bfcf9){if(_0x4bfcf9){return _0x4bfcf9[_0x854e('0x5a')]({'UserId':_0x226480[_0x854e('0x59')][_0x854e('0x63')],'read1stAt':_[_0x854e('0x68')](_0x4bfcf9[_0x854e('0x69')])?moment()[_0x854e('0x6a')](_0x854e('0x62')):undefined});}return null;})[_0x854e('0x35')](function(_0x15a48d){if(_0x15a48d){_0x58feb6[_0x854e('0x6b')]=_0x15a48d[_0x854e('0x65')]({'plain':!![]});interaction_log[_0x854e('0x22')](_0x854e('0x6c'),_0x226480[_0x854e('0x6d')]['id'],_0x226480[_0x854e('0x6d')]['name'],_0x226480[_0x854e('0x6d')][_0x854e('0x6e')],_0x58feb6[_0x854e('0x6b')]['id'],_0x226480[_0x854e('0x59')]?JSON[_0x854e('0x26')](_0x226480[_0x854e('0x59')]):_0x854e('0x6f'));return respondWithRpcPromise('AcceptMessage',_0x854e('0x70'),_0x58feb6);}return null;})[_0x854e('0x35')](function(_0xa900a9){if(_0xa900a9){if(_0x226480[_0x854e('0x59')]['manual']){_0x58feb6[_0x854e('0x2a')][_0x854e('0x71')]=util[_0x854e('0x6a')]('SIP/%s',_0x226480[_0x854e('0x6d')]['name']);_0x58feb6[_0x854e('0x2a')][_0x854e('0x72')]=_0x58feb6['channel'];_0x58feb6[_0x854e('0x2a')][_0x854e('0x73')]='accept';return respondWithRpcPromise(_0x854e('0x74'),_0x854e('0x74'),{'event':_0x854e('0x75'),'message':_0x58feb6['message']},client9002)[_0x854e('0x35')](function(){return _0x58feb6;});}return _0x58feb6;}return null;})[_0x854e('0x35')](respondWithResult(_0x14eedd,null))['catch'](handleError(_0x14eedd,null));};var interaction_log=require(_0x854e('0x5d'))('openchannel-interactions');exports[_0x854e('0x76')]=function(_0x4076e3,_0x1c078e,_0x18e9c1){var _0x284432={'agent':{},'channel':_0x854e('0x60')};if(_0x4076e3['body']['id']){delete _0x4076e3[_0x854e('0x59')]['id'];}_0x4076e3['body'][_0x854e('0x63')]=_0x4076e3[_0x854e('0x59')][_0x854e('0x63')]||_0x4076e3[_0x854e('0x6d')]['id'];_0x284432['agent']['id']=_0x4076e3[_0x854e('0x59')][_0x854e('0x63')];return db[_0x854e('0x50')][_0x854e('0x5b')]({'where':{'id':_0x4076e3[_0x854e('0x55')]['id'],'UserId':null}})[_0x854e('0x35')](handleEntityNotFound(_0x1c078e,null))[_0x854e('0x35')](function(_0x57ff87){if(_0x57ff87){_0x284432[_0x854e('0x2a')]=_0x57ff87[_0x854e('0x65')]({'plain':!![]});return db[_0x854e('0x66')]['find']({'where':{'id':_0x57ff87[_0x854e('0x67')]}});}return null;})[_0x854e('0x35')](handleEntityNotFound(_0x1c078e,null))[_0x854e('0x35')](function(_0x2161a7){if(_0x2161a7){_0x284432['interaction']=_0x2161a7[_0x854e('0x65')]({'plain':!![]});interaction_log[_0x854e('0x22')](_0x854e('0x77'),_0x4076e3[_0x854e('0x6d')]['id'],_0x4076e3[_0x854e('0x6d')]['name'],_0x4076e3[_0x854e('0x6d')]['role'],_0x284432[_0x854e('0x6b')]['id'],_0x4076e3[_0x854e('0x59')]?JSON['stringify'](_0x4076e3[_0x854e('0x59')]):'null');return respondWithRpcPromise(_0x854e('0x78'),'rejectMessage',_0x284432);}return null;})[_0x854e('0x35')](function(_0x8e1dd5){if(_0x8e1dd5){_0x8e1dd5[_0x854e('0x2a')]['interface']=util[_0x854e('0x6a')](_0x854e('0x79'),_0x4076e3['user'][_0x854e('0x39')]);_0x8e1dd5[_0x854e('0x2a')][_0x854e('0x72')]=_0x284432[_0x854e('0x72')];_0x8e1dd5[_0x854e('0x2a')][_0x854e('0x73')]=_0x854e('0x76');respondWithRpcPromise(_0x854e('0x74'),_0x854e('0x74'),{'event':'rejectmessage','message':_0x8e1dd5[_0x854e('0x2a')]},client9002);return _0x284432;}return null;})[_0x854e('0x35')](respondWithResult(_0x1c078e,null))[_0x854e('0x2c')](handleError(_0x1c078e,null));};