Built motion from commit 14588770.|2.5.38
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 60c87ec..f3fd269 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x99d1=['join','root','files','tmp','server','firstName','lastName','Messages','direction','secret','SmsAccount','Account','Owner','Sms','N.A.','YYYY-MM-DD\x20HH:mm:ss','closed','closedAt','disposition','out','System','renderFile','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','log','err','unlinkSync','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/export/pdf','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','redis','defaults','localhost','socket.io-emitter','register','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','save','update','then','destroy','stack','name','send','Users','map','fullname','TagIds','split','Tags','catch','SmsInteraction','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','length','sort','where','filters','select','field','from','tools_tags','u.id','u.fullname','ui.SmsInteractionId','left_join','users','o.id\x20=\x20i.UserId','sms_accounts','a.id\x20=\x20i.SmsAccountId','sms_messages','me.SmsInteractionId\x20=\x20i.id','sms_interaction_has_tags','it.SmsInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','find','unreadMessages','value','having','Contact','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','UserId','body','start','some','compact','SmsAccountId','i.SmsAccountId\x20IN\x20?','concat','createdAt','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','SELECT','clone','DESC','t.id\x20IN\x20?','resolve','user','role','isEmpty','i.SmsAccountId\x20IS\x20NULL','agent','sequelize','toString','keyBy','merge','fields','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','contactName','c.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','Contact.fax','o.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','SmsInteractionId','push','all','rows','show','params','includeAll','include','options','create','describe','addMessage','SmsMessage','omit','ids','getMessages','findOne','hasOwnProperty','order','$gte','format','findAll','addTags','setTags','spread','Tag','color','emit','smsInteractionTags:save','removeTags','download','unix'];(function(_0xfaf455,_0x13c0a9){var _0x5aaa60=function(_0x55ce23){while(--_0x55ce23){_0xfaf455['push'](_0xfaf455['shift']());}};_0x5aaa60(++_0x13c0a9);}(_0x99d1,0x104));var _0x199d=function(_0x4ed12e,_0x449d39){_0x4ed12e=_0x4ed12e-0x0;var _0x4b5f8a=_0x99d1[_0x4ed12e];return _0x4b5f8a;};'use strict';var emlformat=require(_0x199d('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x199d('0x1'));var jsonpatch=require(_0x199d('0x2'));var rp=require(_0x199d('0x3'));var moment=require(_0x199d('0x4'));var BPromise=require(_0x199d('0x5'));var Mustache=require('mustache');var util=require(_0x199d('0x6'));var path=require(_0x199d('0x7'));var sox=require(_0x199d('0x8'));var csv=require(_0x199d('0x9'));var ejs=require(_0x199d('0xa'));var fs=require('fs');var fs_extra=require(_0x199d('0xb'));var _=require(_0x199d('0xc'));var squel=require(_0x199d('0xd'));var crypto=require(_0x199d('0xe'));var jsforce=require(_0x199d('0xf'));var deskjs=require(_0x199d('0x10'));var toCsv=require(_0x199d('0x9'));var querystring=require(_0x199d('0x11'));var Papa=require(_0x199d('0x12'));var Redis=require('ioredis');var authService=require(_0x199d('0x13'));var qs=require(_0x199d('0x14'));var as=require('../../components/parsers/advancedSearch');var pdf=require(_0x199d('0x15'));var hardwareService=require(_0x199d('0x16'));var logger=require(_0x199d('0x17'))('api');var utils=require(_0x199d('0x18'));var config=require(_0x199d('0x19'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0x199d('0x1a')]=_[_0x199d('0x1b')](config[_0x199d('0x1a')],{'host':_0x199d('0x1c'),'port':0x18eb});var socket=require(_0x199d('0x1d'))(new Redis(config[_0x199d('0x1a')]));require('./smsInteraction.socket')[_0x199d('0x1e')](socket);function respondWithStatusCode(_0x3800b4,_0x5b033d){_0x5b033d=_0x5b033d||0xcc;return function(_0x21ee01){if(_0x21ee01){return _0x3800b4[_0x199d('0x1f')](_0x5b033d);}return _0x3800b4[_0x199d('0x20')](_0x5b033d)[_0x199d('0x21')]();};}function respondWithResult(_0x46a10f,_0x3da481){_0x3da481=_0x3da481||0xc8;return function(_0x1fa235){if(_0x1fa235){return _0x46a10f[_0x199d('0x20')](_0x3da481)[_0x199d('0x22')](_0x1fa235);}};}function respondWithFilteredResult(_0x2c68a9,_0x1c99d2){return function(_0x2637a6){if(_0x2637a6){var _0x1bac24=typeof _0x1c99d2[_0x199d('0x23')]===_0x199d('0x24')&&typeof _0x1c99d2[_0x199d('0x25')]===_0x199d('0x24');var _0x28eb93=_0x2637a6[_0x199d('0x26')];var _0x4a4007=_0x1bac24?0x0:_0x1c99d2['offset'];var _0x5e0746=_0x1bac24?_0x2637a6['count']:_0x1c99d2[_0x199d('0x23')]+_0x1c99d2[_0x199d('0x25')];var _0x548a01;if(_0x5e0746>=_0x28eb93){_0x5e0746=_0x28eb93;_0x548a01=0xc8;}else{_0x548a01=0xce;}_0x2c68a9[_0x199d('0x20')](_0x548a01);return _0x2c68a9[_0x199d('0x27')](_0x199d('0x28'),_0x4a4007+'-'+_0x5e0746+'/'+_0x28eb93)['json'](_0x2637a6);}return null;};}function patchUpdates(_0x14bba2){return function(_0x32f7ea){try{jsonpatch[_0x199d('0x29')](_0x32f7ea,_0x14bba2,!![]);}catch(_0x903963){return BPromise['reject'](_0x903963);}return _0x32f7ea[_0x199d('0x2a')]();};}function saveUpdates(_0xac74fe,_0x167b34){return function(_0x582a1f){if(_0x582a1f){return _0x582a1f[_0x199d('0x2b')](_0xac74fe)[_0x199d('0x2c')](function(_0x34f330){return _0x34f330;});}return null;};}function removeEntity(_0x1f73de,_0x40832c){return function(_0x42ccbd){if(_0x42ccbd){return _0x42ccbd[_0x199d('0x2d')]()[_0x199d('0x2c')](function(){_0x1f73de[_0x199d('0x20')](0xcc)[_0x199d('0x21')]();});}};}function handleEntityNotFound(_0x2e35dc,_0x241ce0){return function(_0x4e8a18){if(!_0x4e8a18){_0x2e35dc['sendStatus'](0x194);}return _0x4e8a18;};}function handleError(_0x2e91fa,_0x17a289){_0x17a289=_0x17a289||0x1f4;return function(_0x4bdbda){logger['error'](_0x4bdbda[_0x199d('0x2e')]);if(_0x4bdbda[_0x199d('0x2f')]){delete _0x4bdbda[_0x199d('0x2f')];}_0x2e91fa['status'](_0x17a289)[_0x199d('0x30')](_0x4bdbda);};}function getInteractionUsers(_0x58ba02,_0x15bf09){return new BPromise(function(_0x26eb74,_0x5a2734){try{if(_0x15bf09[_0x58ba02['id']]){_0x58ba02[_0x199d('0x31')]=_[_0x199d('0x32')](_0x15bf09[_0x58ba02['id']],function(_0x1f7e4d){return{'id':_0x1f7e4d['id'],'fullname':_0x1f7e4d[_0x199d('0x33')]};});}}catch(_0x1dd441){_0x5a2734(_0x1dd441);}_0x26eb74(_0x58ba02);});}function getInteractionTags(_0x306af7,_0x1e05ec){return new BPromise(function(_0x22d17b,_0x3405f8){try{if(_0x306af7[_0x199d('0x34')]){_0x306af7['Tags']=[];_0x306af7[_0x199d('0x34')][_0x199d('0x35')](',')['forEach'](function(_0x4f7e41){_0x306af7[_0x199d('0x36')]['push'](_0x1e05ec[_0x4f7e41]);});}delete _0x306af7[_0x199d('0x34')];}catch(_0x487cc1){_0x3405f8(_0x487cc1);}_0x22d17b(_0x306af7);});}function updateSmsInteraction(_0x9fb64,_0x5a9ea0,_0x5b9709){return new BPromise(function(_0x17cfbe,_0x5b2a4e){return getInteractionUsers(_0x9fb64,_0x5b9709)['then'](function(_0x487432){return getInteractionTags(_0x487432,_0x5a9ea0);})[_0x199d('0x2c')](function(_0x171c36){_0x17cfbe(_0x171c36);})[_0x199d('0x37')](function(_0x1840e4){_0x5b2a4e(_0x1840e4);});});}exports['index']=function(_0x134484,_0x241b2e){var _0x11653a={},_0x40c716={},_0xb9a062={'count':0x0,'rows':[]};var _0x234e77=_[_0x199d('0x32')](db[_0x199d('0x38')][_0x199d('0x39')],function(_0x34691d){return{'name':_0x34691d[_0x199d('0x3a')],'type':_0x34691d[_0x199d('0x3b')][_0x199d('0x3c')]};});_0x40c716[_0x199d('0x3d')]=_[_0x199d('0x32')](_0x234e77,_0x199d('0x2f'));_0x40c716[_0x199d('0x3e')]=_[_0x199d('0x3f')](_0x134484[_0x199d('0x3e')]);_0x40c716['filters']=_[_0x199d('0x40')](_0x40c716['model'],_0x40c716[_0x199d('0x3e')]);_0x11653a[_0x199d('0x41')]=_[_0x199d('0x40')](_0x40c716['model'],qs['fields'](_0x134484['query']['fields']));_0x11653a[_0x199d('0x41')]=_0x11653a[_0x199d('0x41')][_0x199d('0x42')]?_0x11653a[_0x199d('0x41')]:_0x40c716[_0x199d('0x3d')];if(!_0x134484[_0x199d('0x3e')]['hasOwnProperty']('nolimit')){_0x11653a[_0x199d('0x25')]=qs[_0x199d('0x25')](_0x134484[_0x199d('0x3e')][_0x199d('0x25')]);_0x11653a[_0x199d('0x23')]=qs['offset'](_0x134484['query'][_0x199d('0x23')]);}_0x11653a['order']=qs[_0x199d('0x43')](_0x134484['query']['sort']);_0x11653a[_0x199d('0x44')]=qs[_0x199d('0x45')](_['pick'](_0x134484[_0x199d('0x3e')],_0x40c716['filters']),_0x234e77);var _0x35ca57=[];var _0x1d95e1=squel[_0x199d('0x46')]()[_0x199d('0x47')]('id')['field']('name')[_0x199d('0x47')]('color')[_0x199d('0x48')](_0x199d('0x49'));var _0x1ab5d8=squel['select']()[_0x199d('0x47')](_0x199d('0x4a'))[_0x199d('0x47')](_0x199d('0x4b'))[_0x199d('0x47')](_0x199d('0x4c'))[_0x199d('0x48')]('user_has_sms_interactions','ui')[_0x199d('0x4d')]('users','u','u.id\x20=\x20ui.UserId');var _0x1b6d3a=squel[_0x199d('0x46')]()['from']('sms_interactions','i')[_0x199d('0x4d')]('cm_contacts','c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0x199d('0x4d')](_0x199d('0x4e'),'o',_0x199d('0x4f'))['left_join'](_0x199d('0x50'),'a',_0x199d('0x51'))[_0x199d('0x4d')](_0x199d('0x52'),'me',_0x199d('0x53'))[_0x199d('0x4d')](_0x199d('0x54'),'it',_0x199d('0x55'))[_0x199d('0x4d')](_0x199d('0x49'),'t',_0x199d('0x56'));var _0x263c6c=squel[_0x199d('0x57')]();var _0x300e25=[];var _0x215b74=squel['expr']();var _0x92e7ca;if(_0x134484[_0x199d('0x3e')][_0x199d('0x58')]){_0x92e7ca=as[_0x199d('0x59')](_0x134484['query'][_0x199d('0x58')]);var _0x1884f3=_0x92e7ca[_0x199d('0x5a')];for(var _0x528c75=0x0;_0x528c75<_0x92e7ca[_0x199d('0x5b')]['length'];_0x528c75++){var _0xdcef98=_0x92e7ca[_0x199d('0x5b')][_0x528c75];var _0x152e10='i';var _0x59c5e9=_[_0x199d('0x5c')](_0x234e77,[_0x199d('0x2f'),_0xdcef98['field']]);if(!_0x59c5e9){switch(_0xdcef98[_0x199d('0x47')]){case _0x199d('0x5d'):if(_0xdcef98[_0x199d('0x5e')]==0x1){_0x1b6d3a[_0x199d('0x5f')]('`'+_0xdcef98[_0x199d('0x47')]+'`\x20=\x200');}else{_0x1b6d3a[_0x199d('0x5f')]('`'+_0xdcef98['field']+'`\x20>\x200');}break;case _0x199d('0x60'):if(_0xdcef98[_0x199d('0x61')]===_0x199d('0x62')){if(_0xdcef98[_0x199d('0x5e')][_0x199d('0x35')]('\x20')[_0x199d('0x42')]>0x1){_0x263c6c[_0x1884f3](_0x199d('0x63'),qs['getFullTextValue'](_0xdcef98[_0x199d('0x5e')]),null);}else{var _0x3efd95='%'+_0xdcef98[_0x199d('0x5e')]+'%';_0x263c6c[_0x1884f3](_0x199d('0x64'),_0x3efd95,_0x3efd95,_0x3efd95);}}else{_0x59c5e9=_['find'](_0x234e77,[_0x199d('0x2f'),'ContactId']);_0xdcef98['field']=_0x199d('0x65');_0x4216bc=as[_0x199d('0x66')](_0x152e10,_0x59c5e9[_0x199d('0x3b')],_0xdcef98);_0x263c6c[_0x1884f3](_0x4216bc[_0x199d('0x67')],_0x4216bc[_0x199d('0x5e')]['start'],_0x4216bc[_0x199d('0x5e')]['end']);}break;case'Tag':var _0x27b568=_0xdcef98['value']['split'](',')[_0x199d('0x32')](function(_0x418eb0){return Number(_0x418eb0);});_0x27b568[_0x199d('0x68')](function(_0x38c2e0){_0x215b74['or'](_0x199d('0x69'),'%,'+_0x38c2e0+',%');});_0x300e25=_[_0x199d('0x6a')](_0x300e25,_0x27b568);break;case _0x199d('0x6b'):if(_0xdcef98[_0x199d('0x61')]===_0x199d('0x62')){_0x263c6c[_0x1884f3]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0xdcef98['value']+'%',null);}else{_0x59c5e9=_['find'](_0x234e77,[_0x199d('0x2f'),_0x199d('0x6c')]);_0xdcef98['field']=_0x199d('0x6c');_0x4216bc=as[_0x199d('0x66')](_0x152e10,_0x59c5e9['type'],_0xdcef98);_0x263c6c[_0x1884f3](_0x4216bc[_0x199d('0x67')],_0x4216bc[_0x199d('0x5e')]['start'],_0x4216bc[_0x199d('0x5e')]['end']);}break;case _0x199d('0x6d'):_0x4216bc=as[_0x199d('0x66')]('me',null,_0xdcef98);_0x263c6c[_0x1884f3](_0x4216bc[_0x199d('0x67')],_0x4216bc[_0x199d('0x5e')][_0x199d('0x6e')],_0x4216bc['value'][_0x199d('0x21')]);break;}}else{var _0x4216bc=as[_0x199d('0x66')](_0x152e10,_0x59c5e9['type'],_0xdcef98);_0x263c6c[_0x1884f3](_0x4216bc[_0x199d('0x67')],_0x4216bc['value']['start'],_0x4216bc[_0x199d('0x5e')][_0x199d('0x21')]);}}}else{var _0x2a8d79=_(_0x134484['query'])['keys']()[_0x199d('0x32')](function(_0x31171f){return _[_0x199d('0x6f')](_0x234e77,[_0x199d('0x2f'),_0x31171f])?_0x31171f:undefined;})[_0x199d('0x70')]()[_0x199d('0x5e')]();if(!_['isEmpty'](_0x2a8d79)){_0x2a8d79['forEach'](function(_0x551102){if(_0x551102===_0x199d('0x71')){_0x1b6d3a[_0x199d('0x44')](_0x199d('0x72'),[][_0x199d('0x73')](_0x134484['query'][_0x551102]));}else if(_0x551102===_0x199d('0x74')){var _0x2b6562=JSON[_0x199d('0x75')](_0x134484[_0x199d('0x3e')][_0x551102])['$gte'];var _0x19fa45=JSON['parse'](_0x134484[_0x199d('0x3e')][_0x551102])[_0x199d('0x76')];_0x1b6d3a[_0x199d('0x44')](_0x199d('0x77'),_0x2b6562,_0x19fa45);}else{if(_0x134484[_0x199d('0x3e')][_0x551102]===_0x199d('0x78')){_0x1b6d3a['where']('i.'+_0x551102+_0x199d('0x79'));}else{_0x1b6d3a[_0x199d('0x44')]('i.'+_0x551102+_0x199d('0x7a'),_0x134484[_0x199d('0x3e')][_0x551102]);}}});}if(_0x134484['query'][_0x199d('0x7b')]){if(_0x134484['query'][_0x199d('0x7b')]==0x1){_0x1b6d3a[_0x199d('0x5f')]('`unreadMessages`\x20=\x200');}else{_0x1b6d3a[_0x199d('0x5f')](_0x199d('0x7c'));}}if(_0x134484['query'][_0x199d('0x7d')]){_0x300e25=_[_0x199d('0x7e')](_0x134484[_0x199d('0x3e')]['tag'])?_0x134484[_0x199d('0x3e')][_0x199d('0x7d')]:new Array(_0x134484['query'][_0x199d('0x7d')]);_0x300e25[_0x199d('0x68')](function(_0x50f7dd){_0x215b74['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x50f7dd+',%');});}if(_0x134484[_0x199d('0x3e')][_0x199d('0x7f')]){var _0x3dc861=_0x134484[_0x199d('0x3e')][_0x199d('0x7f')]['replace']('\x5c','\x5c\x5c')[_0x199d('0x80')](/'/g,'\x27\x27');if(qs['isNumeric'](_0x3dc861)){_0x263c6c['or'](_0x199d('0x81'),_0x3dc861+'%')['or'](_0x199d('0x82'),_0x3dc861+'%');}else{_0x263c6c['or'](_0x199d('0x83'),qs['getFullTextValue'](_0x3dc861))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x3dc861+'%');}}}_0x1b6d3a['where'](_0x263c6c);_0x1b6d3a[_0x199d('0x84')](_0x199d('0x85'));var _0x341a10={'type':db['Sequelize']['QueryTypes'][_0x199d('0x86')],'raw':!![]};var _0x5dca3b=_0x1b6d3a[_0x199d('0x87')]();_0x5dca3b[_0x199d('0x47')]('i.id');_0x5dca3b['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x199d('0x5d'));if(_0x11653a['order']){_0x11653a['order'][_0x199d('0x68')](function(_0xeaf7fa){var _0x440ceb=_0xeaf7fa[0x0]==='contactName'?_0xeaf7fa[0x0]:'i.'+_0xeaf7fa[0x0];_0x1b6d3a['order'](_0x440ceb,_0xeaf7fa[0x1]===_0x199d('0x88')?![]:!![]);});}if(!_['isEmpty'](_0x300e25)){_0x1b6d3a['having'](_0x215b74);_0x5dca3b[_0x199d('0x44')](_0x199d('0x89'),_0x300e25);}BPromise[_0x199d('0x8a')]()[_0x199d('0x2c')](function(){if(!_0x92e7ca){if(_0x134484[_0x199d('0x3e')][_0x199d('0x71')])return;_0x5dca3b[_0x199d('0x44')]('i.SmsAccountId\x20IS\x20NOT\x20NULL');_0x1b6d3a['where']('i.SmsAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x134484[_0x199d('0x8b')][_0x199d('0x8c')]!=='agent')return;return _0x134484['user']['getSmsAccounts']({'attributes':['id'],'raw':!![]})[_0x199d('0x2c')](function(_0x6cdb50){if(_[_0x199d('0x8d')](_0x6cdb50)){_0x5dca3b[_0x199d('0x44')](_0x199d('0x8e'));_0x1b6d3a['where'](_0x199d('0x8e'));}else{_0x5dca3b[_0x199d('0x44')](_0x199d('0x72'),_['map'](_0x6cdb50,'id'));_0x1b6d3a['where']('i.SmsAccountId\x20IN\x20?',_[_0x199d('0x32')](_0x6cdb50,'id'));}});})[_0x199d('0x2c')](function(){if(_0x134484[_0x199d('0x8b')]['role']===_0x199d('0x8f')&&!_0x92e7ca&&!_0x134484[_0x199d('0x3e')]['SmsAccountId'])return[];return db[_0x199d('0x90')][_0x199d('0x3e')](_0x5dca3b[_0x199d('0x91')](),_0x341a10);})['then'](function(_0x39553e){_0xb9a062['count']=_0x39553e[_0x199d('0x42')];if(_0xb9a062[_0x199d('0x26')]===0x0)return[];return db[_0x199d('0x90')][_0x199d('0x3e')](_0x1d95e1[_0x199d('0x91')](),_0x341a10)[_0x199d('0x2c')](function(_0x46cabe){_0x35ca57=_[_0x199d('0x92')](_0x46cabe,'id');_0x341a10=_[_0x199d('0x93')](_0x341a10,{'model':db[_0x199d('0x38')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x134484[_0x199d('0x3e')][_0x199d('0x94')]){_0x11653a[_0x199d('0x41')][_0x199d('0x68')](function(_0x24b001){_0x1b6d3a[_0x199d('0x47')]('i.'+_0x24b001);});}else{_0x1b6d3a['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x199d('0x5d'));_0x1b6d3a['field']('a.key',_0x199d('0x95'));_0x1b6d3a[_0x199d('0x47')](_0x199d('0x96'),_0x199d('0x97'));_0x1b6d3a['field']('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',_0x199d('0x98'));_0x1b6d3a['field']('i.*');_0x1b6d3a[_0x199d('0x47')](_0x199d('0x99'),'Contact.firstName');_0x1b6d3a[_0x199d('0x47')](_0x199d('0x9a'),_0x199d('0x9b'));_0x1b6d3a[_0x199d('0x47')](_0x199d('0x9c'),_0x199d('0x9d'));_0x1b6d3a['field'](_0x199d('0x9e'),_0x199d('0x9f'));_0x1b6d3a[_0x199d('0x47')](_0x199d('0xa0'),_0x199d('0xa1'));_0x1b6d3a[_0x199d('0x47')]('c.fax',_0x199d('0xa2'));_0x1b6d3a[_0x199d('0x47')](_0x199d('0xa3'),'Owner.fullname');_0x1b6d3a[_0x199d('0x47')](_0x199d('0xa4'),_0x199d('0xa5'));_0x1b6d3a[_0x199d('0x47')](_0x199d('0xa6'),'TagIds');}if(_0x11653a[_0x199d('0x25')])_0x1b6d3a[_0x199d('0x25')](_0x11653a[_0x199d('0x25')]);if(_0x11653a[_0x199d('0x23')])_0x1b6d3a[_0x199d('0x23')](_0x11653a[_0x199d('0x23')]);return db[_0x199d('0x90')][_0x199d('0x3e')](_0x1b6d3a[_0x199d('0x91')](),_0x341a10);})['then'](function(_0x5161bf){if(_0x5161bf[_0x199d('0x42')]>0x0)_0x1ab5d8['where']('ui.SmsInteractionId\x20IN\x20?',_[_0x199d('0x32')](_0x5161bf,'id'));return db[_0x199d('0x90')][_0x199d('0x3e')](_0x1ab5d8['toString'](),_0x341a10)['then'](function(_0x52cae7){var _0x4dc3ad=_[_0x199d('0xa7')](_0x52cae7,_0x199d('0xa8'));var _0x346ab2=[];_0x5161bf[_0x199d('0x68')](function(_0x430b19){_0x346ab2[_0x199d('0xa9')](updateSmsInteraction(_0x430b19,_0x35ca57,_0x4dc3ad));});return BPromise[_0x199d('0xaa')](_0x346ab2);});});})[_0x199d('0x2c')](function(_0x296003){_0xb9a062[_0x199d('0xab')]=_0x296003;return _0xb9a062;})[_0x199d('0x2c')](respondWithFilteredResult(_0x241b2e,_0x11653a))['catch'](handleError(_0x241b2e,null));};exports[_0x199d('0xac')]=function(_0x3071b3,_0x2891a0){var _0x260d3e={'raw':![],'where':{'id':_0x3071b3[_0x199d('0xad')]['id']}},_0x4f0d60={};_0x4f0d60['model']=_[_0x199d('0x3f')](db[_0x199d('0x38')]['rawAttributes']);_0x4f0d60[_0x199d('0x3e')]=_[_0x199d('0x3f')](_0x3071b3[_0x199d('0x3e')]);_0x4f0d60[_0x199d('0x45')]=_[_0x199d('0x40')](_0x4f0d60[_0x199d('0x3d')],_0x4f0d60['query']);_0x260d3e[_0x199d('0x41')]=_[_0x199d('0x40')](_0x4f0d60[_0x199d('0x3d')],qs[_0x199d('0x94')](_0x3071b3['query'][_0x199d('0x94')]));_0x260d3e['attributes']=_0x260d3e[_0x199d('0x41')][_0x199d('0x42')]?_0x260d3e[_0x199d('0x41')]:_0x4f0d60[_0x199d('0x3d')];if(_0x3071b3[_0x199d('0x3e')][_0x199d('0xae')]){_0x260d3e[_0x199d('0xaf')]=[{'all':!![]}];}_0x260d3e=_['merge']({},_0x260d3e,_0x3071b3[_0x199d('0xb0')]);return db[_0x199d('0x38')]['find'](_0x260d3e)[_0x199d('0x2c')](handleEntityNotFound(_0x2891a0,null))[_0x199d('0x2c')](respondWithResult(_0x2891a0,null))['catch'](handleError(_0x2891a0,null));};exports[_0x199d('0xb1')]=function(_0x53e2f8,_0x12b87f){return db[_0x199d('0x38')][_0x199d('0xb1')](_0x53e2f8[_0x199d('0x6d')],{})[_0x199d('0x2c')](respondWithResult(_0x12b87f,0xc9))[_0x199d('0x37')](handleError(_0x12b87f,null));};exports[_0x199d('0x2b')]=function(_0x44664f,_0x2ad3e7){if(_0x44664f['body']['id']){delete _0x44664f['body']['id'];}return db[_0x199d('0x38')][_0x199d('0x5c')]({'where':{'id':_0x44664f[_0x199d('0xad')]['id']}})[_0x199d('0x2c')](handleEntityNotFound(_0x2ad3e7,null))[_0x199d('0x2c')](saveUpdates(_0x44664f[_0x199d('0x6d')],null))['then'](respondWithResult(_0x2ad3e7,null))[_0x199d('0x37')](handleError(_0x2ad3e7,null));};exports[_0x199d('0x2d')]=function(_0x4347a0,_0x49307d){return db['SmsInteraction'][_0x199d('0x5c')]({'where':{'id':_0x4347a0[_0x199d('0xad')]['id']}})['then'](handleEntityNotFound(_0x49307d,null))[_0x199d('0x2c')](removeEntity(_0x49307d,null))[_0x199d('0x37')](handleError(_0x49307d,null));};exports[_0x199d('0xb2')]=function(_0x4d051d,_0x9d3040){return db[_0x199d('0x38')][_0x199d('0xb2')]()[_0x199d('0x2c')](respondWithResult(_0x9d3040,null))[_0x199d('0x37')](handleError(_0x9d3040,null));};exports[_0x199d('0xb3')]=function(_0x29a729,_0x6c9a59,_0x3aa329){return db[_0x199d('0xb4')][_0x199d('0x5c')]({'where':{'id':_0x29a729[_0x199d('0xad')]['id']}})[_0x199d('0x2c')](handleEntityNotFound(_0x6c9a59,null))['then'](function(_0x90fab5){if(_0x90fab5){return _0x90fab5[_0x199d('0xb3')](_0x29a729[_0x199d('0x6d')]['ids'],_[_0x199d('0xb5')](_0x29a729['body'],[_0x199d('0xb6'),'id'])||{});}})['then'](respondWithResult(_0x6c9a59,null))[_0x199d('0x37')](handleError(_0x6c9a59,null));};exports[_0x199d('0xb7')]=function(_0x2aad36,_0x46a21b,_0x4e299e){var _0x5f0f78={'raw':![],'where':{}};var _0xaf52ed={};var _0x5023d0={'count':0x0,'rows':[]};return db[_0x199d('0x38')][_0x199d('0xb8')]({'where':{'id':_0x2aad36[_0x199d('0xad')]['id']}})[_0x199d('0x2c')](handleEntityNotFound(_0x46a21b,null))[_0x199d('0x2c')](function(_0x10bf73){if(_0x10bf73){_0xaf52ed['model']=_['keys'](db['SmsMessage'][_0x199d('0x39')]);_0xaf52ed['query']=_['keys'](_0x2aad36[_0x199d('0x3e')]);_0xaf52ed[_0x199d('0x45')]=_[_0x199d('0x40')](_0xaf52ed[_0x199d('0x3d')],_0xaf52ed[_0x199d('0x3e')]);_0x5f0f78[_0x199d('0x41')]=_[_0x199d('0x40')](_0xaf52ed[_0x199d('0x3d')],qs['fields'](_0x2aad36[_0x199d('0x3e')][_0x199d('0x94')]));_0x5f0f78[_0x199d('0x41')]=_0x5f0f78[_0x199d('0x41')][_0x199d('0x42')]?_0x5f0f78[_0x199d('0x41')]:_0xaf52ed[_0x199d('0x3d')];if(!_0x2aad36[_0x199d('0x3e')][_0x199d('0xb9')]('nolimit')){_0x5f0f78[_0x199d('0x25')]=qs[_0x199d('0x25')](_0x2aad36[_0x199d('0x3e')]['limit']);_0x5f0f78[_0x199d('0x23')]=qs[_0x199d('0x23')](_0x2aad36[_0x199d('0x3e')][_0x199d('0x23')]);}_0x5f0f78[_0x199d('0xba')]=qs[_0x199d('0x43')](_0x2aad36[_0x199d('0x3e')]['sort']);_0x5f0f78[_0x199d('0x44')]=qs['filters'](_['pick'](_0x2aad36[_0x199d('0x3e')],_0xaf52ed[_0x199d('0x45')]));_0x5f0f78[_0x199d('0x44')][_0x199d('0xa8')]=_0x10bf73['id'];if(_0x2aad36[_0x199d('0x3e')][_0x199d('0x7f')]){_0x5f0f78[_0x199d('0x44')]=_[_0x199d('0x93')](_0x5f0f78[_0x199d('0x44')],{'$or':_[_0x199d('0x32')](_0x5f0f78[_0x199d('0x41')],function(_0x44c6fe){var _0x435c8c={};_0x435c8c[_0x44c6fe]={'$like':'%'+_0x2aad36['query'][_0x199d('0x7f')]+'%'};return _0x435c8c;})});}if(_0x2aad36[_0x199d('0x3e')][_0x199d('0xbb')]){var _0x28b5e1=_0x2aad36[_0x199d('0x3e')][_0x199d('0xbb')][_0x199d('0x35')](',');var _0x5a9902={};_0x5a9902[_0x28b5e1[0x0]]={'$gte':moment(_0x28b5e1[0x1])[_0x199d('0xbc')]('YYYY-MM-DD\x20HH:mm:ss')};_0x5f0f78[_0x199d('0x44')]=_[_0x199d('0x93')](_0x5f0f78['where'],_0x5a9902);}_0x5f0f78=_[_0x199d('0x93')]({},_0x5f0f78,_0x2aad36[_0x199d('0xb0')]);return db['SmsMessage']['count']({'where':_0x5f0f78[_0x199d('0x44')]})['then'](function(_0x1e4639){_0x5023d0['count']=_0x1e4639;if(_0x2aad36[_0x199d('0x3e')][_0x199d('0xae')]){_0x5f0f78['include']=[{'all':!![]}];}return db[_0x199d('0xb4')][_0x199d('0xbd')](_0x5f0f78);})['then'](function(_0x9f2e9){_0x5023d0[_0x199d('0xab')]=_0x9f2e9;return _0x5023d0;});}})[_0x199d('0x2c')](respondWithFilteredResult(_0x46a21b,_0x5f0f78))[_0x199d('0x37')](handleError(_0x46a21b,null));};exports[_0x199d('0xbe')]=function(_0x24b28a,_0x53dadf,_0x187053){return db['SmsInteraction']['find']({'where':{'id':_0x24b28a[_0x199d('0xad')]['id']}})[_0x199d('0x2c')](handleEntityNotFound(_0x53dadf,null))[_0x199d('0x2c')](function(_0x104558){if(_0x104558){return _0x104558[_0x199d('0xbf')](_0x24b28a[_0x199d('0x6d')]['ids'],_['omit'](_0x24b28a['body'],['ids','id'])||{})[_0x199d('0xc0')](function(){return db[_0x199d('0xc1')]['findAll']({'attributes':['id','name',_0x199d('0xc2')],'where':{'id':_0x24b28a[_0x199d('0x6d')][_0x199d('0xb6')]}});})[_0x199d('0x2c')](function(_0x2bfe5e){socket[_0x199d('0xc3')](_0x199d('0xc4'),{'id':Number(_0x24b28a[_0x199d('0xad')]['id']),'tags':_0x2bfe5e||[]});return{'id':Number(_0x24b28a[_0x199d('0xad')]['id']),'tags':_0x2bfe5e||[]};});}})[_0x199d('0x2c')](respondWithResult(_0x53dadf,null))['catch'](handleError(_0x53dadf,null));};exports[_0x199d('0xc5')]=function(_0xdfecd0,_0x406811,_0x1c4c08){return db[_0x199d('0x38')][_0x199d('0x5c')]({'where':{'id':_0xdfecd0[_0x199d('0xad')]['id']}})['then'](handleEntityNotFound(_0x406811,null))[_0x199d('0x2c')](function(_0x3088f1){if(_0x3088f1){return _0x3088f1[_0x199d('0xc5')](_0xdfecd0['query']['ids']);}})[_0x199d('0x2c')](respondWithStatusCode(_0x406811,null))['catch'](handleError(_0x406811,null));};exports[_0x199d('0xc6')]=function(_0x351f7e,_0x15e503){var _0x1dcc55=moment()[_0x199d('0xc7')]()[_0x199d('0x91')]();var _0x4825bb=path[_0x199d('0xc8')](config[_0x199d('0xc9')],'server',_0x199d('0xca'),_0x199d('0xcb'));var _0x2b8b90=path[_0x199d('0xc8')](config['root'],_0x199d('0xcc'),_0x199d('0xca'),'attachments');var _0xb140c8=path['join'](_0x4825bb,_0x1dcc55);var _0x203ff6=util[_0x199d('0xbc')]('transcript-%d-%s.zip',_0x351f7e[_0x199d('0xad')]['id'],_0x1dcc55);var _0x45b66f=path[_0x199d('0xc8')](_0x4825bb,_0x203ff6);var _0x48594e=[];_0x48594e[_0x199d('0xa9')]({'model':db[_0x199d('0x6b')],'as':'User','attributes':['id',_0x199d('0x33')],'raw':!![]});_0x48594e[_0x199d('0xa9')]({'model':db['CmContact'],'as':'Contact','attributes':['id',_0x199d('0xcd'),_0x199d('0xce')],'raw':!![]});var _0x4f915f=[{'model':db[_0x199d('0xb4')],'as':_0x199d('0xcf'),'attributes':['id',_0x199d('0x6d'),_0x199d('0x74'),_0x199d('0xd0'),_0x199d('0xd1'),_0x199d('0x7b')],'include':_0x48594e}];_0x4f915f[_0x199d('0xa9')]({'model':db[_0x199d('0xd2')],'as':_0x199d('0xd3'),'attributes':['id',_0x199d('0x2f')]});_0x4f915f[_0x199d('0xa9')]({'model':db[_0x199d('0x6b')],'as':_0x199d('0xd4'),'attributes':['id','fullname']});return db[_0x199d('0x38')][_0x199d('0x5c')]({'where':{'id':_0x351f7e[_0x199d('0xad')]['id']},'include':_0x4f915f})['then'](handleEntityNotFound(_0x15e503,null))['then'](function(_0x45667a){if(_0x45667a){var _0x82be14=_0x45667a['get']({'plain':!![]});fs['mkdirSync'](_0xb140c8);var _0x4063b4={'channel':_0x199d('0xd5'),'account':_0x82be14['Account'][_0x199d('0x2f')],'agent':_0x82be14[_0x199d('0xd4')]?_0x82be14['Owner'][_0x199d('0x33')]:_0x199d('0xd6'),'createdAt':moment(_0x82be14['createdAt'])[_0x199d('0xbc')](_0x199d('0xd7'))[_0x199d('0x91')](),'closedAt':_0x82be14[_0x199d('0xd8')]?moment(_0x82be14[_0x199d('0xd9')])['format'](_0x199d('0xd7'))[_0x199d('0x91')]():'','disposition':_0x82be14[_0x199d('0xda')],'messages':_(_0x82be14[_0x199d('0xcf')])[_0x199d('0x7f')]({'secret':![]})[_0x199d('0x32')](function(_0x45c587){return{'date':moment(_0x45c587[_0x199d('0x74')])[_0x199d('0xbc')](_0x199d('0xd7'))[_0x199d('0x91')](),'sender':_0x45c587['direction']===_0x199d('0xdb')?_0x45c587['User']?_0x45c587[_0x199d('0x6b')][_0x199d('0x33')]:_0x199d('0xdc'):_0x45c587['Contact'][_0x199d('0xcd')]+(_0x45c587[_0x199d('0x60')][_0x199d('0xce')]?'\x20'+_0x45c587[_0x199d('0x60')][_0x199d('0xce')]:''),'body':_0x45c587[_0x199d('0x6d')],'direction':_0x45c587[_0x199d('0xd0')]===_0x199d('0xdb')?'A':'C','secret':_0x45c587[_0x199d('0xd1')],'read':_0x45c587['read']};})['value']()};return ejs[_0x199d('0xdd')](path[_0x199d('0xc8')](config[_0x199d('0xc9')],_0x199d('0xcc'),_0x199d('0xde'),_0x199d('0xdf')),{'interaction':_0x4063b4})[_0x199d('0x2c')](function(_0x10a7fc){var _0x506900=path[_0x199d('0xc8')](_0xb140c8,_0x199d('0xe0')+_0x82be14['id']+'-'+_0x1dcc55+_0x199d('0xe1'));var _0x2dd8d3={'path':_0x506900,'channel':_0x199d('0xd5'),'interactionId':_0x82be14['id']};return pdf[_0x199d('0xe2')](_0x10a7fc,_0x2dd8d3);})[_0x199d('0x2c')](function(){return new BPromise(function(_0x21fb96,_0x382d22){zipdir(_0xb140c8,{'saveTo':_0x45b66f},function(_0x38e855,_0x3ed1cd){if(_0x38e855)return _0x382d22(_0x38e855);return _0x21fb96(_0x3ed1cd);});})[_0x199d('0x2c')](function(){return new BPromise(function(_0x7a7e4,_0x49666f){rimraf(_0xb140c8,function(_0x517543){if(_0x517543)_0x49666f(_0x517543);return _0x7a7e4();});});})[_0x199d('0x2c')](function(){return _0x15e503['download'](_0x45b66f,_0x203ff6,function(_0xcf54a){if(_0xcf54a){console[_0x199d('0xe3')](_0x199d('0xe4'),_0xcf54a);}else{fs[_0x199d('0xe5')](_0x45b66f);}});});});}else{return _0x15e503[_0x199d('0x1f')](0xc8);}})[_0x199d('0x37')](handleError(_0x15e503,null));};
\ No newline at end of file
+var _0xc3bf=['key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','select','field','color','from','tools_tags','u.id','ui.SmsInteractionId','user_has_sms_interactions','users','sms_interactions','left_join','cm_contacts','o.id\x20=\x20i.UserId','sms_accounts','a.id\x20=\x20i.SmsAccountId','sms_messages','me.SmsInteractionId\x20=\x20i.id','sms_interaction_has_tags','t.id\x20=\x20it.TagId','expr','search','conditions','find','value','having','`\x20=\x200','`\x20>\x200','Contact','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','start','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','end','body','text','keys','some','compact','isEmpty','SmsAccountId','i.SmsAccountId\x20IN\x20?','concat','createdAt','$gte','parse','$lte','null','\x20=\x20?','read','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','contactName','DESC','resolve','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','role','agent','getSmsAccounts','i.SmsAccountId\x20IS\x20NULL','sequelize','toString','keyBy','merge','a.key','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.*','c.firstName','Contact.firstName','c.lastName','Contact.lastName','Contact.email','c.phone','c.mobile','Contact.mobile','Contact.fax','o.fullname','Owner.fullname','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.SmsInteractionId\x20IN\x20?','SmsInteractionId','rows','catch','params','includeAll','include','create','describe','addMessage','ids','omit','getMessages','findOne','SmsMessage','format','YYYY-MM-DD\x20HH:mm:ss','options','findAll','addTags','setTags','spread','Tag','emit','smsInteractionTags:save','removeTags','unix','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','User','CmContact','firstName','lastName','direction','SmsAccount','Account','get','mkdirSync','Owner','N.A.','closed','closedAt','disposition','Messages','System','out','renderFile','views','downloadInteraction.ejs','.pdf','Sms','createPdfFromHTML','download','log','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','../../components/auth/service','../../components/export/pdf','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsInteraction.socket','register','sendStatus','status','json','undefined','offset','count','limit','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','map','fullname','TagIds','Tags','split','forEach','push','SmsInteraction','rawAttributes','type'];(function(_0xbcea1,_0x469f9f){var _0x17fb47=function(_0x48f5e7){while(--_0x48f5e7){_0xbcea1['push'](_0xbcea1['shift']());}};_0x17fb47(++_0x469f9f);}(_0xc3bf,0x19d));var _0xfc3b=function(_0x48f0de,_0x4ab07d){_0x48f0de=_0x48f0de-0x0;var _0x43185b=_0xc3bf[_0x48f0de];return _0x43185b;};'use strict';var emlformat=require(_0xfc3b('0x0'));var rimraf=require(_0xfc3b('0x1'));var zipdir=require(_0xfc3b('0x2'));var jsonpatch=require(_0xfc3b('0x3'));var rp=require('request-promise');var moment=require(_0xfc3b('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xfc3b('0x5'));var util=require(_0xfc3b('0x6'));var path=require(_0xfc3b('0x7'));var sox=require('sox');var csv=require(_0xfc3b('0x8'));var ejs=require(_0xfc3b('0x9'));var fs=require('fs');var fs_extra=require(_0xfc3b('0xa'));var _=require(_0xfc3b('0xb'));var squel=require(_0xfc3b('0xc'));var crypto=require(_0xfc3b('0xd'));var jsforce=require(_0xfc3b('0xe'));var deskjs=require(_0xfc3b('0xf'));var toCsv=require(_0xfc3b('0x8'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xfc3b('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var pdf=require(_0xfc3b('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xfc3b('0x12'));var utils=require('../../config/utils');var config=require(_0xfc3b('0x13'));var licenseUtil=require(_0xfc3b('0x14'));var db=require(_0xfc3b('0x15'))['db'];config[_0xfc3b('0x16')]=_[_0xfc3b('0x17')](config[_0xfc3b('0x16')],{'host':_0xfc3b('0x18'),'port':0x18eb});var socket=require(_0xfc3b('0x19'))(new Redis(config[_0xfc3b('0x16')]));require(_0xfc3b('0x1a'))[_0xfc3b('0x1b')](socket);function respondWithStatusCode(_0xd4fbca,_0x272b33){_0x272b33=_0x272b33||0xcc;return function(_0xd7d9){if(_0xd7d9){return _0xd4fbca[_0xfc3b('0x1c')](_0x272b33);}return _0xd4fbca[_0xfc3b('0x1d')](_0x272b33)['end']();};}function respondWithResult(_0x268fb6,_0x2202f2){_0x2202f2=_0x2202f2||0xc8;return function(_0x8264a){if(_0x8264a){return _0x268fb6['status'](_0x2202f2)[_0xfc3b('0x1e')](_0x8264a);}};}function respondWithFilteredResult(_0x105124,_0x17bb62){return function(_0xd387fb){if(_0xd387fb){var _0x261332=typeof _0x17bb62['offset']===_0xfc3b('0x1f')&&typeof _0x17bb62['limit']===_0xfc3b('0x1f');var _0x3f272e=_0xd387fb['count'];var _0x4978c8=_0x261332?0x0:_0x17bb62[_0xfc3b('0x20')];var _0x31b4e9=_0x261332?_0xd387fb[_0xfc3b('0x21')]:_0x17bb62[_0xfc3b('0x20')]+_0x17bb62[_0xfc3b('0x22')];var _0x505af0;if(_0x31b4e9>=_0x3f272e){_0x31b4e9=_0x3f272e;_0x505af0=0xc8;}else{_0x505af0=0xce;}_0x105124['status'](_0x505af0);return _0x105124['set'](_0xfc3b('0x23'),_0x4978c8+'-'+_0x31b4e9+'/'+_0x3f272e)[_0xfc3b('0x1e')](_0xd387fb);}return null;};}function patchUpdates(_0x26da24){return function(_0x60721f){try{jsonpatch[_0xfc3b('0x24')](_0x60721f,_0x26da24,!![]);}catch(_0x588209){return BPromise[_0xfc3b('0x25')](_0x588209);}return _0x60721f[_0xfc3b('0x26')]();};}function saveUpdates(_0xd1b564,_0x380feb){return function(_0x4c0761){if(_0x4c0761){return _0x4c0761[_0xfc3b('0x27')](_0xd1b564)[_0xfc3b('0x28')](function(_0x1a469f){return _0x1a469f;});}return null;};}function removeEntity(_0x38df4a,_0x302e2a){return function(_0x160c61){if(_0x160c61){return _0x160c61[_0xfc3b('0x29')]()[_0xfc3b('0x28')](function(){_0x38df4a[_0xfc3b('0x1d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3c395c,_0x118b36){return function(_0x14bb1a){if(!_0x14bb1a){_0x3c395c[_0xfc3b('0x1c')](0x194);}return _0x14bb1a;};}function handleError(_0x346825,_0x16e716){_0x16e716=_0x16e716||0x1f4;return function(_0x2dbd09){logger[_0xfc3b('0x2a')](_0x2dbd09[_0xfc3b('0x2b')]);if(_0x2dbd09[_0xfc3b('0x2c')]){delete _0x2dbd09[_0xfc3b('0x2c')];}_0x346825[_0xfc3b('0x1d')](_0x16e716)['send'](_0x2dbd09);};}function getInteractionUsers(_0x51ba3f,_0x67c51e){return new BPromise(function(_0x18d18f,_0x1c462a){try{if(_0x67c51e[_0x51ba3f['id']]){_0x51ba3f['Users']=_[_0xfc3b('0x2d')](_0x67c51e[_0x51ba3f['id']],function(_0x1aaba5){return{'id':_0x1aaba5['id'],'fullname':_0x1aaba5[_0xfc3b('0x2e')]};});}}catch(_0x463644){_0x1c462a(_0x463644);}_0x18d18f(_0x51ba3f);});}function getInteractionTags(_0x3fe56c,_0x478693){return new BPromise(function(_0xba67c8,_0x4d948e){try{if(_0x3fe56c[_0xfc3b('0x2f')]){_0x3fe56c[_0xfc3b('0x30')]=[];_0x3fe56c[_0xfc3b('0x2f')][_0xfc3b('0x31')](',')[_0xfc3b('0x32')](function(_0x178445){_0x3fe56c[_0xfc3b('0x30')][_0xfc3b('0x33')](_0x478693[_0x178445]);});}delete _0x3fe56c['TagIds'];}catch(_0x22aa22){_0x4d948e(_0x22aa22);}_0xba67c8(_0x3fe56c);});}function updateSmsInteraction(_0xba3e3d,_0x3e7e4e,_0x3522ee){return new BPromise(function(_0x51d757,_0x242ed0){return getInteractionUsers(_0xba3e3d,_0x3522ee)['then'](function(_0x317213){return getInteractionTags(_0x317213,_0x3e7e4e);})[_0xfc3b('0x28')](function(_0x30524f){_0x51d757(_0x30524f);})['catch'](function(_0x37d200){_0x242ed0(_0x37d200);});});}exports['index']=function(_0x29d53e,_0xb84b66){var _0x115737={},_0x4a2599={},_0x186749={'count':0x0,'rows':[]};var _0x30ee6f=_[_0xfc3b('0x2d')](db[_0xfc3b('0x34')][_0xfc3b('0x35')],function(_0x346a1e){return{'name':_0x346a1e['fieldName'],'type':_0x346a1e[_0xfc3b('0x36')][_0xfc3b('0x37')]};});_0x4a2599[_0xfc3b('0x38')]=_[_0xfc3b('0x2d')](_0x30ee6f,_0xfc3b('0x2c'));_0x4a2599[_0xfc3b('0x39')]=_['keys'](_0x29d53e[_0xfc3b('0x39')]);_0x4a2599[_0xfc3b('0x3a')]=_[_0xfc3b('0x3b')](_0x4a2599[_0xfc3b('0x38')],_0x4a2599[_0xfc3b('0x39')]);_0x115737[_0xfc3b('0x3c')]=_[_0xfc3b('0x3b')](_0x4a2599[_0xfc3b('0x38')],qs[_0xfc3b('0x3d')](_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x3d')]));_0x115737[_0xfc3b('0x3c')]=_0x115737[_0xfc3b('0x3c')][_0xfc3b('0x3e')]?_0x115737['attributes']:_0x4a2599[_0xfc3b('0x38')];if(!_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x3f')](_0xfc3b('0x40'))){_0x115737[_0xfc3b('0x22')]=qs[_0xfc3b('0x22')](_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x22')]);_0x115737['offset']=qs['offset'](_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x20')]);}_0x115737[_0xfc3b('0x41')]=qs[_0xfc3b('0x42')](_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x42')]);_0x115737[_0xfc3b('0x43')]=qs[_0xfc3b('0x3a')](_[_0xfc3b('0x44')](_0x29d53e[_0xfc3b('0x39')],_0x4a2599[_0xfc3b('0x3a')]),_0x30ee6f);var _0xb5121e=[];var _0x21675a=squel[_0xfc3b('0x45')]()[_0xfc3b('0x46')]('id')[_0xfc3b('0x46')](_0xfc3b('0x2c'))[_0xfc3b('0x46')](_0xfc3b('0x47'))[_0xfc3b('0x48')](_0xfc3b('0x49'));var _0x424ff5=squel[_0xfc3b('0x45')]()[_0xfc3b('0x46')](_0xfc3b('0x4a'))['field']('u.fullname')[_0xfc3b('0x46')](_0xfc3b('0x4b'))[_0xfc3b('0x48')](_0xfc3b('0x4c'),'ui')['left_join'](_0xfc3b('0x4d'),'u','u.id\x20=\x20ui.UserId');var _0x4376bd=squel[_0xfc3b('0x45')]()['from'](_0xfc3b('0x4e'),'i')[_0xfc3b('0x4f')](_0xfc3b('0x50'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0xfc3b('0x4f')](_0xfc3b('0x4d'),'o',_0xfc3b('0x51'))[_0xfc3b('0x4f')](_0xfc3b('0x52'),'a',_0xfc3b('0x53'))[_0xfc3b('0x4f')](_0xfc3b('0x54'),'me',_0xfc3b('0x55'))['left_join'](_0xfc3b('0x56'),'it','it.SmsInteractionId\x20=\x20i.id')[_0xfc3b('0x4f')](_0xfc3b('0x49'),'t',_0xfc3b('0x57'));var _0x384362=squel['expr']();var _0x2f4c59=[];var _0x213a1f=squel[_0xfc3b('0x58')]();var _0x22be1c;if(_0x29d53e['query'][_0xfc3b('0x59')]){_0x22be1c=as['parseSearch'](_0x29d53e[_0xfc3b('0x39')]['search']);var _0xf47faf=_0x22be1c['sqlOperator'];for(var _0x2b8b1e=0x0;_0x2b8b1e<_0x22be1c[_0xfc3b('0x5a')][_0xfc3b('0x3e')];_0x2b8b1e++){var _0x3afc8b=_0x22be1c['conditions'][_0x2b8b1e];var _0xeddcd0='i';var _0x50ab94=_[_0xfc3b('0x5b')](_0x30ee6f,['name',_0x3afc8b[_0xfc3b('0x46')]]);if(!_0x50ab94){switch(_0x3afc8b[_0xfc3b('0x46')]){case'unreadMessages':if(_0x3afc8b[_0xfc3b('0x5c')]==0x1){_0x4376bd[_0xfc3b('0x5d')]('`'+_0x3afc8b[_0xfc3b('0x46')]+_0xfc3b('0x5e'));}else{_0x4376bd['having']('`'+_0x3afc8b[_0xfc3b('0x46')]+_0xfc3b('0x5f'));}break;case _0xfc3b('0x60'):if(_0x3afc8b['operator']==='$substring'){if(_0x3afc8b[_0xfc3b('0x5c')][_0xfc3b('0x31')]('\x20')['length']>0x1){_0x384362[_0xf47faf](_0xfc3b('0x61'),qs[_0xfc3b('0x62')](_0x3afc8b[_0xfc3b('0x5c')]),null);}else{var _0x32bb99='%'+_0x3afc8b['value']+'%';_0x384362[_0xf47faf](_0xfc3b('0x63'),_0x32bb99,_0x32bb99,_0x32bb99);}}else{_0x50ab94=_[_0xfc3b('0x5b')](_0x30ee6f,[_0xfc3b('0x2c'),_0xfc3b('0x64')]);_0x3afc8b['field']=_0xfc3b('0x64');_0x32cd19=as['buildExpression'](_0xeddcd0,_0x50ab94[_0xfc3b('0x36')],_0x3afc8b);_0x384362[_0xf47faf](_0x32cd19['text'],_0x32cd19[_0xfc3b('0x5c')][_0xfc3b('0x65')],_0x32cd19[_0xfc3b('0x5c')]['end']);}break;case'Tag':var _0x343e25=_0x3afc8b[_0xfc3b('0x5c')]['split'](',')[_0xfc3b('0x2d')](function(_0x356e71){return Number(_0x356e71);});_0x343e25['forEach'](function(_0x566291){_0x213a1f['or'](_0xfc3b('0x66'),'%,'+_0x566291+',%');});_0x2f4c59=_[_0xfc3b('0x67')](_0x2f4c59,_0x343e25);break;case'User':if(_0x3afc8b['operator']===_0xfc3b('0x68')){_0x384362[_0xf47faf](_0xfc3b('0x69'),'%'+_0x3afc8b['value']+'%',null);}else{_0x50ab94=_['find'](_0x30ee6f,[_0xfc3b('0x2c'),_0xfc3b('0x6a')]);_0x3afc8b['field']=_0xfc3b('0x6a');_0x32cd19=as[_0xfc3b('0x6b')](_0xeddcd0,_0x50ab94[_0xfc3b('0x36')],_0x3afc8b);_0x384362[_0xf47faf](_0x32cd19['text'],_0x32cd19['value'][_0xfc3b('0x65')],_0x32cd19[_0xfc3b('0x5c')][_0xfc3b('0x6c')]);}break;case _0xfc3b('0x6d'):_0x32cd19=as[_0xfc3b('0x6b')]('me',null,_0x3afc8b);_0x384362[_0xf47faf](_0x32cd19[_0xfc3b('0x6e')],_0x32cd19[_0xfc3b('0x5c')][_0xfc3b('0x65')],_0x32cd19[_0xfc3b('0x5c')][_0xfc3b('0x6c')]);break;}}else{var _0x32cd19=as[_0xfc3b('0x6b')](_0xeddcd0,_0x50ab94['type'],_0x3afc8b);_0x384362[_0xf47faf](_0x32cd19['text'],_0x32cd19[_0xfc3b('0x5c')]['start'],_0x32cd19[_0xfc3b('0x5c')][_0xfc3b('0x6c')]);}}}else{var _0x3c38c6=_(_0x29d53e[_0xfc3b('0x39')])[_0xfc3b('0x6f')]()['map'](function(_0x4bacb4){return _[_0xfc3b('0x70')](_0x30ee6f,[_0xfc3b('0x2c'),_0x4bacb4])?_0x4bacb4:undefined;})[_0xfc3b('0x71')]()[_0xfc3b('0x5c')]();if(!_[_0xfc3b('0x72')](_0x3c38c6)){_0x3c38c6[_0xfc3b('0x32')](function(_0x3f88e5){if(_0x3f88e5===_0xfc3b('0x73')){_0x4376bd['where'](_0xfc3b('0x74'),[][_0xfc3b('0x75')](_0x29d53e[_0xfc3b('0x39')][_0x3f88e5]));}else if(_0x3f88e5===_0xfc3b('0x76')){var _0x2821d2=JSON['parse'](_0x29d53e[_0xfc3b('0x39')][_0x3f88e5])[_0xfc3b('0x77')];var _0x24a1de=JSON[_0xfc3b('0x78')](_0x29d53e[_0xfc3b('0x39')][_0x3f88e5])[_0xfc3b('0x79')];_0x4376bd[_0xfc3b('0x43')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x2821d2,_0x24a1de);}else{if(_0x29d53e[_0xfc3b('0x39')][_0x3f88e5]===_0xfc3b('0x7a')){_0x4376bd['where']('i.'+_0x3f88e5+'\x20IS\x20NULL');}else{_0x4376bd[_0xfc3b('0x43')]('i.'+_0x3f88e5+_0xfc3b('0x7b'),_0x29d53e[_0xfc3b('0x39')][_0x3f88e5]);}}});}if(_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x7c')]){if(_0x29d53e['query'][_0xfc3b('0x7c')]==0x1){_0x4376bd[_0xfc3b('0x5d')]('`unreadMessages`\x20=\x200');}else{_0x4376bd['having'](_0xfc3b('0x7d'));}}if(_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x7e')]){_0x2f4c59=_[_0xfc3b('0x7f')](_0x29d53e['query'][_0xfc3b('0x7e')])?_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x7e')]:new Array(_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x7e')]);_0x2f4c59[_0xfc3b('0x32')](function(_0x1ab20c){_0x213a1f['or'](_0xfc3b('0x66'),'%,'+_0x1ab20c+',%');});}if(_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x80')]){var _0x3616df=_0x29d53e[_0xfc3b('0x39')]['filter'][_0xfc3b('0x81')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0xfc3b('0x82')](_0x3616df)){_0x384362['or'](_0xfc3b('0x83'),_0x3616df+'%')['or'](_0xfc3b('0x84'),_0x3616df+'%');}else{_0x384362['or'](_0xfc3b('0x85'),qs['getFullTextValue'](_0x3616df))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x3616df+'%');}}}_0x4376bd['where'](_0x384362);_0x4376bd[_0xfc3b('0x86')](_0xfc3b('0x87'));var _0x5d6d5e={'type':db[_0xfc3b('0x88')][_0xfc3b('0x89')][_0xfc3b('0x8a')],'raw':!![]};var _0x4dbbe0=_0x4376bd[_0xfc3b('0x8b')]();_0x4dbbe0['field'](_0xfc3b('0x87'));_0x4dbbe0[_0xfc3b('0x46')](_0xfc3b('0x8c'),_0xfc3b('0x8d'));if(_0x115737[_0xfc3b('0x41')]){_0x115737['order']['forEach'](function(_0x66a661){var _0x19d140=_0x66a661[0x0]===_0xfc3b('0x8e')?_0x66a661[0x0]:'i.'+_0x66a661[0x0];_0x4376bd['order'](_0x19d140,_0x66a661[0x1]===_0xfc3b('0x8f')?![]:!![]);});}if(!_[_0xfc3b('0x72')](_0x2f4c59)){_0x4376bd[_0xfc3b('0x5d')](_0x213a1f);_0x4dbbe0[_0xfc3b('0x43')]('t.id\x20IN\x20?',_0x2f4c59);}BPromise[_0xfc3b('0x90')]()[_0xfc3b('0x28')](function(){if(!_0x22be1c){if(_0x29d53e['query'][_0xfc3b('0x73')])return;_0x4dbbe0[_0xfc3b('0x43')](_0xfc3b('0x91'));_0x4376bd[_0xfc3b('0x43')](_0xfc3b('0x91'));return;}if(_0x29d53e[_0xfc3b('0x92')][_0xfc3b('0x93')]!==_0xfc3b('0x94'))return;return _0x29d53e[_0xfc3b('0x92')][_0xfc3b('0x95')]({'attributes':['id'],'raw':!![]})[_0xfc3b('0x28')](function(_0x1b1434){if(_[_0xfc3b('0x72')](_0x1b1434)){_0x4dbbe0[_0xfc3b('0x43')](_0xfc3b('0x96'));_0x4376bd['where'](_0xfc3b('0x96'));}else{_0x4dbbe0['where'](_0xfc3b('0x74'),_['map'](_0x1b1434,'id'));_0x4376bd[_0xfc3b('0x43')](_0xfc3b('0x74'),_[_0xfc3b('0x2d')](_0x1b1434,'id'));}});})[_0xfc3b('0x28')](function(){if(_0x29d53e[_0xfc3b('0x92')]['role']===_0xfc3b('0x94')&&!_0x22be1c&&!_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x73')])return[];return db['sequelize']['query'](_0x4dbbe0['toString'](),_0x5d6d5e);})['then'](function(_0x36f913){_0x186749['count']=_0x36f913[_0xfc3b('0x3e')];if(_0x186749[_0xfc3b('0x21')]===0x0)return[];return db[_0xfc3b('0x97')][_0xfc3b('0x39')](_0x21675a[_0xfc3b('0x98')](),_0x5d6d5e)[_0xfc3b('0x28')](function(_0x3cb167){_0xb5121e=_[_0xfc3b('0x99')](_0x3cb167,'id');_0x5d6d5e=_[_0xfc3b('0x9a')](_0x5d6d5e,{'model':db[_0xfc3b('0x34')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x29d53e[_0xfc3b('0x39')][_0xfc3b('0x3d')]){_0x115737[_0xfc3b('0x3c')]['forEach'](function(_0x3707fc){_0x4376bd[_0xfc3b('0x46')]('i.'+_0x3707fc);});}else{_0x4376bd[_0xfc3b('0x46')](_0xfc3b('0x8c'),'unreadMessages');_0x4376bd[_0xfc3b('0x46')](_0xfc3b('0x9b'),_0xfc3b('0x9c'));_0x4376bd[_0xfc3b('0x46')](_0xfc3b('0x9d'),_0xfc3b('0x9e'));_0x4376bd[_0xfc3b('0x46')](_0xfc3b('0x9f'),'contactName');_0x4376bd[_0xfc3b('0x46')](_0xfc3b('0xa0'));_0x4376bd['field'](_0xfc3b('0xa1'),_0xfc3b('0xa2'));_0x4376bd[_0xfc3b('0x46')](_0xfc3b('0xa3'),_0xfc3b('0xa4'));_0x4376bd['field']('c.email',_0xfc3b('0xa5'));_0x4376bd[_0xfc3b('0x46')](_0xfc3b('0xa6'),'Contact.phone');_0x4376bd[_0xfc3b('0x46')](_0xfc3b('0xa7'),_0xfc3b('0xa8'));_0x4376bd[_0xfc3b('0x46')]('c.fax',_0xfc3b('0xa9'));_0x4376bd[_0xfc3b('0x46')](_0xfc3b('0xaa'),_0xfc3b('0xab'));_0x4376bd[_0xfc3b('0x46')]('o.internal',_0xfc3b('0xac'));_0x4376bd[_0xfc3b('0x46')](_0xfc3b('0xad'),_0xfc3b('0x2f'));}if(_0x115737[_0xfc3b('0x22')])_0x4376bd[_0xfc3b('0x22')](_0x115737[_0xfc3b('0x22')]);if(_0x115737['offset'])_0x4376bd[_0xfc3b('0x20')](_0x115737[_0xfc3b('0x20')]);return db[_0xfc3b('0x97')][_0xfc3b('0x39')](_0x4376bd[_0xfc3b('0x98')](),_0x5d6d5e);})[_0xfc3b('0x28')](function(_0x557df8){if(_0x557df8[_0xfc3b('0x3e')]>0x0)_0x424ff5['where'](_0xfc3b('0xae'),_[_0xfc3b('0x2d')](_0x557df8,'id'));return db[_0xfc3b('0x97')][_0xfc3b('0x39')](_0x424ff5[_0xfc3b('0x98')](),_0x5d6d5e)[_0xfc3b('0x28')](function(_0x5630ca){var _0x20d441=_['groupBy'](_0x5630ca,_0xfc3b('0xaf'));var _0x2adc17=[];_0x557df8[_0xfc3b('0x32')](function(_0x57bb15){_0x2adc17[_0xfc3b('0x33')](updateSmsInteraction(_0x57bb15,_0xb5121e,_0x20d441));});return BPromise['all'](_0x2adc17);});});})['then'](function(_0x2f5ca1){_0x186749[_0xfc3b('0xb0')]=_0x2f5ca1;return _0x186749;})[_0xfc3b('0x28')](respondWithFilteredResult(_0xb84b66,_0x115737))[_0xfc3b('0xb1')](handleError(_0xb84b66,null));};exports['show']=function(_0x929aac,_0x172476){var _0x154abf={'raw':![],'where':{'id':_0x929aac[_0xfc3b('0xb2')]['id']}},_0x6de5c3={};_0x6de5c3[_0xfc3b('0x38')]=_[_0xfc3b('0x6f')](db[_0xfc3b('0x34')][_0xfc3b('0x35')]);_0x6de5c3['query']=_[_0xfc3b('0x6f')](_0x929aac[_0xfc3b('0x39')]);_0x6de5c3[_0xfc3b('0x3a')]=_[_0xfc3b('0x3b')](_0x6de5c3[_0xfc3b('0x38')],_0x6de5c3[_0xfc3b('0x39')]);_0x154abf[_0xfc3b('0x3c')]=_[_0xfc3b('0x3b')](_0x6de5c3['model'],qs[_0xfc3b('0x3d')](_0x929aac['query'][_0xfc3b('0x3d')]));_0x154abf[_0xfc3b('0x3c')]=_0x154abf[_0xfc3b('0x3c')][_0xfc3b('0x3e')]?_0x154abf[_0xfc3b('0x3c')]:_0x6de5c3[_0xfc3b('0x38')];if(_0x929aac[_0xfc3b('0x39')][_0xfc3b('0xb3')]){_0x154abf[_0xfc3b('0xb4')]=[{'all':!![]}];}_0x154abf=_[_0xfc3b('0x9a')]({},_0x154abf,_0x929aac['options']);return db['SmsInteraction']['find'](_0x154abf)[_0xfc3b('0x28')](handleEntityNotFound(_0x172476,null))[_0xfc3b('0x28')](respondWithResult(_0x172476,null))['catch'](handleError(_0x172476,null));};exports[_0xfc3b('0xb5')]=function(_0x101743,_0x243d69){return db[_0xfc3b('0x34')][_0xfc3b('0xb5')](_0x101743['body'],{})['then'](respondWithResult(_0x243d69,0xc9))[_0xfc3b('0xb1')](handleError(_0x243d69,null));};exports[_0xfc3b('0x27')]=function(_0xad9d70,_0x2114be){if(_0xad9d70[_0xfc3b('0x6d')]['id']){delete _0xad9d70['body']['id'];}return db[_0xfc3b('0x34')]['find']({'where':{'id':_0xad9d70[_0xfc3b('0xb2')]['id']}})['then'](handleEntityNotFound(_0x2114be,null))[_0xfc3b('0x28')](saveUpdates(_0xad9d70[_0xfc3b('0x6d')],null))[_0xfc3b('0x28')](respondWithResult(_0x2114be,null))[_0xfc3b('0xb1')](handleError(_0x2114be,null));};exports['destroy']=function(_0x217c52,_0x40ea2d){return db[_0xfc3b('0x34')][_0xfc3b('0x5b')]({'where':{'id':_0x217c52[_0xfc3b('0xb2')]['id']}})[_0xfc3b('0x28')](handleEntityNotFound(_0x40ea2d,null))[_0xfc3b('0x28')](removeEntity(_0x40ea2d,null))[_0xfc3b('0xb1')](handleError(_0x40ea2d,null));};exports[_0xfc3b('0xb6')]=function(_0x1c702e,_0x73aa0b){return db[_0xfc3b('0x34')]['describe']()[_0xfc3b('0x28')](respondWithResult(_0x73aa0b,null))[_0xfc3b('0xb1')](handleError(_0x73aa0b,null));};exports['addMessage']=function(_0xf10d5b,_0x4cf5bf,_0x2e6f7f){return db['SmsMessage'][_0xfc3b('0x5b')]({'where':{'id':_0xf10d5b[_0xfc3b('0xb2')]['id']}})[_0xfc3b('0x28')](handleEntityNotFound(_0x4cf5bf,null))[_0xfc3b('0x28')](function(_0x509c22){if(_0x509c22){return _0x509c22[_0xfc3b('0xb7')](_0xf10d5b[_0xfc3b('0x6d')][_0xfc3b('0xb8')],_[_0xfc3b('0xb9')](_0xf10d5b[_0xfc3b('0x6d')],[_0xfc3b('0xb8'),'id'])||{});}})[_0xfc3b('0x28')](respondWithResult(_0x4cf5bf,null))[_0xfc3b('0xb1')](handleError(_0x4cf5bf,null));};exports[_0xfc3b('0xba')]=function(_0x5ab2d3,_0x57d7f7,_0x15fda6){var _0x493781={'raw':![],'where':{}};var _0x10ec30={};var _0x533a9c={'count':0x0,'rows':[]};return db['SmsInteraction'][_0xfc3b('0xbb')]({'where':{'id':_0x5ab2d3[_0xfc3b('0xb2')]['id']}})[_0xfc3b('0x28')](handleEntityNotFound(_0x57d7f7,null))['then'](function(_0x267ddf){if(_0x267ddf){_0x10ec30[_0xfc3b('0x38')]=_[_0xfc3b('0x6f')](db[_0xfc3b('0xbc')]['rawAttributes']);_0x10ec30[_0xfc3b('0x39')]=_[_0xfc3b('0x6f')](_0x5ab2d3[_0xfc3b('0x39')]);_0x10ec30[_0xfc3b('0x3a')]=_[_0xfc3b('0x3b')](_0x10ec30[_0xfc3b('0x38')],_0x10ec30[_0xfc3b('0x39')]);_0x493781['attributes']=_[_0xfc3b('0x3b')](_0x10ec30[_0xfc3b('0x38')],qs['fields'](_0x5ab2d3[_0xfc3b('0x39')][_0xfc3b('0x3d')]));_0x493781[_0xfc3b('0x3c')]=_0x493781[_0xfc3b('0x3c')][_0xfc3b('0x3e')]?_0x493781[_0xfc3b('0x3c')]:_0x10ec30[_0xfc3b('0x38')];if(!_0x5ab2d3[_0xfc3b('0x39')]['hasOwnProperty']('nolimit')){_0x493781[_0xfc3b('0x22')]=qs['limit'](_0x5ab2d3[_0xfc3b('0x39')]['limit']);_0x493781[_0xfc3b('0x20')]=qs[_0xfc3b('0x20')](_0x5ab2d3[_0xfc3b('0x39')][_0xfc3b('0x20')]);}_0x493781[_0xfc3b('0x41')]=qs[_0xfc3b('0x42')](_0x5ab2d3[_0xfc3b('0x39')][_0xfc3b('0x42')]);_0x493781['where']=qs[_0xfc3b('0x3a')](_[_0xfc3b('0x44')](_0x5ab2d3[_0xfc3b('0x39')],_0x10ec30[_0xfc3b('0x3a')]));_0x493781[_0xfc3b('0x43')][_0xfc3b('0xaf')]=_0x267ddf['id'];if(_0x5ab2d3['query'][_0xfc3b('0x80')]){_0x493781['where']=_[_0xfc3b('0x9a')](_0x493781['where'],{'$or':_[_0xfc3b('0x2d')](_0x493781[_0xfc3b('0x3c')],function(_0x53fbbd){var _0x3b8ec3={};_0x3b8ec3[_0x53fbbd]={'$like':'%'+_0x5ab2d3[_0xfc3b('0x39')]['filter']+'%'};return _0x3b8ec3;})});}if(_0x5ab2d3[_0xfc3b('0x39')][_0xfc3b('0x77')]){var _0xf01eb4=_0x5ab2d3[_0xfc3b('0x39')][_0xfc3b('0x77')][_0xfc3b('0x31')](',');var _0x2d1718={};_0x2d1718[_0xf01eb4[0x0]]={'$gte':moment(_0xf01eb4[0x1])[_0xfc3b('0xbd')](_0xfc3b('0xbe'))};_0x493781[_0xfc3b('0x43')]=_[_0xfc3b('0x9a')](_0x493781[_0xfc3b('0x43')],_0x2d1718);}_0x493781=_[_0xfc3b('0x9a')]({},_0x493781,_0x5ab2d3[_0xfc3b('0xbf')]);return db[_0xfc3b('0xbc')][_0xfc3b('0x21')]({'where':_0x493781[_0xfc3b('0x43')]})[_0xfc3b('0x28')](function(_0x372e2c){_0x533a9c[_0xfc3b('0x21')]=_0x372e2c;if(_0x5ab2d3[_0xfc3b('0x39')][_0xfc3b('0xb3')]){_0x493781[_0xfc3b('0xb4')]=[{'all':!![]}];}return db['SmsMessage'][_0xfc3b('0xc0')](_0x493781);})[_0xfc3b('0x28')](function(_0x49c700){_0x533a9c[_0xfc3b('0xb0')]=_0x49c700;return _0x533a9c;});}})[_0xfc3b('0x28')](respondWithFilteredResult(_0x57d7f7,_0x493781))['catch'](handleError(_0x57d7f7,null));};exports[_0xfc3b('0xc1')]=function(_0x4a40b9,_0x19124c,_0x12f4ef){return db[_0xfc3b('0x34')][_0xfc3b('0x5b')]({'where':{'id':_0x4a40b9[_0xfc3b('0xb2')]['id']}})['then'](handleEntityNotFound(_0x19124c,null))[_0xfc3b('0x28')](function(_0x540d33){if(_0x540d33){return _0x540d33[_0xfc3b('0xc2')](_0x4a40b9[_0xfc3b('0x6d')][_0xfc3b('0xb8')],_['omit'](_0x4a40b9[_0xfc3b('0x6d')],[_0xfc3b('0xb8'),'id'])||{})[_0xfc3b('0xc3')](function(){return db[_0xfc3b('0xc4')][_0xfc3b('0xc0')]({'attributes':['id',_0xfc3b('0x2c'),_0xfc3b('0x47')],'where':{'id':_0x4a40b9['body'][_0xfc3b('0xb8')]}});})[_0xfc3b('0x28')](function(_0x4a908a){socket[_0xfc3b('0xc5')](_0xfc3b('0xc6'),{'id':Number(_0x4a40b9[_0xfc3b('0xb2')]['id']),'tags':_0x4a908a||[]});return{'id':Number(_0x4a40b9[_0xfc3b('0xb2')]['id']),'tags':_0x4a908a||[]};});}})['then'](respondWithResult(_0x19124c,null))[_0xfc3b('0xb1')](handleError(_0x19124c,null));};exports[_0xfc3b('0xc7')]=function(_0x2cc6df,_0x514c7b,_0x39dd2d){return db[_0xfc3b('0x34')][_0xfc3b('0x5b')]({'where':{'id':_0x2cc6df[_0xfc3b('0xb2')]['id']}})['then'](handleEntityNotFound(_0x514c7b,null))[_0xfc3b('0x28')](function(_0x1e31c0){if(_0x1e31c0){return _0x1e31c0['removeTags'](_0x2cc6df['query'][_0xfc3b('0xb8')]);}})[_0xfc3b('0x28')](respondWithStatusCode(_0x514c7b,null))[_0xfc3b('0xb1')](handleError(_0x514c7b,null));};exports['download']=function(_0x2300a5,_0x2e95e3){var _0x479322=moment()[_0xfc3b('0xc8')]()[_0xfc3b('0x98')]();var _0x360c01=path[_0xfc3b('0xc9')](config[_0xfc3b('0xca')],_0xfc3b('0xcb'),_0xfc3b('0xcc'),_0xfc3b('0xcd'));var _0x404b0c=path['join'](config[_0xfc3b('0xca')],_0xfc3b('0xcb'),_0xfc3b('0xcc'),_0xfc3b('0xce'));var _0x41a37b=path[_0xfc3b('0xc9')](_0x360c01,_0x479322);var _0x361933=util[_0xfc3b('0xbd')](_0xfc3b('0xcf'),_0x2300a5[_0xfc3b('0xb2')]['id'],_0x479322);var _0x43f13c=path[_0xfc3b('0xc9')](_0x360c01,_0x361933);var _0x1c0038=[];_0x1c0038['push']({'model':db[_0xfc3b('0xd0')],'as':'User','attributes':['id','fullname'],'raw':!![]});_0x1c0038['push']({'model':db[_0xfc3b('0xd1')],'as':_0xfc3b('0x60'),'attributes':['id',_0xfc3b('0xd2'),_0xfc3b('0xd3')],'raw':!![]});var _0x112304=[{'model':db[_0xfc3b('0xbc')],'as':'Messages','attributes':['id',_0xfc3b('0x6d'),_0xfc3b('0x76'),_0xfc3b('0xd4'),'secret',_0xfc3b('0x7c')],'include':_0x1c0038}];_0x112304[_0xfc3b('0x33')]({'model':db[_0xfc3b('0xd5')],'as':_0xfc3b('0xd6'),'attributes':['id','name']});_0x112304[_0xfc3b('0x33')]({'model':db[_0xfc3b('0xd0')],'as':'Owner','attributes':['id',_0xfc3b('0x2e')]});return db[_0xfc3b('0x34')][_0xfc3b('0x5b')]({'where':{'id':_0x2300a5[_0xfc3b('0xb2')]['id']},'include':_0x112304})[_0xfc3b('0x28')](handleEntityNotFound(_0x2e95e3,null))[_0xfc3b('0x28')](function(_0x39cd33){if(_0x39cd33){var _0x305945=_0x39cd33[_0xfc3b('0xd7')]({'plain':!![]});fs[_0xfc3b('0xd8')](_0x41a37b);var _0x4cd32e={'channel':'Sms','account':_0x305945[_0xfc3b('0xd6')][_0xfc3b('0x2c')],'agent':_0x305945['Owner']?_0x305945[_0xfc3b('0xd9')][_0xfc3b('0x2e')]:_0xfc3b('0xda'),'createdAt':moment(_0x305945['createdAt'])[_0xfc3b('0xbd')]('YYYY-MM-DD\x20HH:mm:ss')[_0xfc3b('0x98')](),'closedAt':_0x305945[_0xfc3b('0xdb')]?moment(_0x305945[_0xfc3b('0xdc')])[_0xfc3b('0xbd')](_0xfc3b('0xbe'))[_0xfc3b('0x98')]():'','disposition':_0x305945[_0xfc3b('0xdd')],'messages':_(_0x305945[_0xfc3b('0xde')])[_0xfc3b('0x80')]({'secret':![]})['map'](function(_0xed9ac8){return{'date':moment(_0xed9ac8[_0xfc3b('0x76')])[_0xfc3b('0xbd')]('YYYY-MM-DD\x20HH:mm:ss')[_0xfc3b('0x98')](),'sender':_0xed9ac8[_0xfc3b('0xd4')]==='out'?_0xed9ac8[_0xfc3b('0xd0')]?_0xed9ac8['User'][_0xfc3b('0x2e')]:_0xfc3b('0xdf'):_0xed9ac8[_0xfc3b('0x60')][_0xfc3b('0xd2')]+(_0xed9ac8['Contact'][_0xfc3b('0xd3')]?'\x20'+_0xed9ac8['Contact'][_0xfc3b('0xd3')]:''),'body':_0xed9ac8[_0xfc3b('0x6d')],'direction':_0xed9ac8['direction']===_0xfc3b('0xe0')?'A':'C','secret':_0xed9ac8['secret'],'read':_0xed9ac8[_0xfc3b('0x7c')]};})[_0xfc3b('0x5c')]()};return ejs[_0xfc3b('0xe1')](path['join'](config[_0xfc3b('0xca')],_0xfc3b('0xcb'),_0xfc3b('0xe2'),_0xfc3b('0xe3')),{'interaction':_0x4cd32e})[_0xfc3b('0x28')](function(_0x43bee7){var _0x2372fd=path['join'](_0x41a37b,'transcript-'+_0x305945['id']+'-'+_0x479322+_0xfc3b('0xe4'));var _0x4bb4a4={'path':_0x2372fd,'channel':_0xfc3b('0xe5'),'interactionId':_0x305945['id']};return pdf[_0xfc3b('0xe6')](_0x43bee7,_0x4bb4a4);})[_0xfc3b('0x28')](function(){return new BPromise(function(_0x28f11e,_0x511985){zipdir(_0x41a37b,{'saveTo':_0x43f13c},function(_0x4571ae,_0x816cb8){if(_0x4571ae)return _0x511985(_0x4571ae);return _0x28f11e(_0x816cb8);});})[_0xfc3b('0x28')](function(){return new BPromise(function(_0x4b0ee3,_0x587e49){rimraf(_0x41a37b,function(_0x43a9b5){if(_0x43a9b5)_0x587e49(_0x43a9b5);return _0x4b0ee3();});});})[_0xfc3b('0x28')](function(){return _0x2e95e3[_0xfc3b('0xe7')](_0x43f13c,_0x361933,function(_0x28c120){if(_0x28c120){console[_0xfc3b('0xe8')]('err',_0x28c120);}else{fs[_0xfc3b('0xe9')](_0x43f13c);}});});});}else{return _0x2e95e3[_0xfc3b('0x1c')](0xc8);}})[_0xfc3b('0xb1')](handleError(_0x2e95e3,null));};
\ No newline at end of file