Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 259e956..824e417 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x644f=['fields','length','includeAll','merge','find','body','describe','SmsMessage','addMessage','omit','ids','getMessages','findOne','hasOwnProperty','nolimit','order','sort','where','SmsInteractionId','filter','$gte','split','format','include','findAll','rows','addTags','setTags','Tag','emit','removeTags','download','unix','toString','join','server','tmp','transcript-%d-%s.zip','push','User','CmContact','Contact','firstName','lastName','Messages','createdAt','direction','read','SmsAccount','Account','Owner','fullname','get','mkdirSync','Sms','N.A.','closed','closedAt','YYYY-MM-DD\x20HH:mm:ss','out','System','secret','renderFile','root','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','log','err','unlinkSync','sendStatus','rimraf','zip-dir','util','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','defaults','redis','socket.io-emitter','register','status','end','offset','undefined','limit','count','Content-Range','json','update','destroy','then','error','name','send','index','map','SmsInteraction','rawAttributes','fieldName','type','key','getOptions','sms','query','catch','show','params','keys','filters','intersection','model','attributes'];(function(_0x17141f,_0x4d7c4b){var _0x3ee900=function(_0x5ec0f4){while(--_0x5ec0f4){_0x17141f['push'](_0x17141f['shift']());}};_0x3ee900(++_0x4d7c4b);}(_0x644f,0xc2));var _0xf644=function(_0x260f28,_0x4e9b30){_0x260f28=_0x260f28-0x0;var _0x3aefcc=_0x644f[_0x260f28];return _0x3aefcc;};'use strict';var rimraf=require(_0xf644('0x0'));var zipdir=require(_0xf644('0x1'));var moment=require('moment');var BPromise=require('bluebird');var util=require(_0xf644('0x2'));var path=require(_0xf644('0x3'));var ejs=require(_0xf644('0x4'));var fs=require('fs');var _=require(_0xf644('0x5'));var Redis=require(_0xf644('0x6'));var interaction=require(_0xf644('0x7'));var qs=require(_0xf644('0x8'));var pdf=require(_0xf644('0x9'));var logger=require(_0xf644('0xa'))(_0xf644('0xb'));var config=require(_0xf644('0xc'));var db=require(_0xf644('0xd'))['db'];config['redis']=_[_0xf644('0xe')](config[_0xf644('0xf')],{'host':'localhost','port':0x18eb});var socket=require(_0xf644('0x10'))(new Redis(config['redis']));require('./smsInteraction.socket')[_0xf644('0x11')](socket);function respondWithStatusCode(_0x4a490d,_0x2c7bd0){_0x2c7bd0=_0x2c7bd0||0xcc;return function(_0x865312){if(_0x865312){return _0x4a490d['sendStatus'](_0x2c7bd0);}return _0x4a490d[_0xf644('0x12')](_0x2c7bd0)[_0xf644('0x13')]();};}function respondWithResult(_0x1ef872,_0x5911d3){_0x5911d3=_0x5911d3||0xc8;return function(_0x296647){if(_0x296647){return _0x1ef872[_0xf644('0x12')](_0x5911d3)['json'](_0x296647);}};}function respondWithFilteredResult(_0x3678c9,_0xaa5d1c){return function(_0x4ed4d6){if(_0x4ed4d6){var _0x400906=typeof _0xaa5d1c[_0xf644('0x14')]===_0xf644('0x15')&&typeof _0xaa5d1c[_0xf644('0x16')]==='undefined';var _0x155fd9=_0x4ed4d6[_0xf644('0x17')];var _0x52f74a=_0x400906?0x0:_0xaa5d1c['offset'];var _0x4c197b=_0x400906?_0x4ed4d6['count']:_0xaa5d1c[_0xf644('0x14')]+_0xaa5d1c[_0xf644('0x16')];var _0x34dec2;if(_0x4c197b>=_0x155fd9){_0x4c197b=_0x155fd9;_0x34dec2=0xc8;}else{_0x34dec2=0xce;}_0x3678c9[_0xf644('0x12')](_0x34dec2);return _0x3678c9['set'](_0xf644('0x18'),_0x52f74a+'-'+_0x4c197b+'/'+_0x155fd9)[_0xf644('0x19')](_0x4ed4d6);}return null;};}function saveUpdates(_0x4650b5){return function(_0x44fc39){if(_0x44fc39){return _0x44fc39[_0xf644('0x1a')](_0x4650b5)['then'](function(_0x4beeb0){return _0x4beeb0;});}return null;};}function removeEntity(_0x37c32d){return function(_0x305515){if(_0x305515){return _0x305515[_0xf644('0x1b')]()[_0xf644('0x1c')](function(){_0x37c32d[_0xf644('0x12')](0xcc)[_0xf644('0x13')]();});}};}function handleEntityNotFound(_0x67e595){return function(_0x20c0fb){if(!_0x20c0fb){_0x67e595['sendStatus'](0x194);}return _0x20c0fb;};}function handleError(_0x14af1b,_0x1c36b4){_0x1c36b4=_0x1c36b4||0x1f4;return function(_0x2180c6){logger[_0xf644('0x1d')](_0x2180c6['stack']);if(_0x2180c6[_0xf644('0x1e')]){delete _0x2180c6[_0xf644('0x1e')];}_0x14af1b[_0xf644('0x12')](_0x1c36b4)[_0xf644('0x1f')](_0x2180c6);};}exports[_0xf644('0x20')]=function(_0x3173c1,_0xae30c0){var _0x4cb86c={};var _0x4b6369=_[_0xf644('0x21')](db[_0xf644('0x22')][_0xf644('0x23')],function(_0x383987){return{'name':_0x383987[_0xf644('0x24')],'type':_0x383987[_0xf644('0x25')][_0xf644('0x26')]};});_0x4cb86c=qs[_0xf644('0x27')](_0x4b6369,_0x3173c1);return interaction['findAll'](_0xf644('0x28'),_0x3173c1[_0xf644('0x29')],_0x3173c1['user'],_0x4cb86c,_0x4b6369)['then'](respondWithFilteredResult(_0xae30c0,_0x4cb86c))[_0xf644('0x2a')](handleError(_0xae30c0,null));};exports[_0xf644('0x2b')]=function(_0x16c745,_0x3881e3){var _0x2bcb20={'raw':![],'where':{'id':_0x16c745[_0xf644('0x2c')]['id']}},_0x1ef501={};_0x1ef501['model']=_[_0xf644('0x2d')](db[_0xf644('0x22')]['rawAttributes']);_0x1ef501['query']=_[_0xf644('0x2d')](_0x16c745[_0xf644('0x29')]);_0x1ef501[_0xf644('0x2e')]=_[_0xf644('0x2f')](_0x1ef501[_0xf644('0x30')],_0x1ef501[_0xf644('0x29')]);_0x2bcb20[_0xf644('0x31')]=_[_0xf644('0x2f')](_0x1ef501[_0xf644('0x30')],qs[_0xf644('0x32')](_0x16c745['query']['fields']));_0x2bcb20[_0xf644('0x31')]=_0x2bcb20[_0xf644('0x31')][_0xf644('0x33')]?_0x2bcb20[_0xf644('0x31')]:_0x1ef501[_0xf644('0x30')];if(_0x16c745[_0xf644('0x29')][_0xf644('0x34')]){_0x2bcb20['include']=[{'all':!![]}];}_0x2bcb20=_[_0xf644('0x35')]({},_0x2bcb20,_0x16c745['options']);return db['SmsInteraction'][_0xf644('0x36')](_0x2bcb20)[_0xf644('0x1c')](handleEntityNotFound(_0x3881e3,null))[_0xf644('0x1c')](respondWithResult(_0x3881e3,null))['catch'](handleError(_0x3881e3,null));};exports['create']=function(_0x3aa198,_0xd5790a){return db[_0xf644('0x22')]['create'](_0x3aa198[_0xf644('0x37')],{})[_0xf644('0x1c')](respondWithResult(_0xd5790a,0xc9))['catch'](handleError(_0xd5790a,null));};exports[_0xf644('0x1a')]=function(_0x67cbfc,_0x27fbc7){if(_0x67cbfc[_0xf644('0x37')]['id']){delete _0x67cbfc[_0xf644('0x37')]['id'];}return db[_0xf644('0x22')]['find']({'where':{'id':_0x67cbfc[_0xf644('0x2c')]['id']}})['then'](handleEntityNotFound(_0x27fbc7,null))[_0xf644('0x1c')](saveUpdates(_0x67cbfc[_0xf644('0x37')],null))[_0xf644('0x1c')](respondWithResult(_0x27fbc7,null))[_0xf644('0x2a')](handleError(_0x27fbc7,null));};exports[_0xf644('0x1b')]=function(_0x60bec,_0x52e738){return db[_0xf644('0x22')][_0xf644('0x36')]({'where':{'id':_0x60bec[_0xf644('0x2c')]['id']}})['then'](handleEntityNotFound(_0x52e738,null))['then'](removeEntity(_0x52e738,null))[_0xf644('0x2a')](handleError(_0x52e738,null));};exports[_0xf644('0x38')]=function(_0x11d879,_0x14efb3){return db['SmsInteraction'][_0xf644('0x38')]()['then'](respondWithResult(_0x14efb3,null))[_0xf644('0x2a')](handleError(_0x14efb3,null));};exports['addMessage']=function(_0x2d9f52,_0x3475cf){return db[_0xf644('0x39')][_0xf644('0x36')]({'where':{'id':_0x2d9f52['params']['id']}})[_0xf644('0x1c')](handleEntityNotFound(_0x3475cf,null))[_0xf644('0x1c')](function(_0x565e83){if(_0x565e83){return _0x565e83[_0xf644('0x3a')](_0x2d9f52[_0xf644('0x37')]['ids'],_[_0xf644('0x3b')](_0x2d9f52['body'],[_0xf644('0x3c'),'id'])||{});}})[_0xf644('0x1c')](respondWithResult(_0x3475cf,null))[_0xf644('0x2a')](handleError(_0x3475cf,null));};exports[_0xf644('0x3d')]=function(_0x29724d,_0x594615){var _0x1062e3={'raw':![],'where':{}};var _0x395340={};var _0x1b9e4f={'count':0x0,'rows':[]};return db[_0xf644('0x22')][_0xf644('0x3e')]({'where':{'id':_0x29724d['params']['id']}})[_0xf644('0x1c')](handleEntityNotFound(_0x594615,null))[_0xf644('0x1c')](function(_0x2db98c){if(_0x2db98c){_0x395340['model']=_[_0xf644('0x2d')](db[_0xf644('0x39')][_0xf644('0x23')]);_0x395340[_0xf644('0x29')]=_['keys'](_0x29724d['query']);_0x395340[_0xf644('0x2e')]=_[_0xf644('0x2f')](_0x395340[_0xf644('0x30')],_0x395340[_0xf644('0x29')]);_0x1062e3['attributes']=_['intersection'](_0x395340[_0xf644('0x30')],qs[_0xf644('0x32')](_0x29724d[_0xf644('0x29')]['fields']));_0x1062e3[_0xf644('0x31')]=_0x1062e3[_0xf644('0x31')][_0xf644('0x33')]?_0x1062e3[_0xf644('0x31')]:_0x395340[_0xf644('0x30')];if(!_0x29724d[_0xf644('0x29')][_0xf644('0x3f')](_0xf644('0x40'))){_0x1062e3[_0xf644('0x16')]=qs['limit'](_0x29724d[_0xf644('0x29')][_0xf644('0x16')]);_0x1062e3[_0xf644('0x14')]=qs[_0xf644('0x14')](_0x29724d[_0xf644('0x29')][_0xf644('0x14')]);}_0x1062e3[_0xf644('0x41')]=qs['sort'](_0x29724d[_0xf644('0x29')][_0xf644('0x42')]);_0x1062e3['where']=qs['filters'](_['pick'](_0x29724d[_0xf644('0x29')],_0x395340['filters']));_0x1062e3[_0xf644('0x43')][_0xf644('0x44')]=_0x2db98c['id'];if(_0x29724d['query'][_0xf644('0x45')]){_0x1062e3[_0xf644('0x43')]=_[_0xf644('0x35')](_0x1062e3[_0xf644('0x43')],{'$or':_[_0xf644('0x21')](_0x1062e3[_0xf644('0x31')],function(_0x40910c){var _0x3d0915={};_0x3d0915[_0x40910c]={'$like':'%'+_0x29724d['query'][_0xf644('0x45')]+'%'};return _0x3d0915;})});}if(_0x29724d[_0xf644('0x29')][_0xf644('0x46')]){var _0x53701d=_0x29724d[_0xf644('0x29')][_0xf644('0x46')][_0xf644('0x47')](',');var _0x58a3b8={};_0x58a3b8[_0x53701d[0x0]]={'$gte':moment(_0x53701d[0x1])[_0xf644('0x48')]('YYYY-MM-DD\x20HH:mm:ss')};_0x1062e3[_0xf644('0x43')]=_['merge'](_0x1062e3[_0xf644('0x43')],_0x58a3b8);}_0x1062e3=_[_0xf644('0x35')]({},_0x1062e3,_0x29724d['options']);return db[_0xf644('0x39')][_0xf644('0x17')]({'where':_0x1062e3[_0xf644('0x43')]})[_0xf644('0x1c')](function(_0x1d68fd){_0x1b9e4f['count']=_0x1d68fd;if(_0x29724d['query'][_0xf644('0x34')]){_0x1062e3[_0xf644('0x49')]=[{'all':!![]}];}return db[_0xf644('0x39')][_0xf644('0x4a')](_0x1062e3);})[_0xf644('0x1c')](function(_0x4763c7){_0x1b9e4f[_0xf644('0x4b')]=_0x4763c7;return _0x1b9e4f;});}})[_0xf644('0x1c')](respondWithFilteredResult(_0x594615,_0x1062e3))[_0xf644('0x2a')](handleError(_0x594615,null));};exports[_0xf644('0x4c')]=function(_0x389c40,_0xf74e1){return db[_0xf644('0x22')][_0xf644('0x36')]({'where':{'id':_0x389c40['params']['id']}})[_0xf644('0x1c')](handleEntityNotFound(_0xf74e1,null))[_0xf644('0x1c')](function(_0x2ad9a3){if(_0x2ad9a3){return _0x2ad9a3[_0xf644('0x4d')](_0x389c40[_0xf644('0x37')][_0xf644('0x3c')],_[_0xf644('0x3b')](_0x389c40[_0xf644('0x37')],[_0xf644('0x3c'),'id'])||{})['spread'](function(){return db[_0xf644('0x4e')][_0xf644('0x4a')]({'attributes':['id',_0xf644('0x1e'),'color'],'where':{'id':_0x389c40[_0xf644('0x37')][_0xf644('0x3c')]}});})['then'](function(_0x4efff5){socket[_0xf644('0x4f')]('smsInteractionTags:save',{'id':Number(_0x389c40[_0xf644('0x2c')]['id']),'tags':_0x4efff5||[]});return{'id':Number(_0x389c40[_0xf644('0x2c')]['id']),'tags':_0x4efff5||[]};});}})[_0xf644('0x1c')](respondWithResult(_0xf74e1,null))['catch'](handleError(_0xf74e1,null));};exports[_0xf644('0x50')]=function(_0xc225ae,_0x41e3d8){return db['SmsInteraction'][_0xf644('0x36')]({'where':{'id':_0xc225ae[_0xf644('0x2c')]['id']}})['then'](handleEntityNotFound(_0x41e3d8,null))[_0xf644('0x1c')](function(_0x479d21){if(_0x479d21){return _0x479d21[_0xf644('0x50')](_0xc225ae['query'][_0xf644('0x3c')]);}})['then'](respondWithStatusCode(_0x41e3d8,null))[_0xf644('0x2a')](handleError(_0x41e3d8,null));};exports[_0xf644('0x51')]=function(_0x27c13d,_0x36c5db){var _0x31e76a=moment()[_0xf644('0x52')]()[_0xf644('0x53')]();var _0xf258d8=path[_0xf644('0x54')](config['root'],_0xf644('0x55'),'files',_0xf644('0x56'));var _0x18b52b=path[_0xf644('0x54')](_0xf258d8,_0x31e76a);var _0xbd0649=util['format'](_0xf644('0x57'),_0x27c13d[_0xf644('0x2c')]['id'],_0x31e76a);var _0x2eac5e=path[_0xf644('0x54')](_0xf258d8,_0xbd0649);var _0x25ccee=[];_0x25ccee[_0xf644('0x58')]({'model':db[_0xf644('0x59')],'as':_0xf644('0x59'),'attributes':['id','fullname'],'raw':!![]});_0x25ccee[_0xf644('0x58')]({'model':db[_0xf644('0x5a')],'as':_0xf644('0x5b'),'attributes':['id',_0xf644('0x5c'),_0xf644('0x5d')],'raw':!![]});var _0x275a9e=[{'model':db[_0xf644('0x39')],'as':_0xf644('0x5e'),'attributes':['id','body',_0xf644('0x5f'),_0xf644('0x60'),'secret',_0xf644('0x61')],'include':_0x25ccee}];_0x275a9e['push']({'model':db[_0xf644('0x62')],'as':_0xf644('0x63'),'attributes':['id',_0xf644('0x1e')]});_0x275a9e['push']({'model':db['User'],'as':_0xf644('0x64'),'attributes':['id',_0xf644('0x65')]});return db[_0xf644('0x22')][_0xf644('0x36')]({'where':{'id':_0x27c13d[_0xf644('0x2c')]['id']},'include':_0x275a9e})['then'](handleEntityNotFound(_0x36c5db,null))[_0xf644('0x1c')](function(_0x4ec2b1){if(_0x4ec2b1){var _0x580871=_0x4ec2b1[_0xf644('0x66')]({'plain':!![]});fs[_0xf644('0x67')](_0x18b52b);var _0x174bfd={'channel':_0xf644('0x68'),'account':_0x580871[_0xf644('0x63')][_0xf644('0x1e')],'agent':_0x580871[_0xf644('0x64')]?_0x580871['Owner'][_0xf644('0x65')]:_0xf644('0x69'),'createdAt':moment(_0x580871[_0xf644('0x5f')])[_0xf644('0x48')]('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'closedAt':_0x580871[_0xf644('0x6a')]?moment(_0x580871[_0xf644('0x6b')])[_0xf644('0x48')](_0xf644('0x6c'))[_0xf644('0x53')]():'','disposition':_0x580871['disposition'],'messages':_(_0x580871['Messages'])['filter']({'secret':![]})[_0xf644('0x21')](function(_0xfd5aad){return{'date':moment(_0xfd5aad[_0xf644('0x5f')])[_0xf644('0x48')](_0xf644('0x6c'))['toString'](),'sender':_0xfd5aad[_0xf644('0x60')]===_0xf644('0x6d')?_0xfd5aad[_0xf644('0x59')]?_0xfd5aad[_0xf644('0x59')][_0xf644('0x65')]:_0xf644('0x6e'):_0xfd5aad[_0xf644('0x5b')]['firstName']+(_0xfd5aad['Contact'][_0xf644('0x5d')]?'\x20'+_0xfd5aad['Contact'][_0xf644('0x5d')]:''),'body':_0xfd5aad[_0xf644('0x37')],'direction':_0xfd5aad[_0xf644('0x60')]===_0xf644('0x6d')?'A':'C','secret':_0xfd5aad[_0xf644('0x6f')],'read':_0xfd5aad[_0xf644('0x61')]};})['value']()};return ejs[_0xf644('0x70')](path['join'](config[_0xf644('0x71')],'server','views',_0xf644('0x72')),{'interaction':_0x174bfd})['then'](function(_0x29f9f9){var _0x2310e8=path['join'](_0x18b52b,_0xf644('0x73')+_0x580871['id']+'-'+_0x31e76a+_0xf644('0x74'));var _0x173a93={'path':_0x2310e8,'channel':_0xf644('0x68'),'interactionId':_0x580871['id']};return pdf[_0xf644('0x75')](_0x29f9f9,_0x173a93);})[_0xf644('0x1c')](function(){return new BPromise(function(_0x1a3ba2,_0x152f1e){zipdir(_0x18b52b,{'saveTo':_0x2eac5e},function(_0x50bdd7,_0x4f485f){if(_0x50bdd7)return _0x152f1e(_0x50bdd7);return _0x1a3ba2(_0x4f485f);});})['then'](function(){return new BPromise(function(_0x49f208,_0x4b3a85){rimraf(_0x18b52b,function(_0x59d2e1){if(_0x59d2e1)_0x4b3a85(_0x59d2e1);return _0x49f208();});});})[_0xf644('0x1c')](function(){return _0x36c5db['download'](_0x2eac5e,_0xbd0649,function(_0x17586f){if(_0x17586f){console[_0xf644('0x76')](_0xf644('0x77'),_0x17586f);}else{fs[_0xf644('0x78')](_0x2eac5e);}});});});}else{return _0x36c5db[_0xf644('0x79')](0xc8);}})['catch'](handleError(_0x36c5db,null));};
\ No newline at end of file
+var _0x254a=['findAll','sms','query','catch','show','params','model','keys','filters','intersection','fields','attributes','length','includeAll','merge','options','SmsInteraction','find','create','body','describe','addMessage','SmsMessage','omit','ids','getMessages','hasOwnProperty','nolimit','order','where','pick','SmsInteractionId','filter','$gte','split','YYYY-MM-DD\x20HH:mm:ss','include','addTags','setTags','spread','color','emit','smsInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','transcript-%d-%s.zip','push','User','CmContact','Contact','firstName','Messages','createdAt','direction','secret','SmsAccount','Account','Owner','fullname','mkdirSync','Sms','N.A.','closedAt','out','lastName','read','renderFile','views','transcript-','createPdfFromHTML','log','err','unlinkSync','rimraf','zip-dir','moment','util','path','ejs','lodash','../../components/interaction/service','../../components/export/pdf','../../config/logger','api','redis','defaults','localhost','./smsInteraction.socket','sendStatus','status','end','json','offset','undefined','limit','count','update','then','destroy','error','stack','name','send','map','rawAttributes','fieldName','type','key','getOptions'];(function(_0x312775,_0x486f37){var _0x3cff11=function(_0x4c4715){while(--_0x4c4715){_0x312775['push'](_0x312775['shift']());}};_0x3cff11(++_0x486f37);}(_0x254a,0x138));var _0xa254=function(_0x41598b,_0x897d53){_0x41598b=_0x41598b-0x0;var _0x2cb5e5=_0x254a[_0x41598b];return _0x2cb5e5;};'use strict';var rimraf=require(_0xa254('0x0'));var zipdir=require(_0xa254('0x1'));var moment=require(_0xa254('0x2'));var BPromise=require('bluebird');var util=require(_0xa254('0x3'));var path=require(_0xa254('0x4'));var ejs=require(_0xa254('0x5'));var fs=require('fs');var _=require(_0xa254('0x6'));var Redis=require('ioredis');var interaction=require(_0xa254('0x7'));var qs=require('../../components/parsers/qs');var pdf=require(_0xa254('0x8'));var logger=require(_0xa254('0x9'))(_0xa254('0xa'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];config[_0xa254('0xb')]=_[_0xa254('0xc')](config['redis'],{'host':_0xa254('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xa254('0xb')]));require(_0xa254('0xe'))['register'](socket);function respondWithStatusCode(_0x4fc5f2,_0x346ea1){_0x346ea1=_0x346ea1||0xcc;return function(_0x2a4519){if(_0x2a4519){return _0x4fc5f2[_0xa254('0xf')](_0x346ea1);}return _0x4fc5f2[_0xa254('0x10')](_0x346ea1)[_0xa254('0x11')]();};}function respondWithResult(_0x533881,_0x11965c){_0x11965c=_0x11965c||0xc8;return function(_0x5b5f73){if(_0x5b5f73){return _0x533881['status'](_0x11965c)[_0xa254('0x12')](_0x5b5f73);}};}function respondWithFilteredResult(_0x1e3cf8,_0x504296){return function(_0x22c469){if(_0x22c469){var _0x46322b=typeof _0x504296[_0xa254('0x13')]===_0xa254('0x14')&&typeof _0x504296[_0xa254('0x15')]==='undefined';var _0x217467=_0x22c469[_0xa254('0x16')];var _0x7532b7=_0x46322b?0x0:_0x504296[_0xa254('0x13')];var _0x37586e=_0x46322b?_0x22c469[_0xa254('0x16')]:_0x504296[_0xa254('0x13')]+_0x504296[_0xa254('0x15')];var _0x348a64;if(_0x37586e>=_0x217467){_0x37586e=_0x217467;_0x348a64=0xc8;}else{_0x348a64=0xce;}_0x1e3cf8['status'](_0x348a64);return _0x1e3cf8['set']('Content-Range',_0x7532b7+'-'+_0x37586e+'/'+_0x217467)[_0xa254('0x12')](_0x22c469);}return null;};}function saveUpdates(_0x2dcf3a){return function(_0x31ec79){if(_0x31ec79){return _0x31ec79[_0xa254('0x17')](_0x2dcf3a)[_0xa254('0x18')](function(_0x1b7773){return _0x1b7773;});}return null;};}function removeEntity(_0x25455e){return function(_0x4d82f9){if(_0x4d82f9){return _0x4d82f9[_0xa254('0x19')]()['then'](function(){_0x25455e[_0xa254('0x10')](0xcc)[_0xa254('0x11')]();});}};}function handleEntityNotFound(_0x572b2f){return function(_0x3a1927){if(!_0x3a1927){_0x572b2f[_0xa254('0xf')](0x194);}return _0x3a1927;};}function handleError(_0x53f908,_0x5d8bcc){_0x5d8bcc=_0x5d8bcc||0x1f4;return function(_0x34c7c4){logger[_0xa254('0x1a')](_0x34c7c4[_0xa254('0x1b')]);if(_0x34c7c4['name']){delete _0x34c7c4[_0xa254('0x1c')];}_0x53f908[_0xa254('0x10')](_0x5d8bcc)[_0xa254('0x1d')](_0x34c7c4);};}exports['index']=function(_0x4bd012,_0xe734d5){var _0xcbf8c4={};var _0x3c2a25=_[_0xa254('0x1e')](db['SmsInteraction'][_0xa254('0x1f')],function(_0xdd8c94){return{'name':_0xdd8c94[_0xa254('0x20')],'type':_0xdd8c94[_0xa254('0x21')][_0xa254('0x22')]};});_0xcbf8c4=qs[_0xa254('0x23')](_0x3c2a25,_0x4bd012);return interaction[_0xa254('0x24')](_0xa254('0x25'),_0x4bd012[_0xa254('0x26')],_0x4bd012['user'],_0xcbf8c4,_0x3c2a25)[_0xa254('0x18')](respondWithFilteredResult(_0xe734d5,_0xcbf8c4))[_0xa254('0x27')](handleError(_0xe734d5,null));};exports[_0xa254('0x28')]=function(_0x135cf3,_0x627344){var _0x5c9e28={'raw':![],'where':{'id':_0x135cf3[_0xa254('0x29')]['id']}},_0xa6aad0={};_0xa6aad0[_0xa254('0x2a')]=_[_0xa254('0x2b')](db['SmsInteraction'][_0xa254('0x1f')]);_0xa6aad0[_0xa254('0x26')]=_[_0xa254('0x2b')](_0x135cf3[_0xa254('0x26')]);_0xa6aad0[_0xa254('0x2c')]=_[_0xa254('0x2d')](_0xa6aad0[_0xa254('0x2a')],_0xa6aad0[_0xa254('0x26')]);_0x5c9e28['attributes']=_[_0xa254('0x2d')](_0xa6aad0[_0xa254('0x2a')],qs[_0xa254('0x2e')](_0x135cf3[_0xa254('0x26')]['fields']));_0x5c9e28[_0xa254('0x2f')]=_0x5c9e28[_0xa254('0x2f')][_0xa254('0x30')]?_0x5c9e28['attributes']:_0xa6aad0[_0xa254('0x2a')];if(_0x135cf3[_0xa254('0x26')][_0xa254('0x31')]){_0x5c9e28['include']=[{'all':!![]}];}_0x5c9e28=_[_0xa254('0x32')]({},_0x5c9e28,_0x135cf3[_0xa254('0x33')]);return db[_0xa254('0x34')][_0xa254('0x35')](_0x5c9e28)[_0xa254('0x18')](handleEntityNotFound(_0x627344,null))[_0xa254('0x18')](respondWithResult(_0x627344,null))[_0xa254('0x27')](handleError(_0x627344,null));};exports[_0xa254('0x36')]=function(_0x172d0d,_0x4aa54e){return db['SmsInteraction'][_0xa254('0x36')](_0x172d0d[_0xa254('0x37')],{})['then'](respondWithResult(_0x4aa54e,0xc9))[_0xa254('0x27')](handleError(_0x4aa54e,null));};exports['update']=function(_0x5d1cd0,_0x288c66){if(_0x5d1cd0[_0xa254('0x37')]['id']){delete _0x5d1cd0[_0xa254('0x37')]['id'];}return db[_0xa254('0x34')]['find']({'where':{'id':_0x5d1cd0[_0xa254('0x29')]['id']}})[_0xa254('0x18')](handleEntityNotFound(_0x288c66,null))[_0xa254('0x18')](saveUpdates(_0x5d1cd0[_0xa254('0x37')],null))[_0xa254('0x18')](respondWithResult(_0x288c66,null))[_0xa254('0x27')](handleError(_0x288c66,null));};exports[_0xa254('0x19')]=function(_0x120195,_0x1a7d06){return db[_0xa254('0x34')][_0xa254('0x35')]({'where':{'id':_0x120195[_0xa254('0x29')]['id']}})[_0xa254('0x18')](handleEntityNotFound(_0x1a7d06,null))['then'](removeEntity(_0x1a7d06,null))['catch'](handleError(_0x1a7d06,null));};exports[_0xa254('0x38')]=function(_0x15fe81,_0x5e359f){return db['SmsInteraction'][_0xa254('0x38')]()[_0xa254('0x18')](respondWithResult(_0x5e359f,null))[_0xa254('0x27')](handleError(_0x5e359f,null));};exports[_0xa254('0x39')]=function(_0x3d9efa,_0x2efe10){return db[_0xa254('0x3a')]['find']({'where':{'id':_0x3d9efa[_0xa254('0x29')]['id']}})[_0xa254('0x18')](handleEntityNotFound(_0x2efe10,null))[_0xa254('0x18')](function(_0xf1ee69){if(_0xf1ee69){return _0xf1ee69[_0xa254('0x39')](_0x3d9efa[_0xa254('0x37')]['ids'],_[_0xa254('0x3b')](_0x3d9efa[_0xa254('0x37')],[_0xa254('0x3c'),'id'])||{});}})[_0xa254('0x18')](respondWithResult(_0x2efe10,null))[_0xa254('0x27')](handleError(_0x2efe10,null));};exports[_0xa254('0x3d')]=function(_0x3a3458,_0x32c60e){var _0x171d57={'raw':![],'where':{}};var _0x15bbba={};var _0x21f446={'count':0x0,'rows':[]};return db['SmsInteraction']['findOne']({'where':{'id':_0x3a3458[_0xa254('0x29')]['id']}})[_0xa254('0x18')](handleEntityNotFound(_0x32c60e,null))[_0xa254('0x18')](function(_0x4814e0){if(_0x4814e0){_0x15bbba[_0xa254('0x2a')]=_['keys'](db[_0xa254('0x3a')][_0xa254('0x1f')]);_0x15bbba[_0xa254('0x26')]=_['keys'](_0x3a3458[_0xa254('0x26')]);_0x15bbba['filters']=_[_0xa254('0x2d')](_0x15bbba[_0xa254('0x2a')],_0x15bbba[_0xa254('0x26')]);_0x171d57[_0xa254('0x2f')]=_[_0xa254('0x2d')](_0x15bbba['model'],qs[_0xa254('0x2e')](_0x3a3458['query'][_0xa254('0x2e')]));_0x171d57[_0xa254('0x2f')]=_0x171d57['attributes'][_0xa254('0x30')]?_0x171d57[_0xa254('0x2f')]:_0x15bbba[_0xa254('0x2a')];if(!_0x3a3458[_0xa254('0x26')][_0xa254('0x3e')](_0xa254('0x3f'))){_0x171d57[_0xa254('0x15')]=qs[_0xa254('0x15')](_0x3a3458['query']['limit']);_0x171d57['offset']=qs[_0xa254('0x13')](_0x3a3458['query'][_0xa254('0x13')]);}_0x171d57[_0xa254('0x40')]=qs['sort'](_0x3a3458[_0xa254('0x26')]['sort']);_0x171d57[_0xa254('0x41')]=qs[_0xa254('0x2c')](_[_0xa254('0x42')](_0x3a3458[_0xa254('0x26')],_0x15bbba[_0xa254('0x2c')]));_0x171d57[_0xa254('0x41')][_0xa254('0x43')]=_0x4814e0['id'];if(_0x3a3458[_0xa254('0x26')][_0xa254('0x44')]){_0x171d57[_0xa254('0x41')]=_[_0xa254('0x32')](_0x171d57['where'],{'$or':_[_0xa254('0x1e')](_0x171d57[_0xa254('0x2f')],function(_0x4056e6){var _0x624926={};_0x624926[_0x4056e6]={'$like':'%'+_0x3a3458[_0xa254('0x26')][_0xa254('0x44')]+'%'};return _0x624926;})});}if(_0x3a3458['query'][_0xa254('0x45')]){var _0x578233=_0x3a3458['query'][_0xa254('0x45')][_0xa254('0x46')](',');var _0x2869b1={};_0x2869b1[_0x578233[0x0]]={'$gte':moment(_0x578233[0x1])['format'](_0xa254('0x47'))};_0x171d57['where']=_[_0xa254('0x32')](_0x171d57[_0xa254('0x41')],_0x2869b1);}_0x171d57=_[_0xa254('0x32')]({},_0x171d57,_0x3a3458[_0xa254('0x33')]);return db[_0xa254('0x3a')]['count']({'where':_0x171d57[_0xa254('0x41')]})[_0xa254('0x18')](function(_0x2775ba){_0x21f446[_0xa254('0x16')]=_0x2775ba;if(_0x3a3458[_0xa254('0x26')][_0xa254('0x31')]){_0x171d57[_0xa254('0x48')]=[{'all':!![]}];}return db[_0xa254('0x3a')]['findAll'](_0x171d57);})[_0xa254('0x18')](function(_0x2fc253){_0x21f446['rows']=_0x2fc253;return _0x21f446;});}})[_0xa254('0x18')](respondWithFilteredResult(_0x32c60e,_0x171d57))[_0xa254('0x27')](handleError(_0x32c60e,null));};exports[_0xa254('0x49')]=function(_0x4e7e2b,_0x4fb797){return db[_0xa254('0x34')][_0xa254('0x35')]({'where':{'id':_0x4e7e2b[_0xa254('0x29')]['id']}})[_0xa254('0x18')](handleEntityNotFound(_0x4fb797,null))['then'](function(_0x348e6){if(_0x348e6){return _0x348e6[_0xa254('0x4a')](_0x4e7e2b[_0xa254('0x37')][_0xa254('0x3c')],_['omit'](_0x4e7e2b[_0xa254('0x37')],[_0xa254('0x3c'),'id'])||{})[_0xa254('0x4b')](function(){return db['Tag'][_0xa254('0x24')]({'attributes':['id',_0xa254('0x1c'),_0xa254('0x4c')],'where':{'id':_0x4e7e2b['body'][_0xa254('0x3c')]}});})[_0xa254('0x18')](function(_0x1bd93d){socket[_0xa254('0x4d')](_0xa254('0x4e'),{'id':Number(_0x4e7e2b['params']['id']),'tags':_0x1bd93d||[]});return{'id':Number(_0x4e7e2b['params']['id']),'tags':_0x1bd93d||[]};});}})[_0xa254('0x18')](respondWithResult(_0x4fb797,null))[_0xa254('0x27')](handleError(_0x4fb797,null));};exports[_0xa254('0x4f')]=function(_0x49d39f,_0x10b8be){return db[_0xa254('0x34')]['find']({'where':{'id':_0x49d39f[_0xa254('0x29')]['id']}})[_0xa254('0x18')](handleEntityNotFound(_0x10b8be,null))[_0xa254('0x18')](function(_0x29bdb9){if(_0x29bdb9){return _0x29bdb9[_0xa254('0x4f')](_0x49d39f[_0xa254('0x26')][_0xa254('0x3c')]);}})[_0xa254('0x18')](respondWithStatusCode(_0x10b8be,null))['catch'](handleError(_0x10b8be,null));};exports[_0xa254('0x50')]=function(_0x1d89fd,_0x5f1081){var _0x81b94f=moment()[_0xa254('0x51')]()[_0xa254('0x52')]();var _0xb21c9=path[_0xa254('0x53')](config[_0xa254('0x54')],_0xa254('0x55'),_0xa254('0x56'),_0xa254('0x57'));var _0x57d176=path['join'](_0xb21c9,_0x81b94f);var _0x1d7b8b=util['format'](_0xa254('0x58'),_0x1d89fd[_0xa254('0x29')]['id'],_0x81b94f);var _0x5eb711=path[_0xa254('0x53')](_0xb21c9,_0x1d7b8b);var _0x28d224=[];_0x28d224[_0xa254('0x59')]({'model':db[_0xa254('0x5a')],'as':_0xa254('0x5a'),'attributes':['id','fullname'],'raw':!![]});_0x28d224[_0xa254('0x59')]({'model':db[_0xa254('0x5b')],'as':_0xa254('0x5c'),'attributes':['id',_0xa254('0x5d'),'lastName'],'raw':!![]});var _0x62948f=[{'model':db[_0xa254('0x3a')],'as':_0xa254('0x5e'),'attributes':['id','body',_0xa254('0x5f'),_0xa254('0x60'),_0xa254('0x61'),'read'],'include':_0x28d224}];_0x62948f['push']({'model':db[_0xa254('0x62')],'as':_0xa254('0x63'),'attributes':['id',_0xa254('0x1c')]});_0x62948f[_0xa254('0x59')]({'model':db[_0xa254('0x5a')],'as':_0xa254('0x64'),'attributes':['id',_0xa254('0x65')]});return db[_0xa254('0x34')][_0xa254('0x35')]({'where':{'id':_0x1d89fd[_0xa254('0x29')]['id']},'include':_0x62948f})[_0xa254('0x18')](handleEntityNotFound(_0x5f1081,null))[_0xa254('0x18')](function(_0x478448){if(_0x478448){var _0x3cc896=_0x478448['get']({'plain':!![]});fs[_0xa254('0x66')](_0x57d176);var _0xc07788={'channel':_0xa254('0x67'),'account':_0x3cc896[_0xa254('0x63')][_0xa254('0x1c')],'agent':_0x3cc896[_0xa254('0x64')]?_0x3cc896[_0xa254('0x64')]['fullname']:_0xa254('0x68'),'createdAt':moment(_0x3cc896[_0xa254('0x5f')])['format'](_0xa254('0x47'))[_0xa254('0x52')](),'closedAt':_0x3cc896['closed']?moment(_0x3cc896[_0xa254('0x69')])['format'](_0xa254('0x47'))[_0xa254('0x52')]():'','disposition':_0x3cc896['disposition'],'messages':_(_0x3cc896['Messages'])['filter']({'secret':![]})['map'](function(_0x1b38e1){return{'date':moment(_0x1b38e1[_0xa254('0x5f')])['format'](_0xa254('0x47'))[_0xa254('0x52')](),'sender':_0x1b38e1['direction']===_0xa254('0x6a')?_0x1b38e1[_0xa254('0x5a')]?_0x1b38e1[_0xa254('0x5a')][_0xa254('0x65')]:'System':_0x1b38e1[_0xa254('0x5c')][_0xa254('0x5d')]+(_0x1b38e1[_0xa254('0x5c')][_0xa254('0x6b')]?'\x20'+_0x1b38e1['Contact'][_0xa254('0x6b')]:''),'body':_0x1b38e1[_0xa254('0x37')],'direction':_0x1b38e1[_0xa254('0x60')]==='out'?'A':'C','secret':_0x1b38e1[_0xa254('0x61')],'read':_0x1b38e1[_0xa254('0x6c')]};})['value']()};return ejs[_0xa254('0x6d')](path[_0xa254('0x53')](config[_0xa254('0x54')],_0xa254('0x55'),_0xa254('0x6e'),'downloadInteraction.ejs'),{'interaction':_0xc07788})['then'](function(_0x37f04d){var _0x173206=path[_0xa254('0x53')](_0x57d176,_0xa254('0x6f')+_0x3cc896['id']+'-'+_0x81b94f+'.pdf');var _0xb99519={'path':_0x173206,'channel':_0xa254('0x67'),'interactionId':_0x3cc896['id']};return pdf[_0xa254('0x70')](_0x37f04d,_0xb99519);})[_0xa254('0x18')](function(){return new BPromise(function(_0x123456,_0x51fd39){zipdir(_0x57d176,{'saveTo':_0x5eb711},function(_0x33cf5a,_0x448f85){if(_0x33cf5a)return _0x51fd39(_0x33cf5a);return _0x123456(_0x448f85);});})[_0xa254('0x18')](function(){return new BPromise(function(_0x1ccf16,_0x3248c9){rimraf(_0x57d176,function(_0x14ecd1){if(_0x14ecd1)_0x3248c9(_0x14ecd1);return _0x1ccf16();});});})['then'](function(){return _0x5f1081['download'](_0x5eb711,_0x1d7b8b,function(_0x14042c){if(_0x14042c){console[_0xa254('0x71')](_0xa254('0x72'),_0x14042c);}else{fs[_0xa254('0x73')](_0x5eb711);}});});});}else{return _0x5f1081[_0xa254('0xf')](0xc8);}})['catch'](handleError(_0x5f1081,null));};
\ No newline at end of file