Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 030b14d..7ec3fcd 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9800=['lastName','Messages','createdAt','direction','Account','Owner','mkdirSync','40px','<hr\x20class=\x22separator\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22footer\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22left\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22center\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>{{page}}/{{pages}}</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22right\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','%s\x20#%d','Sms','YYYY-MM-DD','N.A.','closed','closedAt','disposition','System','firstName','out','secret','renderFile','views','downloadInteraction.html','create','toFile','transcript-','log','err','html-pdf','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','sox','to-csv','ejs','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','defaults','redis','register','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','destroy','then','stack','name','send','TagIds','Tags','split','forEach','catch','index','map','SmsInteraction','rawAttributes','fieldName','type','key','keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','select','field','color','from','tools_tags','u.id','u.fullname','ui.SmsInteractionId','left_join','users','u.id\x20=\x20ui.UserId','sms_interactions','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','sms_accounts','a.id\x20=\x20i.SmsAccountId','sms_interaction_has_tags','it.SmsInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','conditions','find','unreadMessages','value','having','`\x20>\x200','Contact','operator','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','body','text','some','compact','SmsAccountId','i.SmsAccountId\x20IN\x20?','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','filter','replace','isNumeric','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','Sequelize','QueryTypes','SELECT','isEmpty','t.id\x20IN\x20?','resolve','journey','user','role','getSmsAccounts','i.SmsAccountId\x20IS\x20NULL','agent','sequelize','toString','keyBy','merge','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.*','Contact.firstName','c.lastName','c.email','Contact.email','Contact.phone','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.SmsInteractionId\x20IN\x20?','groupBy','SmsInteractionId','push','all','rows','show','params','includeAll','include','describe','addMessage','SmsMessage','ids','omit','getMessages','pick','YYYY-MM-DD\x20HH:mm:ss','options','findAll','setTags','spread','emit','smsInteractionTags:save','removeTags','download','unix','join','root','server','tmp','files','attachments','format','transcript-%d-%s.zip','fullname','CmContact'];(function(_0x3cb7f5,_0x4f1868){var _0x21312a=function(_0x3dbd0a){while(--_0x3dbd0a){_0x3cb7f5['push'](_0x3cb7f5['shift']());}};_0x21312a(++_0x4f1868);}(_0x9800,0x1ee));var _0x0980=function(_0xf2e56b,_0x170412){_0xf2e56b=_0xf2e56b-0x0;var _0x40b011=_0x9800[_0xf2e56b];return _0x40b011;};'use strict';var pdf=require(_0x0980('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x0980('0x1'));var zipdir=require(_0x0980('0x2'));var jsonpatch=require(_0x0980('0x3'));var rp=require('request-promise');var moment=require(_0x0980('0x4'));var BPromise=require(_0x0980('0x5'));var Mustache=require('mustache');var util=require(_0x0980('0x6'));var path=require('path');var sox=require(_0x0980('0x7'));var csv=require(_0x0980('0x8'));var ejs=require(_0x0980('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0x0980('0xa'));var crypto=require(_0x0980('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x0980('0xc'));var toCsv=require('to-csv');var querystring=require(_0x0980('0xd'));var Papa=require(_0x0980('0xe'));var Redis=require(_0x0980('0xf'));var authService=require(_0x0980('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x0980('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x0980('0x12'))(_0x0980('0x13'));var utils=require(_0x0980('0x14'));var config=require(_0x0980('0x15'));var licenseUtil=require(_0x0980('0x16'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x0980('0x17')](config[_0x0980('0x18')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./smsInteraction.socket')[_0x0980('0x19')](socket);function respondWithStatusCode(_0x245501,_0x435291){_0x435291=_0x435291||0xcc;return function(_0x2d2f7d){if(_0x2d2f7d){return _0x245501[_0x0980('0x1a')](_0x435291);}return _0x245501[_0x0980('0x1b')](_0x435291)[_0x0980('0x1c')]();};}function respondWithResult(_0x15d305,_0x87e49f){_0x87e49f=_0x87e49f||0xc8;return function(_0x153859){if(_0x153859){return _0x15d305['status'](_0x87e49f)[_0x0980('0x1d')](_0x153859);}};}function respondWithFilteredResult(_0x2d7e10,_0x3da8df){return function(_0x4ed4f7){if(_0x4ed4f7){var _0x21867b=_0x4ed4f7[_0x0980('0x1e')],_0x272662=_0x3da8df[_0x0980('0x1f')],_0x5b4185=_0x3da8df[_0x0980('0x1f')]+_0x3da8df[_0x0980('0x20')],_0x28501f;if(_0x5b4185>=_0x21867b){_0x5b4185=_0x21867b;_0x28501f=0xc8;}else{_0x28501f=0xce;}_0x2d7e10[_0x0980('0x1b')](_0x28501f);return _0x2d7e10[_0x0980('0x21')](_0x0980('0x22'),_0x272662+'-'+_0x5b4185+'/'+_0x21867b)[_0x0980('0x1d')](_0x4ed4f7);}return null;};}function patchUpdates(_0x1bfe4b){return function(_0x118e78){try{jsonpatch[_0x0980('0x23')](_0x118e78,_0x1bfe4b,!![]);}catch(_0xf7489b){return BPromise[_0x0980('0x24')](_0xf7489b);}return _0x118e78[_0x0980('0x25')]();};}function saveUpdates(_0x5805a6,_0x56499b){return function(_0x1b5095){if(_0x1b5095){return _0x1b5095[_0x0980('0x26')](_0x5805a6)['then'](function(_0x409700){return _0x409700;});}return null;};}function removeEntity(_0x20d1da,_0x3da74c){return function(_0x5d6b56){if(_0x5d6b56){return _0x5d6b56[_0x0980('0x27')]()[_0x0980('0x28')](function(){_0x20d1da[_0x0980('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0xb879b2,_0x20af96){return function(_0x227516){if(!_0x227516){_0xb879b2[_0x0980('0x1a')](0x194);}return _0x227516;};}function handleError(_0x2bacc9,_0x1476c9){_0x1476c9=_0x1476c9||0x1f4;return function(_0x21baae){logger['error'](_0x21baae[_0x0980('0x29')]);if(_0x21baae[_0x0980('0x2a')]){delete _0x21baae['name'];}_0x2bacc9['status'](_0x1476c9)[_0x0980('0x2b')](_0x21baae);};}function getInteractionUsers(_0xc9958a,_0x29d5cc){return new BPromise(function(_0x3514de,_0x210f96){try{if(_0x29d5cc[_0xc9958a['id']]){_0xc9958a['Users']=_['map'](_0x29d5cc[_0xc9958a['id']],function(_0x7c7924){return{'id':_0x7c7924['id'],'fullname':_0x7c7924['fullname']};});}}catch(_0x1f1e21){_0x210f96(_0x1f1e21);}_0x3514de(_0xc9958a);});}function getInteractionTags(_0xfbb4ab,_0x241ee0){return new BPromise(function(_0x5bec0f,_0x3c02c0){try{if(_0xfbb4ab[_0x0980('0x2c')]){_0xfbb4ab[_0x0980('0x2d')]=[];_0xfbb4ab['TagIds'][_0x0980('0x2e')](',')[_0x0980('0x2f')](function(_0xc2c41b){_0xfbb4ab[_0x0980('0x2d')]['push'](_0x241ee0[_0xc2c41b]);});}delete _0xfbb4ab['TagIds'];}catch(_0x12bda5){_0x3c02c0(_0x12bda5);}_0x5bec0f(_0xfbb4ab);});}function updateSmsInteraction(_0xc4562f,_0x63138b,_0x467a81){return new BPromise(function(_0x2feaf1,_0x3dbf16){return getInteractionUsers(_0xc4562f,_0x467a81)[_0x0980('0x28')](function(_0x89c58){return getInteractionTags(_0x89c58,_0x63138b);})[_0x0980('0x28')](function(_0x1cc64a){_0x2feaf1(_0x1cc64a);})[_0x0980('0x30')](function(_0x59a2d1){_0x3dbf16(_0x59a2d1);});});}exports[_0x0980('0x31')]=function(_0x3d9a20,_0x5c6ea2){var _0x3fb28b={},_0x31b0a5={},_0x4d765b={'count':0x0,'rows':[]};var _0x50e281=_[_0x0980('0x32')](db[_0x0980('0x33')][_0x0980('0x34')],function(_0x23a8b7){return{'name':_0x23a8b7[_0x0980('0x35')],'type':_0x23a8b7[_0x0980('0x36')][_0x0980('0x37')]};});_0x31b0a5['model']=_['map'](_0x50e281,_0x0980('0x2a'));_0x31b0a5['query']=_[_0x0980('0x38')](_0x3d9a20[_0x0980('0x39')]);_0x31b0a5[_0x0980('0x3a')]=_[_0x0980('0x3b')](_0x31b0a5[_0x0980('0x3c')],_0x31b0a5[_0x0980('0x39')]);_0x3fb28b[_0x0980('0x3d')]=_[_0x0980('0x3b')](_0x31b0a5['model'],qs[_0x0980('0x3e')](_0x3d9a20[_0x0980('0x39')][_0x0980('0x3e')]));_0x3fb28b[_0x0980('0x3d')]=_0x3fb28b[_0x0980('0x3d')][_0x0980('0x3f')]?_0x3fb28b['attributes']:_0x31b0a5['model'];if(!_0x3d9a20[_0x0980('0x39')][_0x0980('0x40')](_0x0980('0x41'))){_0x3fb28b['limit']=qs[_0x0980('0x20')](_0x3d9a20[_0x0980('0x39')][_0x0980('0x20')]);_0x3fb28b[_0x0980('0x1f')]=qs[_0x0980('0x1f')](_0x3d9a20['query'][_0x0980('0x1f')]);}_0x3fb28b[_0x0980('0x42')]=qs[_0x0980('0x43')](_0x3d9a20['query'][_0x0980('0x43')]);_0x3fb28b[_0x0980('0x44')]=qs[_0x0980('0x3a')](_['pick'](_0x3d9a20[_0x0980('0x39')],_0x31b0a5[_0x0980('0x3a')]),_0x50e281);var _0x450146=[];var _0x2096ee=squel[_0x0980('0x45')]()[_0x0980('0x46')]('id')[_0x0980('0x46')](_0x0980('0x2a'))['field'](_0x0980('0x47'))[_0x0980('0x48')](_0x0980('0x49'));var _0x3ea610=squel['select']()[_0x0980('0x46')](_0x0980('0x4a'))[_0x0980('0x46')](_0x0980('0x4b'))[_0x0980('0x46')](_0x0980('0x4c'))[_0x0980('0x48')]('user_has_sms_interactions','ui')[_0x0980('0x4d')](_0x0980('0x4e'),'u',_0x0980('0x4f'));var _0x329365=squel['select']()[_0x0980('0x48')](_0x0980('0x50'),'i')[_0x0980('0x4d')]('cm_contacts','c',_0x0980('0x51'))[_0x0980('0x4d')]('users','o',_0x0980('0x52'))['left_join'](_0x0980('0x53'),'a',_0x0980('0x54'))[_0x0980('0x4d')]('sms_messages','me','me.SmsInteractionId\x20=\x20i.id')[_0x0980('0x4d')](_0x0980('0x55'),'it',_0x0980('0x56'))[_0x0980('0x4d')]('tools_tags','t',_0x0980('0x57'));var _0x24f656=squel[_0x0980('0x58')]();var _0x5bb9d1=[];var _0x165920=squel[_0x0980('0x58')]();var _0x3b03a5;if(_0x3d9a20[_0x0980('0x39')][_0x0980('0x59')]){_0x3b03a5=as[_0x0980('0x5a')](_0x3d9a20[_0x0980('0x39')]['search']);var _0x336e52=_0x3b03a5['sqlOperator'];for(var _0x1bae87=0x0;_0x1bae87<_0x3b03a5[_0x0980('0x5b')]['length'];_0x1bae87++){var _0x27e2e8=_0x3b03a5[_0x0980('0x5b')][_0x1bae87];var _0x2b108a='i';var _0x93112e=_[_0x0980('0x5c')](_0x50e281,[_0x0980('0x2a'),_0x27e2e8[_0x0980('0x46')]]);if(!_0x93112e){switch(_0x27e2e8[_0x0980('0x46')]){case _0x0980('0x5d'):if(_0x27e2e8[_0x0980('0x5e')]==0x1){_0x329365[_0x0980('0x5f')]('`'+_0x27e2e8[_0x0980('0x46')]+'`\x20=\x200');}else{_0x329365[_0x0980('0x5f')]('`'+_0x27e2e8[_0x0980('0x46')]+_0x0980('0x60'));}break;case _0x0980('0x61'):if(_0x27e2e8[_0x0980('0x62')]==='$substring'){if(_0x27e2e8[_0x0980('0x5e')][_0x0980('0x2e')]('\x20')[_0x0980('0x3f')]>0x1){_0x24f656[_0x336e52](_0x0980('0x63'),qs[_0x0980('0x64')](_0x27e2e8[_0x0980('0x5e')]),null);}else{var _0xc93c1c='%'+_0x27e2e8['value']+'%';_0x24f656[_0x336e52](_0x0980('0x65'),_0xc93c1c,_0xc93c1c,_0xc93c1c);}}else{_0x93112e=_['find'](_0x50e281,['name',_0x0980('0x66')]);_0x27e2e8['field']=_0x0980('0x66');_0x3d592d=as[_0x0980('0x67')](_0x2b108a,_0x93112e[_0x0980('0x36')],_0x27e2e8);_0x24f656[_0x336e52](_0x3d592d['text'],_0x3d592d[_0x0980('0x5e')][_0x0980('0x68')],_0x3d592d[_0x0980('0x5e')][_0x0980('0x1c')]);}break;case _0x0980('0x69'):var _0x27d08d=_0x27e2e8['value'][_0x0980('0x2e')](',')[_0x0980('0x32')](function(_0x19bb7e){return Number(_0x19bb7e);});_0x27d08d[_0x0980('0x2f')](function(_0x4a8a69){_0x165920['or'](_0x0980('0x6a'),'%,'+_0x4a8a69+',%');});_0x5bb9d1=_[_0x0980('0x6b')](_0x5bb9d1,_0x27d08d);break;case _0x0980('0x6c'):if(_0x27e2e8[_0x0980('0x62')]===_0x0980('0x6d')){_0x24f656[_0x336e52](_0x0980('0x6e'),'%'+_0x27e2e8[_0x0980('0x5e')]+'%',null);}else{_0x93112e=_[_0x0980('0x5c')](_0x50e281,[_0x0980('0x2a'),_0x0980('0x6f')]);_0x27e2e8['field']=_0x0980('0x6f');_0x3d592d=as[_0x0980('0x67')](_0x2b108a,_0x93112e[_0x0980('0x36')],_0x27e2e8);_0x24f656[_0x336e52](_0x3d592d['text'],_0x3d592d[_0x0980('0x5e')]['start'],_0x3d592d[_0x0980('0x5e')][_0x0980('0x1c')]);}break;case _0x0980('0x70'):_0x3d592d=as[_0x0980('0x67')]('me',null,_0x27e2e8);_0x24f656[_0x336e52](_0x3d592d['text'],_0x3d592d['value'][_0x0980('0x68')],_0x3d592d[_0x0980('0x5e')][_0x0980('0x1c')]);break;}}else{var _0x3d592d=as[_0x0980('0x67')](_0x2b108a,_0x93112e[_0x0980('0x36')],_0x27e2e8);_0x24f656[_0x336e52](_0x3d592d[_0x0980('0x71')],_0x3d592d['value'][_0x0980('0x68')],_0x3d592d[_0x0980('0x5e')][_0x0980('0x1c')]);}}}else{var _0x3b20fd=_(_0x3d9a20['query'])[_0x0980('0x38')]()['map'](function(_0x4155b9){return _[_0x0980('0x72')](_0x50e281,[_0x0980('0x2a'),_0x4155b9])?_0x4155b9:undefined;})[_0x0980('0x73')]()['value']();if(!_['isEmpty'](_0x3b20fd)){_0x3b20fd['forEach'](function(_0xe016b4){if(_0xe016b4===_0x0980('0x74')){_0x329365[_0x0980('0x44')](_0x0980('0x75'),[]['concat'](_0x3d9a20[_0x0980('0x39')][_0xe016b4]));}else if(_0xe016b4==='createdAt'){var _0x24e718=JSON[_0x0980('0x76')](_0x3d9a20[_0x0980('0x39')][_0xe016b4])[_0x0980('0x77')];var _0x3d746=JSON[_0x0980('0x76')](_0x3d9a20[_0x0980('0x39')][_0xe016b4])[_0x0980('0x78')];_0x329365[_0x0980('0x44')](_0x0980('0x79'),_0x24e718,_0x3d746);}else{if(_0x3d9a20[_0x0980('0x39')][_0xe016b4]==='null'){_0x329365['where']('i.'+_0xe016b4+_0x0980('0x7a'));}else{_0x329365[_0x0980('0x44')]('i.'+_0xe016b4+_0x0980('0x7b'),_0x3d9a20[_0x0980('0x39')][_0xe016b4]);}}});}if(_0x3d9a20[_0x0980('0x39')]['read']){if(_0x3d9a20[_0x0980('0x39')][_0x0980('0x7c')]==0x1){_0x329365[_0x0980('0x5f')](_0x0980('0x7d'));}else{_0x329365['having'](_0x0980('0x7e'));}}if(_0x3d9a20[_0x0980('0x39')][_0x0980('0x7f')]){_0x5bb9d1=_['isArray'](_0x3d9a20['query']['tag'])?_0x3d9a20['query'][_0x0980('0x7f')]:new Array(_0x3d9a20[_0x0980('0x39')][_0x0980('0x7f')]);_0x5bb9d1[_0x0980('0x2f')](function(_0x3689f5){_0x165920['or'](_0x0980('0x6a'),'%,'+_0x3689f5+',%');});}if(_0x3d9a20[_0x0980('0x39')]['filter']){var _0x187f64=_0x3d9a20[_0x0980('0x39')][_0x0980('0x80')][_0x0980('0x81')]('\x5c','\x5c\x5c')[_0x0980('0x81')](/'/g,'\x27\x27');if(qs[_0x0980('0x82')](_0x187f64)){_0x24f656['or'](_0x0980('0x83'),_0x187f64+'%')['or'](_0x0980('0x84'),_0x187f64+'%');}else{_0x24f656['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x0980('0x64')](_0x187f64))['or'](_0x0980('0x85'),_0x187f64+'%');}}}_0x329365['where'](_0x24f656);_0x329365['group']('i.id');var _0x1cff39={'type':db[_0x0980('0x86')][_0x0980('0x87')][_0x0980('0x88')],'raw':!![]};var _0x5dd162=_0x329365['clone']();_0x5dd162[_0x0980('0x46')]('i.id');_0x5dd162[_0x0980('0x46')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');if(_0x3fb28b[_0x0980('0x42')]){_0x3fb28b['order'][_0x0980('0x2f')](function(_0x5842de){var _0x51819c=_0x5842de[0x0]==='contactName'?_0x5842de[0x0]:'i.'+_0x5842de[0x0];_0x329365['order'](_0x51819c,_0x5842de[0x1]==='DESC'?![]:!![]);});}if(!_[_0x0980('0x89')](_0x5bb9d1)){_0x329365[_0x0980('0x5f')](_0x165920);_0x5dd162['where'](_0x0980('0x8a'),_0x5bb9d1);}BPromise[_0x0980('0x8b')]()[_0x0980('0x28')](function(){if(!_0x3b03a5){if(_0x3d9a20['query']['SmsAccountId']||_0x3d9a20[_0x0980('0x39')][_0x0980('0x8c')])return;_0x5dd162[_0x0980('0x44')]('i.SmsAccountId\x20IS\x20NOT\x20NULL');_0x329365[_0x0980('0x44')]('i.SmsAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x3d9a20[_0x0980('0x8d')][_0x0980('0x8e')]!=='agent')return;return _0x3d9a20['user'][_0x0980('0x8f')]({'attributes':['id'],'raw':!![]})[_0x0980('0x28')](function(_0x20731){if(_['isEmpty'](_0x20731)){_0x5dd162['where'](_0x0980('0x90'));_0x329365[_0x0980('0x44')](_0x0980('0x90'));}else{_0x5dd162[_0x0980('0x44')](_0x0980('0x75'),_['map'](_0x20731,'id'));_0x329365['where'](_0x0980('0x75'),_['map'](_0x20731,'id'));}});})[_0x0980('0x28')](function(){if(_0x3d9a20[_0x0980('0x8d')][_0x0980('0x8e')]===_0x0980('0x91')&&!_0x3b03a5&&!_0x3d9a20[_0x0980('0x39')][_0x0980('0x74')])return[];return db[_0x0980('0x92')][_0x0980('0x39')](_0x5dd162[_0x0980('0x93')](),_0x1cff39);})[_0x0980('0x28')](function(_0x552864){_0x4d765b[_0x0980('0x1e')]=_0x552864[_0x0980('0x3f')];if(_0x4d765b['count']===0x0)return[];return db['sequelize']['query'](_0x2096ee[_0x0980('0x93')](),_0x1cff39)[_0x0980('0x28')](function(_0x38b02c){_0x450146=_[_0x0980('0x94')](_0x38b02c,'id');_0x1cff39=_[_0x0980('0x95')](_0x1cff39,{'model':db[_0x0980('0x33')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x3d9a20[_0x0980('0x39')][_0x0980('0x3e')]){_0x3fb28b[_0x0980('0x3d')][_0x0980('0x2f')](function(_0x2b7211){_0x329365[_0x0980('0x46')]('i.'+_0x2b7211);});}else{_0x329365['field'](_0x0980('0x96'),_0x0980('0x5d'));_0x329365[_0x0980('0x46')]('a.key',_0x0980('0x97'));_0x329365[_0x0980('0x46')](_0x0980('0x98'),_0x0980('0x99'));_0x329365[_0x0980('0x46')](_0x0980('0x9a'),'contactName');_0x329365[_0x0980('0x46')](_0x0980('0x9b'));_0x329365[_0x0980('0x46')]('c.firstName',_0x0980('0x9c'));_0x329365[_0x0980('0x46')](_0x0980('0x9d'),'Contact.lastName');_0x329365[_0x0980('0x46')](_0x0980('0x9e'),_0x0980('0x9f'));_0x329365[_0x0980('0x46')]('c.phone',_0x0980('0xa0'));_0x329365['field']('c.mobile',_0x0980('0xa1'));_0x329365[_0x0980('0x46')](_0x0980('0xa2'),_0x0980('0xa3'));_0x329365['field'](_0x0980('0xa4'),_0x0980('0xa5'));_0x329365[_0x0980('0x46')]('o.internal',_0x0980('0xa6'));_0x329365[_0x0980('0x46')](_0x0980('0xa7'),_0x0980('0x2c'));}if(_0x3fb28b[_0x0980('0x20')])_0x329365['limit'](_0x3fb28b[_0x0980('0x20')]);if(_0x3fb28b[_0x0980('0x1f')])_0x329365['offset'](_0x3fb28b[_0x0980('0x1f')]);return db[_0x0980('0x92')][_0x0980('0x39')](_0x329365[_0x0980('0x93')](),_0x1cff39);})[_0x0980('0x28')](function(_0x35f763){_0x3ea610['where'](_0x0980('0xa8'),_['map'](_0x35f763,'id'));return db[_0x0980('0x92')][_0x0980('0x39')](_0x3ea610[_0x0980('0x93')](),_0x1cff39)[_0x0980('0x28')](function(_0x47770c){var _0x563cf4=_[_0x0980('0xa9')](_0x47770c,_0x0980('0xaa'));var _0x2bcd67=[];_0x35f763[_0x0980('0x2f')](function(_0x4ad017){_0x2bcd67[_0x0980('0xab')](updateSmsInteraction(_0x4ad017,_0x450146,_0x563cf4));});return BPromise[_0x0980('0xac')](_0x2bcd67);});});})[_0x0980('0x28')](function(_0x4146af){_0x4d765b[_0x0980('0xad')]=_0x4146af;return _0x4d765b;})['then'](respondWithFilteredResult(_0x5c6ea2,_0x3fb28b))['catch'](handleError(_0x5c6ea2,null));};exports[_0x0980('0xae')]=function(_0x1c2b3a,_0x4c1339){var _0x113e61={'raw':![],'where':{'id':_0x1c2b3a[_0x0980('0xaf')]['id']}},_0x962294={};_0x962294['model']=_[_0x0980('0x38')](db[_0x0980('0x33')][_0x0980('0x34')]);_0x962294['query']=_[_0x0980('0x38')](_0x1c2b3a['query']);_0x962294[_0x0980('0x3a')]=_[_0x0980('0x3b')](_0x962294['model'],_0x962294[_0x0980('0x39')]);_0x113e61[_0x0980('0x3d')]=_[_0x0980('0x3b')](_0x962294[_0x0980('0x3c')],qs['fields'](_0x1c2b3a[_0x0980('0x39')][_0x0980('0x3e')]));_0x113e61[_0x0980('0x3d')]=_0x113e61[_0x0980('0x3d')][_0x0980('0x3f')]?_0x113e61[_0x0980('0x3d')]:_0x962294[_0x0980('0x3c')];if(_0x1c2b3a[_0x0980('0x39')][_0x0980('0xb0')]){_0x113e61[_0x0980('0xb1')]=[{'all':!![]}];}_0x113e61=_[_0x0980('0x95')]({},_0x113e61,_0x1c2b3a['options']);return db[_0x0980('0x33')][_0x0980('0x5c')](_0x113e61)['then'](handleEntityNotFound(_0x4c1339,null))[_0x0980('0x28')](respondWithResult(_0x4c1339,null))[_0x0980('0x30')](handleError(_0x4c1339,null));};exports['create']=function(_0x48591c,_0x140398){return db[_0x0980('0x33')]['create'](_0x48591c[_0x0980('0x70')],{})['then'](respondWithResult(_0x140398,0xc9))[_0x0980('0x30')](handleError(_0x140398,null));};exports[_0x0980('0x26')]=function(_0x5cc87f,_0x4405f6){if(_0x5cc87f[_0x0980('0x70')]['id']){delete _0x5cc87f[_0x0980('0x70')]['id'];}return db[_0x0980('0x33')][_0x0980('0x5c')]({'where':{'id':_0x5cc87f[_0x0980('0xaf')]['id']}})['then'](handleEntityNotFound(_0x4405f6,null))[_0x0980('0x28')](saveUpdates(_0x5cc87f[_0x0980('0x70')],null))['then'](respondWithResult(_0x4405f6,null))[_0x0980('0x30')](handleError(_0x4405f6,null));};exports[_0x0980('0x27')]=function(_0x200dc6,_0x8e6a7e){return db[_0x0980('0x33')][_0x0980('0x5c')]({'where':{'id':_0x200dc6[_0x0980('0xaf')]['id']}})['then'](handleEntityNotFound(_0x8e6a7e,null))[_0x0980('0x28')](removeEntity(_0x8e6a7e,null))['catch'](handleError(_0x8e6a7e,null));};exports['describe']=function(_0x5a8226,_0x12aff3){return db[_0x0980('0x33')][_0x0980('0xb2')]()[_0x0980('0x28')](respondWithResult(_0x12aff3,null))[_0x0980('0x30')](handleError(_0x12aff3,null));};exports[_0x0980('0xb3')]=function(_0x571f59,_0xb56753,_0x4cc4be){return db[_0x0980('0xb4')][_0x0980('0x5c')]({'where':{'id':_0x571f59[_0x0980('0xaf')]['id']}})['then'](handleEntityNotFound(_0xb56753,null))[_0x0980('0x28')](function(_0x54a02c){if(_0x54a02c){return _0x54a02c[_0x0980('0xb3')](_0x571f59['body'][_0x0980('0xb5')],_[_0x0980('0xb6')](_0x571f59[_0x0980('0x70')],['ids','id'])||{});}})['then'](respondWithResult(_0xb56753,null))['catch'](handleError(_0xb56753,null));};exports[_0x0980('0xb7')]=function(_0xe7f650,_0x3bf1bc,_0x15d788){var _0x3071c8={'raw':![],'where':{}};var _0x59fa98={};var _0x2ecfca={'count':0x0,'rows':[]};return db['SmsInteraction']['findOne']({'where':{'id':_0xe7f650['params']['id']}})[_0x0980('0x28')](handleEntityNotFound(_0x3bf1bc,null))[_0x0980('0x28')](function(_0x4655b9){if(_0x4655b9){_0x59fa98['model']=_[_0x0980('0x38')](db[_0x0980('0xb4')][_0x0980('0x34')]);_0x59fa98[_0x0980('0x39')]=_[_0x0980('0x38')](_0xe7f650['query']);_0x59fa98[_0x0980('0x3a')]=_[_0x0980('0x3b')](_0x59fa98[_0x0980('0x3c')],_0x59fa98[_0x0980('0x39')]);_0x3071c8[_0x0980('0x3d')]=_['intersection'](_0x59fa98[_0x0980('0x3c')],qs[_0x0980('0x3e')](_0xe7f650[_0x0980('0x39')][_0x0980('0x3e')]));_0x3071c8['attributes']=_0x3071c8[_0x0980('0x3d')][_0x0980('0x3f')]?_0x3071c8[_0x0980('0x3d')]:_0x59fa98[_0x0980('0x3c')];if(!_0xe7f650['query'][_0x0980('0x40')](_0x0980('0x41'))){_0x3071c8[_0x0980('0x20')]=qs['limit'](_0xe7f650['query'][_0x0980('0x20')]);_0x3071c8['offset']=qs[_0x0980('0x1f')](_0xe7f650[_0x0980('0x39')][_0x0980('0x1f')]);}_0x3071c8[_0x0980('0x42')]=qs[_0x0980('0x43')](_0xe7f650[_0x0980('0x39')][_0x0980('0x43')]);_0x3071c8['where']=qs[_0x0980('0x3a')](_[_0x0980('0xb8')](_0xe7f650[_0x0980('0x39')],_0x59fa98[_0x0980('0x3a')]));_0x3071c8[_0x0980('0x44')]['SmsInteractionId']=_0x4655b9['id'];if(_0xe7f650['query'][_0x0980('0x80')]){_0x3071c8[_0x0980('0x44')]=_[_0x0980('0x95')](_0x3071c8[_0x0980('0x44')],{'$or':_[_0x0980('0x32')](_0x3071c8['attributes'],function(_0xcec8c7){var _0x5e2f34={};_0x5e2f34[_0xcec8c7]={'$like':'%'+_0xe7f650['query']['filter']+'%'};return _0x5e2f34;})});}if(_0xe7f650[_0x0980('0x39')][_0x0980('0x77')]){var _0x5264f9=_0xe7f650[_0x0980('0x39')][_0x0980('0x77')]['split'](',');var _0x18f1bd={};_0x18f1bd[_0x5264f9[0x0]]={'$gte':moment(_0x5264f9[0x1])['format'](_0x0980('0xb9'))};_0x3071c8[_0x0980('0x44')]=_[_0x0980('0x95')](_0x3071c8[_0x0980('0x44')],_0x18f1bd);}_0x3071c8=_[_0x0980('0x95')]({},_0x3071c8,_0xe7f650[_0x0980('0xba')]);return db[_0x0980('0xb4')][_0x0980('0x1e')]({'where':_0x3071c8['where']})[_0x0980('0x28')](function(_0x1db314){_0x2ecfca[_0x0980('0x1e')]=_0x1db314;if(_0xe7f650[_0x0980('0x39')]['includeAll']){_0x3071c8['include']=[{'all':!![]}];}return db['SmsMessage'][_0x0980('0xbb')](_0x3071c8);})[_0x0980('0x28')](function(_0x49a715){_0x2ecfca['rows']=_0x49a715;return _0x2ecfca;});}})[_0x0980('0x28')](respondWithFilteredResult(_0x3bf1bc,_0x3071c8))[_0x0980('0x30')](handleError(_0x3bf1bc,null));};exports['addTags']=function(_0x2280c0,_0x3a962f,_0x5db166){return db[_0x0980('0x33')][_0x0980('0x5c')]({'where':{'id':_0x2280c0[_0x0980('0xaf')]['id']}})[_0x0980('0x28')](handleEntityNotFound(_0x3a962f,null))[_0x0980('0x28')](function(_0x1867c6){if(_0x1867c6){return _0x1867c6[_0x0980('0xbc')](_0x2280c0[_0x0980('0x70')]['ids'],_[_0x0980('0xb6')](_0x2280c0['body'],[_0x0980('0xb5'),'id'])||{})[_0x0980('0xbd')](function(){return db[_0x0980('0x69')][_0x0980('0xbb')]({'attributes':['id',_0x0980('0x2a'),'color'],'where':{'id':_0x2280c0[_0x0980('0x70')]['ids']}});})[_0x0980('0x28')](function(_0x5bf56d){socket[_0x0980('0xbe')](_0x0980('0xbf'),{'id':Number(_0x2280c0[_0x0980('0xaf')]['id']),'tags':_0x5bf56d||[]});return{'id':Number(_0x2280c0[_0x0980('0xaf')]['id']),'tags':_0x5bf56d||[]};});}})[_0x0980('0x28')](respondWithResult(_0x3a962f,null))[_0x0980('0x30')](handleError(_0x3a962f,null));};exports['removeTags']=function(_0x311e21,_0x23cce9,_0x1d94d6){return db[_0x0980('0x33')]['find']({'where':{'id':_0x311e21[_0x0980('0xaf')]['id']}})[_0x0980('0x28')](handleEntityNotFound(_0x23cce9,null))[_0x0980('0x28')](function(_0x396adb){if(_0x396adb){return _0x396adb[_0x0980('0xc0')](_0x311e21[_0x0980('0x39')][_0x0980('0xb5')]);}})[_0x0980('0x28')](respondWithStatusCode(_0x23cce9,null))['catch'](handleError(_0x23cce9,null));};exports[_0x0980('0xc1')]=function(_0x352028,_0x296a2b){var _0x5b32e6=moment()[_0x0980('0xc2')]()[_0x0980('0x93')]();var _0x58496f=path[_0x0980('0xc3')](config[_0x0980('0xc4')],_0x0980('0xc5'),'files',_0x0980('0xc6'));var _0x39177c=path[_0x0980('0xc3')](config[_0x0980('0xc4')],_0x0980('0xc5'),_0x0980('0xc7'),_0x0980('0xc8'));var _0x2f34a0=path[_0x0980('0xc3')](_0x58496f,_0x5b32e6);var _0x1ed25f=util[_0x0980('0xc9')](_0x0980('0xca'),_0x352028[_0x0980('0xaf')]['id'],_0x5b32e6);var _0x40da1f=path['join'](_0x58496f,_0x1ed25f);var _0x1399a9=[];_0x1399a9[_0x0980('0xab')]({'model':db[_0x0980('0x6c')],'as':_0x0980('0x6c'),'attributes':['id',_0x0980('0xcb')],'raw':!![]});_0x1399a9[_0x0980('0xab')]({'model':db[_0x0980('0xcc')],'as':'Contact','attributes':['id','firstName',_0x0980('0xcd')],'raw':!![]});var _0x532eb1=[{'model':db[_0x0980('0xb4')],'as':_0x0980('0xce'),'attributes':['id','body',_0x0980('0xcf'),_0x0980('0xd0'),'secret',_0x0980('0x7c')],'include':_0x1399a9}];_0x532eb1[_0x0980('0xab')]({'model':db['SmsAccount'],'as':_0x0980('0xd1'),'attributes':['id','name']});_0x532eb1[_0x0980('0xab')]({'model':db[_0x0980('0x6c')],'as':_0x0980('0xd2'),'attributes':['id',_0x0980('0xcb')]});return db[_0x0980('0x33')]['find']({'where':{'id':_0x352028[_0x0980('0xaf')]['id']},'include':_0x532eb1})[_0x0980('0x28')](handleEntityNotFound(_0x296a2b,null))[_0x0980('0x28')](function(_0x201380){if(_0x201380){var _0x8735c6=_0x201380['get']({'plain':!![]});fs[_0x0980('0xd3')](_0x2f34a0);var _0x5b68c1={'format':'A4','border':'10px','header':{'height':_0x0980('0xd4'),'contents':{'first':'<div\x20class=\x22header\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<h5>Interaction\x20Transcript</h5>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>'}},'footer':{'height':'30px','contents':{'default':util[_0x0980('0xc9')](_0x0980('0xd5'),util[_0x0980('0xc9')](_0x0980('0xd6'),_0x0980('0xd7'),_0x8735c6['id']),moment()['format'](_0x0980('0xd8'))[_0x0980('0x93')]())}}};var _0xcaa97={'channel':_0x0980('0xd7'),'account':_0x8735c6[_0x0980('0xd1')]['name'],'agent':_0x8735c6['Owner']?_0x8735c6[_0x0980('0xd2')][_0x0980('0xcb')]:_0x0980('0xd9'),'createdAt':moment(_0x8735c6['createdAt'])['format']('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'closedAt':_0x8735c6[_0x0980('0xda')]?moment(_0x8735c6[_0x0980('0xdb')])['format'](_0x0980('0xb9'))['toString']():'','disposition':_0x8735c6[_0x0980('0xdc')],'messages':_(_0x8735c6[_0x0980('0xce')])[_0x0980('0x80')]({'secret':![]})[_0x0980('0x32')](function(_0x13cb2e){return{'date':moment(_0x13cb2e['createdAt'])[_0x0980('0xc9')](_0x0980('0xb9'))[_0x0980('0x93')](),'sender':_0x13cb2e[_0x0980('0xd0')]==='out'?_0x13cb2e[_0x0980('0x6c')]?_0x13cb2e[_0x0980('0x6c')]['fullname']:_0x0980('0xdd'):_0x13cb2e[_0x0980('0x61')][_0x0980('0xde')]+(_0x13cb2e[_0x0980('0x61')][_0x0980('0xcd')]?'\x20'+_0x13cb2e['Contact'][_0x0980('0xcd')]:''),'body':_0x13cb2e[_0x0980('0x70')],'direction':_0x13cb2e[_0x0980('0xd0')]===_0x0980('0xdf')?'A':'C','secret':_0x13cb2e[_0x0980('0xe0')],'read':_0x13cb2e['read']};})[_0x0980('0x5e')]()};return ejs[_0x0980('0xe1')](path[_0x0980('0xc3')](config[_0x0980('0xc4')],_0x0980('0xc5'),_0x0980('0xe2'),_0x0980('0xe3')),{'interaction':_0xcaa97})[_0x0980('0x28')](function(_0x37414a){return new BPromise(function(_0x16cf44,_0xe2028b){pdf[_0x0980('0xe4')](_0x37414a,_0x5b68c1)[_0x0980('0xe5')](path[_0x0980('0xc3')](_0x2f34a0,_0x0980('0xe6')+_0x8735c6['id']+'-'+_0x5b32e6+'.pdf'),function(_0x555467,_0x4255e9){if(_0x555467)return _0xe2028b(_0x555467);_0x16cf44(_0x4255e9);});});})[_0x0980('0x28')](function(){return new BPromise(function(_0x372494,_0x9d7def){zipdir(_0x2f34a0,{'saveTo':_0x40da1f},function(_0x2ae58c,_0x502ece){if(_0x2ae58c)return _0x9d7def(_0x2ae58c);return _0x372494(_0x502ece);});})[_0x0980('0x28')](function(){return new BPromise(function(_0xe85be6,_0x3e7b8f){rimraf(_0x2f34a0,function(_0x587c72){if(_0x587c72)_0x3e7b8f(_0x587c72);return _0xe85be6();});});})[_0x0980('0x28')](function(){return _0x296a2b[_0x0980('0xc1')](_0x40da1f,_0x1ed25f,function(_0x143285){if(_0x143285){console[_0x0980('0xe7')](_0x0980('0xe8'),_0x143285);}else{fs['unlinkSync'](_0x40da1f);}});});});}else{return _0x296a2b[_0x0980('0x1a')](0xc8);}})[_0x0980('0x30')](handleError(_0x296a2b,null));};
\ No newline at end of file
+var _0x24dd=['direction','read','Account','Owner','get','mkdirSync','Sms','N.A.','closed','closedAt','disposition','Messages','out','System','Contact','secret','value','renderFile','downloadInteraction.ejs','.pdf','log','err','unlinkSync','rimraf','zip-dir','moment','bluebird','util','path','lodash','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','./smsInteraction.socket','register','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','update','destroy','then','end','error','stack','name','send','index','map','SmsInteraction','type','sms','catch','show','keys','rawAttributes','query','filters','intersection','attributes','fields','length','model','includeAll','options','find','create','body','params','describe','addMessage','SmsMessage','ids','omit','findOne','hasOwnProperty','nolimit','sort','where','SmsInteractionId','filter','merge','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','include','findAll','addTags','setTags','spread','Tag','color','emit','removeTags','download','toString','join','root','server','files','tmp','transcript-%d-%s.zip','push','User','fullname','CmContact','firstName','lastName','createdAt'];(function(_0x4b2680,_0x1c92ad){var _0x40f43f=function(_0x2d7cb2){while(--_0x2d7cb2){_0x4b2680['push'](_0x4b2680['shift']());}};_0x40f43f(++_0x1c92ad);}(_0x24dd,0x109));var _0xd24d=function(_0x247fa1,_0x4ec37c){_0x247fa1=_0x247fa1-0x0;var _0x244f35=_0x24dd[_0x247fa1];return _0x244f35;};'use strict';var rimraf=require(_0xd24d('0x0'));var zipdir=require(_0xd24d('0x1'));var moment=require(_0xd24d('0x2'));var BPromise=require(_0xd24d('0x3'));var util=require(_0xd24d('0x4'));var path=require(_0xd24d('0x5'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xd24d('0x6'));var Redis=require('ioredis');var interaction=require('../../components/interaction/service');var qs=require(_0xd24d('0x7'));var pdf=require(_0xd24d('0x8'));var logger=require(_0xd24d('0x9'))(_0xd24d('0xa'));var config=require(_0xd24d('0xb'));var db=require(_0xd24d('0xc'))['db'];config[_0xd24d('0xd')]=_[_0xd24d('0xe')](config[_0xd24d('0xd')],{'host':_0xd24d('0xf'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd24d('0xd')]));require(_0xd24d('0x10'))[_0xd24d('0x11')](socket);function respondWithStatusCode(_0x14e0b8,_0x1b7949){_0x1b7949=_0x1b7949||0xcc;return function(_0x3b0f87){if(_0x3b0f87){return _0x14e0b8[_0xd24d('0x12')](_0x1b7949);}return _0x14e0b8[_0xd24d('0x13')](_0x1b7949)['end']();};}function respondWithResult(_0x46254e,_0x1c545f){_0x1c545f=_0x1c545f||0xc8;return function(_0x3de3e1){if(_0x3de3e1){return _0x46254e[_0xd24d('0x13')](_0x1c545f)[_0xd24d('0x14')](_0x3de3e1);}};}function respondWithFilteredResult(_0x12c4e5,_0x154a96){return function(_0x1cf55f){if(_0x1cf55f){var _0x4a6595=typeof _0x154a96[_0xd24d('0x15')]===_0xd24d('0x16')&&typeof _0x154a96[_0xd24d('0x17')]===_0xd24d('0x16');var _0x12891d=_0x1cf55f['count'];var _0x2a94bf=_0x4a6595?0x0:_0x154a96[_0xd24d('0x15')];var _0x50229c=_0x4a6595?_0x1cf55f[_0xd24d('0x18')]:_0x154a96[_0xd24d('0x15')]+_0x154a96[_0xd24d('0x17')];var _0x3c0b86;if(_0x50229c>=_0x12891d){_0x50229c=_0x12891d;_0x3c0b86=0xc8;}else{_0x3c0b86=0xce;}_0x12c4e5[_0xd24d('0x13')](_0x3c0b86);return _0x12c4e5[_0xd24d('0x19')](_0xd24d('0x1a'),_0x2a94bf+'-'+_0x50229c+'/'+_0x12891d)[_0xd24d('0x14')](_0x1cf55f);}return null;};}function saveUpdates(_0xd6b38){return function(_0x3b90f4){if(_0x3b90f4){return _0x3b90f4[_0xd24d('0x1b')](_0xd6b38)['then'](function(_0x5e668a){return _0x5e668a;});}return null;};}function removeEntity(_0x18acea){return function(_0x3db89d){if(_0x3db89d){return _0x3db89d[_0xd24d('0x1c')]()[_0xd24d('0x1d')](function(){_0x18acea[_0xd24d('0x13')](0xcc)[_0xd24d('0x1e')]();});}};}function handleEntityNotFound(_0x7c2000){return function(_0x58c968){if(!_0x58c968){_0x7c2000[_0xd24d('0x12')](0x194);}return _0x58c968;};}function handleError(_0x201140,_0x345f6b){_0x345f6b=_0x345f6b||0x1f4;return function(_0xd1b706){logger[_0xd24d('0x1f')](_0xd1b706[_0xd24d('0x20')]);if(_0xd1b706[_0xd24d('0x21')]){delete _0xd1b706['name'];}_0x201140[_0xd24d('0x13')](_0x345f6b)[_0xd24d('0x22')](_0xd1b706);};}exports[_0xd24d('0x23')]=function(_0x2fa2b4,_0x54e13d){var _0x3cfd1d={};var _0x596fe4=_[_0xd24d('0x24')](db[_0xd24d('0x25')]['rawAttributes'],function(_0x2aff0b){return{'name':_0x2aff0b['fieldName'],'type':_0x2aff0b[_0xd24d('0x26')]['key']};});_0x3cfd1d=qs['getOptions'](_0x596fe4,_0x2fa2b4);return interaction['findAll'](_0xd24d('0x27'),_0x2fa2b4['query'],_0x2fa2b4['user'],_0x3cfd1d,_0x596fe4)['then'](respondWithFilteredResult(_0x54e13d,_0x3cfd1d))[_0xd24d('0x28')](handleError(_0x54e13d,null));};exports[_0xd24d('0x29')]=function(_0x5b8fe3,_0x19a253){var _0x413369={'raw':![],'where':{'id':_0x5b8fe3['params']['id']}},_0x51c638={};_0x51c638['model']=_[_0xd24d('0x2a')](db['SmsInteraction'][_0xd24d('0x2b')]);_0x51c638[_0xd24d('0x2c')]=_['keys'](_0x5b8fe3[_0xd24d('0x2c')]);_0x51c638[_0xd24d('0x2d')]=_[_0xd24d('0x2e')](_0x51c638['model'],_0x51c638[_0xd24d('0x2c')]);_0x413369[_0xd24d('0x2f')]=_[_0xd24d('0x2e')](_0x51c638['model'],qs[_0xd24d('0x30')](_0x5b8fe3[_0xd24d('0x2c')][_0xd24d('0x30')]));_0x413369[_0xd24d('0x2f')]=_0x413369[_0xd24d('0x2f')][_0xd24d('0x31')]?_0x413369[_0xd24d('0x2f')]:_0x51c638[_0xd24d('0x32')];if(_0x5b8fe3[_0xd24d('0x2c')][_0xd24d('0x33')]){_0x413369['include']=[{'all':!![]}];}_0x413369=_['merge']({},_0x413369,_0x5b8fe3[_0xd24d('0x34')]);return db['SmsInteraction'][_0xd24d('0x35')](_0x413369)[_0xd24d('0x1d')](handleEntityNotFound(_0x19a253,null))[_0xd24d('0x1d')](respondWithResult(_0x19a253,null))['catch'](handleError(_0x19a253,null));};exports['create']=function(_0x202695,_0x364d50){return db[_0xd24d('0x25')][_0xd24d('0x36')](_0x202695[_0xd24d('0x37')],{})[_0xd24d('0x1d')](respondWithResult(_0x364d50,0xc9))[_0xd24d('0x28')](handleError(_0x364d50,null));};exports['update']=function(_0x146fb9,_0x297335){if(_0x146fb9[_0xd24d('0x37')]['id']){delete _0x146fb9['body']['id'];}return db[_0xd24d('0x25')]['find']({'where':{'id':_0x146fb9[_0xd24d('0x38')]['id']}})['then'](handleEntityNotFound(_0x297335,null))[_0xd24d('0x1d')](saveUpdates(_0x146fb9[_0xd24d('0x37')],null))['then'](respondWithResult(_0x297335,null))[_0xd24d('0x28')](handleError(_0x297335,null));};exports[_0xd24d('0x1c')]=function(_0x45cbc5,_0x47c323){return db[_0xd24d('0x25')][_0xd24d('0x35')]({'where':{'id':_0x45cbc5['params']['id']}})['then'](handleEntityNotFound(_0x47c323,null))[_0xd24d('0x1d')](removeEntity(_0x47c323,null))['catch'](handleError(_0x47c323,null));};exports[_0xd24d('0x39')]=function(_0x1e0326,_0xcacdcb){return db['SmsInteraction'][_0xd24d('0x39')]()[_0xd24d('0x1d')](respondWithResult(_0xcacdcb,null))['catch'](handleError(_0xcacdcb,null));};exports[_0xd24d('0x3a')]=function(_0x2653bc,_0x194ba8){return db[_0xd24d('0x3b')][_0xd24d('0x35')]({'where':{'id':_0x2653bc[_0xd24d('0x38')]['id']}})[_0xd24d('0x1d')](handleEntityNotFound(_0x194ba8,null))['then'](function(_0x13495d){if(_0x13495d){return _0x13495d[_0xd24d('0x3a')](_0x2653bc['body'][_0xd24d('0x3c')],_[_0xd24d('0x3d')](_0x2653bc['body'],['ids','id'])||{});}})['then'](respondWithResult(_0x194ba8,null))[_0xd24d('0x28')](handleError(_0x194ba8,null));};exports['getMessages']=function(_0x4cda9c,_0x4394bd){var _0x1f8970={'raw':![],'where':{}};var _0x5ae4dd={};var _0x57f62b={'count':0x0,'rows':[]};return db[_0xd24d('0x25')][_0xd24d('0x3e')]({'where':{'id':_0x4cda9c[_0xd24d('0x38')]['id']}})[_0xd24d('0x1d')](handleEntityNotFound(_0x4394bd,null))[_0xd24d('0x1d')](function(_0x5626f5){if(_0x5626f5){_0x5ae4dd[_0xd24d('0x32')]=_[_0xd24d('0x2a')](db['SmsMessage'][_0xd24d('0x2b')]);_0x5ae4dd[_0xd24d('0x2c')]=_['keys'](_0x4cda9c[_0xd24d('0x2c')]);_0x5ae4dd[_0xd24d('0x2d')]=_[_0xd24d('0x2e')](_0x5ae4dd[_0xd24d('0x32')],_0x5ae4dd[_0xd24d('0x2c')]);_0x1f8970[_0xd24d('0x2f')]=_[_0xd24d('0x2e')](_0x5ae4dd[_0xd24d('0x32')],qs[_0xd24d('0x30')](_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x30')]));_0x1f8970[_0xd24d('0x2f')]=_0x1f8970['attributes'][_0xd24d('0x31')]?_0x1f8970[_0xd24d('0x2f')]:_0x5ae4dd[_0xd24d('0x32')];if(!_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x3f')](_0xd24d('0x40'))){_0x1f8970[_0xd24d('0x17')]=qs[_0xd24d('0x17')](_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x17')]);_0x1f8970[_0xd24d('0x15')]=qs[_0xd24d('0x15')](_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x15')]);}_0x1f8970['order']=qs[_0xd24d('0x41')](_0x4cda9c['query']['sort']);_0x1f8970[_0xd24d('0x42')]=qs[_0xd24d('0x2d')](_['pick'](_0x4cda9c[_0xd24d('0x2c')],_0x5ae4dd[_0xd24d('0x2d')]));_0x1f8970[_0xd24d('0x42')][_0xd24d('0x43')]=_0x5626f5['id'];if(_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x44')]){_0x1f8970[_0xd24d('0x42')]=_[_0xd24d('0x45')](_0x1f8970[_0xd24d('0x42')],{'$or':_[_0xd24d('0x24')](_0x1f8970[_0xd24d('0x2f')],function(_0x5d5a43){var _0x3f62ab={};_0x3f62ab[_0x5d5a43]={'$like':'%'+_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x44')]+'%'};return _0x3f62ab;})});}if(_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x46')]){var _0x314f58=_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x46')][_0xd24d('0x47')](',');var _0x5f3c3c={};_0x5f3c3c[_0x314f58[0x0]]={'$gte':moment(_0x314f58[0x1])[_0xd24d('0x48')](_0xd24d('0x49'))};_0x1f8970[_0xd24d('0x42')]=_[_0xd24d('0x45')](_0x1f8970[_0xd24d('0x42')],_0x5f3c3c);}_0x1f8970=_[_0xd24d('0x45')]({},_0x1f8970,_0x4cda9c[_0xd24d('0x34')]);return db[_0xd24d('0x3b')][_0xd24d('0x18')]({'where':_0x1f8970[_0xd24d('0x42')]})['then'](function(_0x105077){_0x57f62b[_0xd24d('0x18')]=_0x105077;if(_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x33')]){_0x1f8970[_0xd24d('0x4a')]=[{'all':!![]}];}return db['SmsMessage'][_0xd24d('0x4b')](_0x1f8970);})['then'](function(_0x44a6ce){_0x57f62b['rows']=_0x44a6ce;return _0x57f62b;});}})[_0xd24d('0x1d')](respondWithFilteredResult(_0x4394bd,_0x1f8970))['catch'](handleError(_0x4394bd,null));};exports[_0xd24d('0x4c')]=function(_0x138e3a,_0x3be9a5){return db[_0xd24d('0x25')]['find']({'where':{'id':_0x138e3a[_0xd24d('0x38')]['id']}})[_0xd24d('0x1d')](handleEntityNotFound(_0x3be9a5,null))['then'](function(_0x548cfb){if(_0x548cfb){return _0x548cfb[_0xd24d('0x4d')](_0x138e3a[_0xd24d('0x37')]['ids'],_[_0xd24d('0x3d')](_0x138e3a[_0xd24d('0x37')],[_0xd24d('0x3c'),'id'])||{})[_0xd24d('0x4e')](function(){return db[_0xd24d('0x4f')][_0xd24d('0x4b')]({'attributes':['id',_0xd24d('0x21'),_0xd24d('0x50')],'where':{'id':_0x138e3a[_0xd24d('0x37')]['ids']}});})[_0xd24d('0x1d')](function(_0x953ea1){socket[_0xd24d('0x51')]('smsInteractionTags:save',{'id':Number(_0x138e3a[_0xd24d('0x38')]['id']),'tags':_0x953ea1||[]});return{'id':Number(_0x138e3a[_0xd24d('0x38')]['id']),'tags':_0x953ea1||[]};});}})[_0xd24d('0x1d')](respondWithResult(_0x3be9a5,null))[_0xd24d('0x28')](handleError(_0x3be9a5,null));};exports[_0xd24d('0x52')]=function(_0x3278bf,_0xf23df1){return db[_0xd24d('0x25')][_0xd24d('0x35')]({'where':{'id':_0x3278bf['params']['id']}})[_0xd24d('0x1d')](handleEntityNotFound(_0xf23df1,null))['then'](function(_0x1c4a1b){if(_0x1c4a1b){return _0x1c4a1b['removeTags'](_0x3278bf[_0xd24d('0x2c')]['ids']);}})[_0xd24d('0x1d')](respondWithStatusCode(_0xf23df1,null))[_0xd24d('0x28')](handleError(_0xf23df1,null));};exports[_0xd24d('0x53')]=function(_0x2c510f,_0x362158){var _0x3f4bdd=moment()['unix']()[_0xd24d('0x54')]();var _0xfff876=path[_0xd24d('0x55')](config[_0xd24d('0x56')],_0xd24d('0x57'),_0xd24d('0x58'),_0xd24d('0x59'));var _0x19359e=path[_0xd24d('0x55')](_0xfff876,_0x3f4bdd);var _0x58f281=util[_0xd24d('0x48')](_0xd24d('0x5a'),_0x2c510f[_0xd24d('0x38')]['id'],_0x3f4bdd);var _0x4d1643=path[_0xd24d('0x55')](_0xfff876,_0x58f281);var _0x5c7fd8=[];_0x5c7fd8[_0xd24d('0x5b')]({'model':db[_0xd24d('0x5c')],'as':_0xd24d('0x5c'),'attributes':['id',_0xd24d('0x5d')],'raw':!![]});_0x5c7fd8[_0xd24d('0x5b')]({'model':db[_0xd24d('0x5e')],'as':'Contact','attributes':['id',_0xd24d('0x5f'),_0xd24d('0x60')],'raw':!![]});var _0x3ab32a=[{'model':db[_0xd24d('0x3b')],'as':'Messages','attributes':['id','body',_0xd24d('0x61'),_0xd24d('0x62'),'secret',_0xd24d('0x63')],'include':_0x5c7fd8}];_0x3ab32a[_0xd24d('0x5b')]({'model':db['SmsAccount'],'as':_0xd24d('0x64'),'attributes':['id','name']});_0x3ab32a[_0xd24d('0x5b')]({'model':db[_0xd24d('0x5c')],'as':_0xd24d('0x65'),'attributes':['id',_0xd24d('0x5d')]});return db['SmsInteraction'][_0xd24d('0x35')]({'where':{'id':_0x2c510f['params']['id']},'include':_0x3ab32a})[_0xd24d('0x1d')](handleEntityNotFound(_0x362158,null))[_0xd24d('0x1d')](function(_0x5a7486){if(_0x5a7486){var _0x19f9e=_0x5a7486[_0xd24d('0x66')]({'plain':!![]});fs[_0xd24d('0x67')](_0x19359e);var _0x2897c4={'channel':_0xd24d('0x68'),'account':_0x19f9e[_0xd24d('0x64')][_0xd24d('0x21')],'agent':_0x19f9e[_0xd24d('0x65')]?_0x19f9e['Owner'][_0xd24d('0x5d')]:_0xd24d('0x69'),'createdAt':moment(_0x19f9e['createdAt'])[_0xd24d('0x48')](_0xd24d('0x49'))['toString'](),'closedAt':_0x19f9e[_0xd24d('0x6a')]?moment(_0x19f9e[_0xd24d('0x6b')])[_0xd24d('0x48')](_0xd24d('0x49'))[_0xd24d('0x54')]():'','disposition':_0x19f9e[_0xd24d('0x6c')],'messages':_(_0x19f9e[_0xd24d('0x6d')])[_0xd24d('0x44')]({'secret':![]})['map'](function(_0x360ad7){return{'date':moment(_0x360ad7['createdAt'])['format'](_0xd24d('0x49'))[_0xd24d('0x54')](),'sender':_0x360ad7[_0xd24d('0x62')]===_0xd24d('0x6e')?_0x360ad7[_0xd24d('0x5c')]?_0x360ad7[_0xd24d('0x5c')][_0xd24d('0x5d')]:_0xd24d('0x6f'):_0x360ad7[_0xd24d('0x70')][_0xd24d('0x5f')]+(_0x360ad7[_0xd24d('0x70')]['lastName']?'\x20'+_0x360ad7[_0xd24d('0x70')]['lastName']:''),'body':_0x360ad7['body'],'direction':_0x360ad7[_0xd24d('0x62')]==='out'?'A':'C','secret':_0x360ad7[_0xd24d('0x71')],'read':_0x360ad7[_0xd24d('0x63')]};})[_0xd24d('0x72')]()};return ejs[_0xd24d('0x73')](path[_0xd24d('0x55')](config['root'],_0xd24d('0x57'),'views',_0xd24d('0x74')),{'interaction':_0x2897c4})[_0xd24d('0x1d')](function(_0x3295ef){var _0x762d41=path['join'](_0x19359e,'transcript-'+_0x19f9e['id']+'-'+_0x3f4bdd+_0xd24d('0x75'));var _0x5c2181={'path':_0x762d41,'channel':_0xd24d('0x68'),'interactionId':_0x19f9e['id']};return pdf['createPdfFromHTML'](_0x3295ef,_0x5c2181);})[_0xd24d('0x1d')](function(){return new BPromise(function(_0x599f0f,_0x5dfdea){zipdir(_0x19359e,{'saveTo':_0x4d1643},function(_0x4debff,_0x69cef8){if(_0x4debff)return _0x5dfdea(_0x4debff);return _0x599f0f(_0x69cef8);});})['then'](function(){return new BPromise(function(_0x4ebf4d,_0x2d83bd){rimraf(_0x19359e,function(_0x1b98f6){if(_0x1b98f6)_0x2d83bd(_0x1b98f6);return _0x4ebf4d();});});})[_0xd24d('0x1d')](function(){return _0x362158['download'](_0x4d1643,_0x58f281,function(_0x5ada4a){if(_0x5ada4a){console[_0xd24d('0x76')](_0xd24d('0x77'),_0x5ada4a);}else{fs[_0xd24d('0x78')](_0x4d1643);}});});});}else{return _0x362158[_0xd24d('0x12')](0xc8);}})[_0xd24d('0x28')](handleError(_0x362158,null));};
\ No newline at end of file