Built motion from commit (unavailable).|2.5.15
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 9a8526e..e6021de 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfcbb=['options','findAll','rows','addTags','setTags','emit','smsInteractionTags:save','removeTags','unix','join','root','files','tmp','server','attachments','transcript-%d-%s.zip','User','Contact','firstName','secret','SmsAccount','Account','Owner','get','mkdirSync','10px','40px','<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>','YYYY-MM-DD','Sms','N.A.','closed','closedAt','disposition','direction','out','System','renderFile','views','downloadInteraction.html','toFile','download','err','unlinkSync','html-pdf','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','redis','defaults','socket.io-emitter','./smsInteraction.socket','register','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','save','update','then','destroy','error','name','send','Users','map','fullname','TagIds','Tags','forEach','push','SmsInteraction','fieldName','model','query','keys','filters','attributes','intersection','fields','hasOwnProperty','nolimit','sort','where','pick','field','color','from','select','u.fullname','ui.SmsInteractionId','user_has_sms_interactions','left_join','users','u.id\x20=\x20ui.UserId','sms_interactions','cm_contacts','o.id\x20=\x20i.UserId','sms_accounts','sms_messages','me.SmsInteractionId\x20=\x20i.id','it.SmsInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','parseSearch','search','conditions','unreadMessages','value','`\x20=\x200','having','operator','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','type','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','$substring','find','UserId','text','body','some','isEmpty','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','\x27\x27\x27\x27','isNumeric','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SELECT','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','order','DESC','journey','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','i.SmsAccountId\x20IS\x20NULL','i.SmsAccountId\x20IN\x20?','sequelize','toString','keyBy','merge','a.mandatoryDisposition','Account.mandatoryDisposition','i.*','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','Contact.phone','Owner.fullname','o.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','SmsInteractionId','all','catch','show','params','rawAttributes','length','includeAll','include','create','describe','addMessage','SmsMessage','ids','omit','getMessages','split','format','YYYY-MM-DD\x20HH:mm:ss'];(function(_0x2010e4,_0x2d9bfc){var _0x58f6f0=function(_0x4ad6d9){while(--_0x4ad6d9){_0x2010e4['push'](_0x2010e4['shift']());}};_0x58f6f0(++_0x2d9bfc);}(_0xfcbb,0x10d));var _0xbfcb=function(_0x4b3f7f,_0x529369){_0x4b3f7f=_0x4b3f7f-0x0;var _0x4302fe=_0xfcbb[_0x4b3f7f];return _0x4302fe;};'use strict';var pdf=require(_0xbfcb('0x0'));var emlformat=require(_0xbfcb('0x1'));var rimraf=require(_0xbfcb('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xbfcb('0x3'));var moment=require(_0xbfcb('0x4'));var BPromise=require(_0xbfcb('0x5'));var Mustache=require(_0xbfcb('0x6'));var util=require(_0xbfcb('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0xbfcb('0x8'));var ejs=require(_0xbfcb('0x9'));var fs=require('fs');var _=require(_0xbfcb('0xa'));var squel=require(_0xbfcb('0xb'));var crypto=require(_0xbfcb('0xc'));var jsforce=require(_0xbfcb('0xd'));var deskjs=require(_0xbfcb('0xe'));var toCsv=require('to-csv');var querystring=require(_0xbfcb('0xf'));var Papa=require(_0xbfcb('0x10'));var Redis=require(_0xbfcb('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xbfcb('0x12'));var as=require(_0xbfcb('0x13'));var hardwareService=require(_0xbfcb('0x14'));var logger=require(_0xbfcb('0x15'))(_0xbfcb('0x16'));var utils=require(_0xbfcb('0x17'));var config=require('../../config/environment');var db=require(_0xbfcb('0x18'))['db'];config[_0xbfcb('0x19')]=_[_0xbfcb('0x1a')](config[_0xbfcb('0x19')],{'host':'localhost','port':0x18eb});var socket=require(_0xbfcb('0x1b'))(new Redis(config['redis']));require(_0xbfcb('0x1c'))[_0xbfcb('0x1d')](socket);function respondWithStatusCode(_0x44ad6c,_0x1047c4){_0x1047c4=_0x1047c4||0xcc;return function(_0x2074d4){if(_0x2074d4){return _0x44ad6c[_0xbfcb('0x1e')](_0x1047c4);}return _0x44ad6c[_0xbfcb('0x1f')](_0x1047c4)[_0xbfcb('0x20')]();};}function respondWithResult(_0x90ed8c,_0x339347){_0x339347=_0x339347||0xc8;return function(_0x2c4a85){if(_0x2c4a85){return _0x90ed8c[_0xbfcb('0x1f')](_0x339347)[_0xbfcb('0x21')](_0x2c4a85);}};}function respondWithFilteredResult(_0x41dc15,_0x318d07){return function(_0x1a4d75){if(_0x1a4d75){var _0xba1d6=_0x1a4d75[_0xbfcb('0x22')],_0x38689e=_0x318d07[_0xbfcb('0x23')],_0x3404aa=_0x318d07['offset']+_0x318d07[_0xbfcb('0x24')],_0x46b8d2;if(_0x3404aa>=_0xba1d6){_0x3404aa=_0xba1d6;_0x46b8d2=0xc8;}else{_0x46b8d2=0xce;}_0x41dc15[_0xbfcb('0x1f')](_0x46b8d2);return _0x41dc15['set'](_0xbfcb('0x25'),_0x38689e+'-'+_0x3404aa+'/'+_0xba1d6)[_0xbfcb('0x21')](_0x1a4d75);}return null;};}function patchUpdates(_0x48c3c8){return function(_0x58f16b){try{jsonpatch[_0xbfcb('0x26')](_0x58f16b,_0x48c3c8,!![]);}catch(_0x45f0a0){return BPromise[_0xbfcb('0x27')](_0x45f0a0);}return _0x58f16b[_0xbfcb('0x28')]();};}function saveUpdates(_0x1c5924,_0x56c158){return function(_0x365d6c){if(_0x365d6c){return _0x365d6c[_0xbfcb('0x29')](_0x1c5924)[_0xbfcb('0x2a')](function(_0xd4d29){return _0xd4d29;});}return null;};}function removeEntity(_0x1651e5,_0x19616c){return function(_0x69c8e9){if(_0x69c8e9){return _0x69c8e9[_0xbfcb('0x2b')]()[_0xbfcb('0x2a')](function(){_0x1651e5[_0xbfcb('0x1f')](0xcc)[_0xbfcb('0x20')]();});}};}function handleEntityNotFound(_0xf6dbb7,_0x3ef71c){return function(_0x121a90){if(!_0x121a90){_0xf6dbb7[_0xbfcb('0x1e')](0x194);}return _0x121a90;};}function handleError(_0x2a1272,_0x5cd703){_0x5cd703=_0x5cd703||0x1f4;return function(_0x3465f5){logger[_0xbfcb('0x2c')](_0x3465f5['stack']);if(_0x3465f5[_0xbfcb('0x2d')]){delete _0x3465f5[_0xbfcb('0x2d')];}_0x2a1272[_0xbfcb('0x1f')](_0x5cd703)[_0xbfcb('0x2e')](_0x3465f5);};}function getInteractionUsers(_0xf4b944,_0x3542e9){return new BPromise(function(_0x4069a7,_0x1a5db2){try{if(_0x3542e9[_0xf4b944['id']]){_0xf4b944[_0xbfcb('0x2f')]=_[_0xbfcb('0x30')](_0x3542e9[_0xf4b944['id']],function(_0x59719b){return{'id':_0x59719b['id'],'fullname':_0x59719b[_0xbfcb('0x31')]};});}}catch(_0x3aa3cd){_0x1a5db2(_0x3aa3cd);}_0x4069a7(_0xf4b944);});}function getInteractionTags(_0x43c3c3,_0x43de3c){return new BPromise(function(_0x1f45fc,_0x14f6f5){try{if(_0x43c3c3[_0xbfcb('0x32')]){_0x43c3c3[_0xbfcb('0x33')]=[];_0x43c3c3[_0xbfcb('0x32')]['split'](',')[_0xbfcb('0x34')](function(_0xaa6ae6){_0x43c3c3[_0xbfcb('0x33')][_0xbfcb('0x35')](_0x43de3c[_0xaa6ae6]);});}delete _0x43c3c3['TagIds'];}catch(_0x5aa2dd){_0x14f6f5(_0x5aa2dd);}_0x1f45fc(_0x43c3c3);});}function updateSmsInteraction(_0x30cf97,_0x35925b,_0x1d523d){return new BPromise(function(_0x1b2fa5,_0x32d9a2){return getInteractionUsers(_0x30cf97,_0x1d523d)[_0xbfcb('0x2a')](function(_0x60f995){return getInteractionTags(_0x60f995,_0x35925b);})['then'](function(_0x504d81){_0x1b2fa5(_0x504d81);})['catch'](function(_0x1eab10){_0x32d9a2(_0x1eab10);});});}exports['index']=function(_0xda9f61,_0x410948){var _0x505b0d={},_0x49c295={},_0x935af={'count':0x0,'rows':[]};var _0x256177=_[_0xbfcb('0x30')](db[_0xbfcb('0x36')]['rawAttributes'],function(_0x159f3d){return{'name':_0x159f3d[_0xbfcb('0x37')],'type':_0x159f3d['type']['key']};});_0x49c295[_0xbfcb('0x38')]=_['map'](_0x256177,'name');_0x49c295[_0xbfcb('0x39')]=_[_0xbfcb('0x3a')](_0xda9f61[_0xbfcb('0x39')]);_0x49c295[_0xbfcb('0x3b')]=_['intersection'](_0x49c295[_0xbfcb('0x38')],_0x49c295[_0xbfcb('0x39')]);_0x505b0d[_0xbfcb('0x3c')]=_[_0xbfcb('0x3d')](_0x49c295[_0xbfcb('0x38')],qs[_0xbfcb('0x3e')](_0xda9f61['query'][_0xbfcb('0x3e')]));_0x505b0d['attributes']=_0x505b0d[_0xbfcb('0x3c')]['length']?_0x505b0d[_0xbfcb('0x3c')]:_0x49c295[_0xbfcb('0x38')];if(!_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x3f')](_0xbfcb('0x40'))){_0x505b0d[_0xbfcb('0x24')]=qs[_0xbfcb('0x24')](_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x24')]);_0x505b0d[_0xbfcb('0x23')]=qs['offset'](_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x23')]);}_0x505b0d['order']=qs[_0xbfcb('0x41')](_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x41')]);_0x505b0d[_0xbfcb('0x42')]=qs[_0xbfcb('0x3b')](_[_0xbfcb('0x43')](_0xda9f61['query'],_0x49c295[_0xbfcb('0x3b')]));var _0x10ffa0=[];var _0x10ea4f=squel['select']()[_0xbfcb('0x44')]('id')[_0xbfcb('0x44')](_0xbfcb('0x2d'))['field'](_0xbfcb('0x45'))[_0xbfcb('0x46')]('tools_tags');var _0x4f9521=squel[_0xbfcb('0x47')]()[_0xbfcb('0x44')]('u.id')[_0xbfcb('0x44')](_0xbfcb('0x48'))['field'](_0xbfcb('0x49'))[_0xbfcb('0x46')](_0xbfcb('0x4a'),'ui')[_0xbfcb('0x4b')](_0xbfcb('0x4c'),'u',_0xbfcb('0x4d'));var _0x19d04d=squel[_0xbfcb('0x47')]()[_0xbfcb('0x46')](_0xbfcb('0x4e'),'i')[_0xbfcb('0x4b')](_0xbfcb('0x4f'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0xbfcb('0x4b')](_0xbfcb('0x4c'),'o',_0xbfcb('0x50'))['left_join'](_0xbfcb('0x51'),'a','a.id\x20=\x20i.SmsAccountId')['left_join'](_0xbfcb('0x52'),'me',_0xbfcb('0x53'))[_0xbfcb('0x4b')]('sms_interaction_has_tags','it',_0xbfcb('0x54'))['left_join']('tools_tags','t',_0xbfcb('0x55'));var _0x588d32=squel[_0xbfcb('0x56')]();var _0x7afcba=[];var _0x538c23=squel[_0xbfcb('0x56')]();var _0x5d942f;if(_0xda9f61[_0xbfcb('0x39')]['search']){_0x5d942f=as[_0xbfcb('0x57')](_0xda9f61['query'][_0xbfcb('0x58')]);var _0x423822=_0x5d942f['sqlOperator'];for(var _0x131af7=0x0;_0x131af7<_0x5d942f['conditions']['length'];_0x131af7++){var _0x3b8683=_0x5d942f[_0xbfcb('0x59')][_0x131af7];var _0xce9c54='i';var _0x5bc330=_['find'](_0x256177,[_0xbfcb('0x2d'),_0x3b8683[_0xbfcb('0x44')]]);if(!_0x5bc330){switch(_0x3b8683[_0xbfcb('0x44')]){case _0xbfcb('0x5a'):if(_0x3b8683[_0xbfcb('0x5b')]==0x1){_0x19d04d['having']('`'+_0x3b8683[_0xbfcb('0x44')]+_0xbfcb('0x5c'));}else{_0x19d04d[_0xbfcb('0x5d')]('`'+_0x3b8683[_0xbfcb('0x44')]+'`\x20>\x200');}break;case'Contact':if(_0x3b8683[_0xbfcb('0x5e')]==='$substring'){if(_0x3b8683[_0xbfcb('0x5b')]['split']('\x20')['length']>0x1){_0x588d32[_0x423822](_0xbfcb('0x5f'),qs['getFullTextValue'](_0x3b8683['value']),null);}else{var _0x27058a='%'+_0x3b8683['value']+'%';_0x588d32[_0x423822](_0xbfcb('0x60'),_0x27058a,_0x27058a,_0x27058a);}}else{_0x5bc330=_['find'](_0x256177,[_0xbfcb('0x2d'),_0xbfcb('0x61')]);_0x3b8683['field']=_0xbfcb('0x61');_0x548083=as[_0xbfcb('0x62')](_0xce9c54,_0x5bc330[_0xbfcb('0x63')],_0x3b8683);_0x588d32[_0x423822](_0x548083['text'],_0x548083[_0xbfcb('0x5b')][_0xbfcb('0x64')],_0x548083[_0xbfcb('0x5b')][_0xbfcb('0x20')]);}break;case _0xbfcb('0x65'):var _0x4421fc=_0x3b8683[_0xbfcb('0x5b')]['split'](',')[_0xbfcb('0x30')](function(_0x5743ad){return Number(_0x5743ad);});_0x4421fc[_0xbfcb('0x34')](function(_0xf5c2a1){_0x538c23['or'](_0xbfcb('0x66'),'%,'+_0xf5c2a1+',%');});_0x7afcba=_[_0xbfcb('0x67')](_0x7afcba,_0x4421fc);break;case'User':if(_0x3b8683['operator']===_0xbfcb('0x68')){_0x588d32[_0x423822]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x3b8683[_0xbfcb('0x5b')]+'%',null);}else{_0x5bc330=_[_0xbfcb('0x69')](_0x256177,[_0xbfcb('0x2d'),_0xbfcb('0x6a')]);_0x3b8683[_0xbfcb('0x44')]=_0xbfcb('0x6a');_0x548083=as['buildExpression'](_0xce9c54,_0x5bc330[_0xbfcb('0x63')],_0x3b8683);_0x588d32[_0x423822](_0x548083[_0xbfcb('0x6b')],_0x548083[_0xbfcb('0x5b')][_0xbfcb('0x64')],_0x548083[_0xbfcb('0x5b')][_0xbfcb('0x20')]);}break;case _0xbfcb('0x6c'):_0x548083=as['buildExpression']('me',null,_0x3b8683);_0x588d32[_0x423822](_0x548083['text'],_0x548083['value'][_0xbfcb('0x64')],_0x548083[_0xbfcb('0x5b')][_0xbfcb('0x20')]);break;}}else{var _0x548083=as[_0xbfcb('0x62')](_0xce9c54,_0x5bc330[_0xbfcb('0x63')],_0x3b8683);_0x588d32[_0x423822](_0x548083[_0xbfcb('0x6b')],_0x548083['value']['start'],_0x548083['value'][_0xbfcb('0x20')]);}}}else{var _0x156f61=_(_0xda9f61[_0xbfcb('0x39')])[_0xbfcb('0x3a')]()['map'](function(_0x196d51){return _[_0xbfcb('0x6d')](_0x256177,[_0xbfcb('0x2d'),_0x196d51])?_0x196d51:undefined;})['compact']()['value']();if(!_[_0xbfcb('0x6e')](_0x156f61)){_0x156f61[_0xbfcb('0x34')](function(_0x5e011a){if(_0x5e011a==='SmsAccountId'){_0x19d04d['where']('i.SmsAccountId\x20IN\x20?',[][_0xbfcb('0x6f')](_0xda9f61[_0xbfcb('0x39')][_0x5e011a]));}else if(_0x5e011a===_0xbfcb('0x70')){var _0x2d77f9=JSON[_0xbfcb('0x71')](_0xda9f61[_0xbfcb('0x39')][_0x5e011a])[_0xbfcb('0x72')];var _0x299e63=JSON['parse'](_0xda9f61[_0xbfcb('0x39')][_0x5e011a])[_0xbfcb('0x73')];_0x19d04d[_0xbfcb('0x42')](_0xbfcb('0x74'),_0x2d77f9,_0x299e63);}else{if(_0xda9f61[_0xbfcb('0x39')][_0x5e011a]===_0xbfcb('0x75')){_0x19d04d[_0xbfcb('0x42')]('i.'+_0x5e011a+_0xbfcb('0x76'));}else{_0x19d04d['where']('i.'+_0x5e011a+_0xbfcb('0x77'),_0xda9f61['query'][_0x5e011a]);}}});}if(_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x78')]){if(_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x78')]==0x1){_0x19d04d[_0xbfcb('0x5d')]('`unreadMessages`\x20=\x200');}else{_0x19d04d[_0xbfcb('0x5d')](_0xbfcb('0x79'));}}if(_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x7a')]){_0x7afcba=_[_0xbfcb('0x7b')](_0xda9f61['query'][_0xbfcb('0x7a')])?_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x7a')]:new Array(_0xda9f61[_0xbfcb('0x39')]['tag']);_0x7afcba['forEach'](function(_0x467f17){_0x538c23['or'](_0xbfcb('0x66'),'%,'+_0x467f17+',%');});}if(_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x7c')]){var _0x3226e5=_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x7c')][_0xbfcb('0x7d')]('\x5c','\x5c\x5c')[_0xbfcb('0x7d')]('\x27\x27',_0xbfcb('0x7e'));if(qs[_0xbfcb('0x7f')](_0x3226e5)){_0x588d32['or'](_0xbfcb('0x80'),_0x3226e5+'%')['or'](_0xbfcb('0x81'),_0x3226e5+'%');}else{_0x588d32['or'](_0xbfcb('0x82'),qs['getFullTextValue'](_0x3226e5))['or'](_0xbfcb('0x83'),_0x3226e5+'%');}}}_0x19d04d['where'](_0x588d32);_0x19d04d[_0xbfcb('0x84')](_0xbfcb('0x85'));var _0x5209ea={'type':db[_0xbfcb('0x86')][_0xbfcb('0x87')][_0xbfcb('0x88')],'raw':!![]};var _0x26bb68=_0x19d04d['clone']();_0x26bb68[_0xbfcb('0x44')]('i.id');_0x26bb68[_0xbfcb('0x44')](_0xbfcb('0x89'),'unreadMessages');if(_0x505b0d['order']){_0x505b0d[_0xbfcb('0x8a')][_0xbfcb('0x34')](function(_0x233da5){_0x19d04d[_0xbfcb('0x8a')]('i.'+_0x233da5[0x0],_0x233da5[0x1]===_0xbfcb('0x8b')?![]:!![]);});}if(!_['isEmpty'](_0x7afcba)){_0x19d04d['having'](_0x538c23);_0x26bb68[_0xbfcb('0x42')]('t.id\x20IN\x20?',_0x7afcba);}BPromise['resolve']()[_0xbfcb('0x2a')](function(){if(!_0x5d942f){if(_0xda9f61[_0xbfcb('0x39')]['SmsAccountId']||_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x8c')])return;_0x26bb68['where'](_0xbfcb('0x8d'));_0x19d04d[_0xbfcb('0x42')](_0xbfcb('0x8d'));return;}return _0xda9f61[_0xbfcb('0x8e')]['getSmsAccounts']({'attributes':['id'],'raw':!![]})[_0xbfcb('0x2a')](function(_0x2546b1){if(_[_0xbfcb('0x6e')](_0x2546b1)){_0x26bb68[_0xbfcb('0x42')](_0xbfcb('0x8f'));_0x19d04d[_0xbfcb('0x42')]('i.SmsAccountId\x20IS\x20NULL');}else{_0x26bb68[_0xbfcb('0x42')](_0xbfcb('0x90'),_[_0xbfcb('0x30')](_0x2546b1,'id'));_0x19d04d[_0xbfcb('0x42')](_0xbfcb('0x90'),_[_0xbfcb('0x30')](_0x2546b1,'id'));}});})[_0xbfcb('0x2a')](function(){db[_0xbfcb('0x91')][_0xbfcb('0x39')](_0x26bb68[_0xbfcb('0x92')](),_0x5209ea)[_0xbfcb('0x2a')](function(_0x29d86f){_0x935af['count']=_0x29d86f['length'];if(_0x935af[_0xbfcb('0x22')]===0x0)return[];return db[_0xbfcb('0x91')][_0xbfcb('0x39')](_0x10ea4f[_0xbfcb('0x92')](),_0x5209ea)[_0xbfcb('0x2a')](function(_0x280260){_0x10ffa0=_[_0xbfcb('0x93')](_0x280260,'id');_0x5209ea=_[_0xbfcb('0x94')](_0x5209ea,{'model':db['SmsInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0xda9f61[_0xbfcb('0x39')][_0xbfcb('0x3e')]){_0x505b0d[_0xbfcb('0x3c')][_0xbfcb('0x34')](function(_0x9d27b5){_0x19d04d['field']('i.'+_0x9d27b5);});}else{_0x19d04d[_0xbfcb('0x44')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xbfcb('0x5a'));_0x19d04d[_0xbfcb('0x44')]('a.key','Account.key');_0x19d04d[_0xbfcb('0x44')](_0xbfcb('0x95'),_0xbfcb('0x96'));_0x19d04d[_0xbfcb('0x44')](_0xbfcb('0x97'));_0x19d04d[_0xbfcb('0x44')]('c.firstName',_0xbfcb('0x98'));_0x19d04d[_0xbfcb('0x44')](_0xbfcb('0x99'),_0xbfcb('0x9a'));_0x19d04d[_0xbfcb('0x44')](_0xbfcb('0x9b'),_0xbfcb('0x9c'));_0x19d04d[_0xbfcb('0x44')]('c.phone',_0xbfcb('0x9d'));_0x19d04d[_0xbfcb('0x44')]('c.mobile','Contact.mobile');_0x19d04d[_0xbfcb('0x44')]('c.fax','Contact.fax');_0x19d04d[_0xbfcb('0x44')]('o.fullname',_0xbfcb('0x9e'));_0x19d04d[_0xbfcb('0x44')](_0xbfcb('0x9f'),'Owner.internal');_0x19d04d[_0xbfcb('0x44')](_0xbfcb('0xa0'),_0xbfcb('0x32'));}_0x19d04d['limit'](_0x505b0d['limit']);_0x19d04d[_0xbfcb('0x23')](_0x505b0d[_0xbfcb('0x23')]);return db[_0xbfcb('0x91')]['query'](_0x19d04d[_0xbfcb('0x92')](),_0x5209ea);})['then'](function(_0x33b34a){_0x4f9521[_0xbfcb('0x42')]('ui.SmsInteractionId\x20IN\x20?',_[_0xbfcb('0x30')](_0x33b34a,'id'));return db[_0xbfcb('0x91')][_0xbfcb('0x39')](_0x4f9521['toString'](),_0x5209ea)[_0xbfcb('0x2a')](function(_0x57eb2d){var _0x437ccf=_[_0xbfcb('0xa1')](_0x57eb2d,_0xbfcb('0xa2'));var _0x34812d=[];_0x33b34a[_0xbfcb('0x34')](function(_0x4b1b69){_0x34812d[_0xbfcb('0x35')](updateSmsInteraction(_0x4b1b69,_0x10ffa0,_0x437ccf));});return BPromise[_0xbfcb('0xa3')](_0x34812d);});});})['then'](function(_0x2cb2af){_0x935af['rows']=_0x2cb2af;return _0x935af;})['then'](respondWithFilteredResult(_0x410948,_0x505b0d));})[_0xbfcb('0xa4')](handleError(_0x410948,null));};exports[_0xbfcb('0xa5')]=function(_0x5bba0b,_0x2ac498){var _0xdd9f4b={'raw':![],'where':{'id':_0x5bba0b[_0xbfcb('0xa6')]['id']}},_0x32f648={};_0x32f648[_0xbfcb('0x38')]=_['keys'](db[_0xbfcb('0x36')][_0xbfcb('0xa7')]);_0x32f648[_0xbfcb('0x39')]=_[_0xbfcb('0x3a')](_0x5bba0b[_0xbfcb('0x39')]);_0x32f648[_0xbfcb('0x3b')]=_[_0xbfcb('0x3d')](_0x32f648[_0xbfcb('0x38')],_0x32f648[_0xbfcb('0x39')]);_0xdd9f4b[_0xbfcb('0x3c')]=_[_0xbfcb('0x3d')](_0x32f648[_0xbfcb('0x38')],qs[_0xbfcb('0x3e')](_0x5bba0b['query'][_0xbfcb('0x3e')]));_0xdd9f4b[_0xbfcb('0x3c')]=_0xdd9f4b[_0xbfcb('0x3c')][_0xbfcb('0xa8')]?_0xdd9f4b[_0xbfcb('0x3c')]:_0x32f648[_0xbfcb('0x38')];if(_0x5bba0b[_0xbfcb('0x39')][_0xbfcb('0xa9')]){_0xdd9f4b[_0xbfcb('0xaa')]=[{'all':!![]}];}_0xdd9f4b=_['merge']({},_0xdd9f4b,_0x5bba0b['options']);return db[_0xbfcb('0x36')]['find'](_0xdd9f4b)[_0xbfcb('0x2a')](handleEntityNotFound(_0x2ac498,null))['then'](respondWithResult(_0x2ac498,null))['catch'](handleError(_0x2ac498,null));};exports[_0xbfcb('0xab')]=function(_0x4931a8,_0x74ecaa){return db['SmsInteraction'][_0xbfcb('0xab')](_0x4931a8[_0xbfcb('0x6c')],{})['then'](respondWithResult(_0x74ecaa,0xc9))[_0xbfcb('0xa4')](handleError(_0x74ecaa,null));};exports[_0xbfcb('0x29')]=function(_0x437b3d,_0x324927){if(_0x437b3d[_0xbfcb('0x6c')]['id']){delete _0x437b3d[_0xbfcb('0x6c')]['id'];}return db[_0xbfcb('0x36')][_0xbfcb('0x69')]({'where':{'id':_0x437b3d[_0xbfcb('0xa6')]['id']}})[_0xbfcb('0x2a')](handleEntityNotFound(_0x324927,null))[_0xbfcb('0x2a')](saveUpdates(_0x437b3d[_0xbfcb('0x6c')],null))[_0xbfcb('0x2a')](respondWithResult(_0x324927,null))[_0xbfcb('0xa4')](handleError(_0x324927,null));};exports[_0xbfcb('0x2b')]=function(_0x43dbc7,_0x2c3587){return db[_0xbfcb('0x36')]['find']({'where':{'id':_0x43dbc7[_0xbfcb('0xa6')]['id']}})['then'](handleEntityNotFound(_0x2c3587,null))[_0xbfcb('0x2a')](removeEntity(_0x2c3587,null))[_0xbfcb('0xa4')](handleError(_0x2c3587,null));};exports['describe']=function(_0x341cf,_0x21aa71){return db[_0xbfcb('0x36')][_0xbfcb('0xac')]()['then'](respondWithResult(_0x21aa71,null))[_0xbfcb('0xa4')](handleError(_0x21aa71,null));};exports[_0xbfcb('0xad')]=function(_0x4a1792,_0xcc1771,_0x46a30d){return db[_0xbfcb('0xae')][_0xbfcb('0x69')]({'where':{'id':_0x4a1792['params']['id']}})[_0xbfcb('0x2a')](handleEntityNotFound(_0xcc1771,null))['then'](function(_0x9e7a65){if(_0x9e7a65){return _0x9e7a65[_0xbfcb('0xad')](_0x4a1792['body'][_0xbfcb('0xaf')],_[_0xbfcb('0xb0')](_0x4a1792['body'],[_0xbfcb('0xaf'),'id'])||{});}})['then'](respondWithResult(_0xcc1771,null))['catch'](handleError(_0xcc1771,null));};exports[_0xbfcb('0xb1')]=function(_0x1624a6,_0x2033bd,_0x4cb67e){var _0x33b758={'raw':![],'where':{}};var _0x27f186={};var _0x22f558={'count':0x0,'rows':[]};return db[_0xbfcb('0x36')]['findOne']({'where':{'id':_0x1624a6['params']['id']}})[_0xbfcb('0x2a')](handleEntityNotFound(_0x2033bd,null))['then'](function(_0x3d52e6){if(_0x3d52e6){_0x27f186[_0xbfcb('0x38')]=_[_0xbfcb('0x3a')](db[_0xbfcb('0xae')]['rawAttributes']);_0x27f186[_0xbfcb('0x39')]=_['keys'](_0x1624a6[_0xbfcb('0x39')]);_0x27f186['filters']=_[_0xbfcb('0x3d')](_0x27f186['model'],_0x27f186[_0xbfcb('0x39')]);_0x33b758['attributes']=_[_0xbfcb('0x3d')](_0x27f186['model'],qs['fields'](_0x1624a6[_0xbfcb('0x39')][_0xbfcb('0x3e')]));_0x33b758['attributes']=_0x33b758[_0xbfcb('0x3c')][_0xbfcb('0xa8')]?_0x33b758[_0xbfcb('0x3c')]:_0x27f186[_0xbfcb('0x38')];if(!_0x1624a6[_0xbfcb('0x39')][_0xbfcb('0x3f')](_0xbfcb('0x40'))){_0x33b758[_0xbfcb('0x24')]=qs[_0xbfcb('0x24')](_0x1624a6[_0xbfcb('0x39')][_0xbfcb('0x24')]);_0x33b758[_0xbfcb('0x23')]=qs['offset'](_0x1624a6[_0xbfcb('0x39')]['offset']);}_0x33b758[_0xbfcb('0x8a')]=qs[_0xbfcb('0x41')](_0x1624a6[_0xbfcb('0x39')]['sort']);_0x33b758[_0xbfcb('0x42')]=qs[_0xbfcb('0x3b')](_['pick'](_0x1624a6['query'],_0x27f186['filters']));_0x33b758['where'][_0xbfcb('0xa2')]=_0x3d52e6['id'];if(_0x1624a6['query'][_0xbfcb('0x7c')]){_0x33b758[_0xbfcb('0x42')]=_[_0xbfcb('0x94')](_0x33b758[_0xbfcb('0x42')],{'$or':_[_0xbfcb('0x30')](_0x33b758[_0xbfcb('0x3c')],function(_0x216110){var _0x295f8d={};_0x295f8d[_0x216110]={'$like':'%'+_0x1624a6[_0xbfcb('0x39')][_0xbfcb('0x7c')]+'%'};return _0x295f8d;})});}if(_0x1624a6['query'][_0xbfcb('0x72')]){var _0x25d2ac=_0x1624a6['query'][_0xbfcb('0x72')][_0xbfcb('0xb2')](',');var _0x4610fc={};_0x4610fc[_0x25d2ac[0x0]]={'$gte':moment(_0x25d2ac[0x1])[_0xbfcb('0xb3')](_0xbfcb('0xb4'))};_0x33b758['where']=_[_0xbfcb('0x94')](_0x33b758[_0xbfcb('0x42')],_0x4610fc);}_0x33b758=_[_0xbfcb('0x94')]({},_0x33b758,_0x1624a6[_0xbfcb('0xb5')]);return db['SmsMessage'][_0xbfcb('0x22')]({'where':_0x33b758[_0xbfcb('0x42')]})['then'](function(_0x236080){_0x22f558[_0xbfcb('0x22')]=_0x236080;if(_0x1624a6[_0xbfcb('0x39')]['includeAll']){_0x33b758[_0xbfcb('0xaa')]=[{'all':!![]}];}return db[_0xbfcb('0xae')][_0xbfcb('0xb6')](_0x33b758);})[_0xbfcb('0x2a')](function(_0x33c20e){_0x22f558[_0xbfcb('0xb7')]=_0x33c20e;return _0x22f558;});}})[_0xbfcb('0x2a')](respondWithFilteredResult(_0x2033bd,_0x33b758))[_0xbfcb('0xa4')](handleError(_0x2033bd,null));};exports[_0xbfcb('0xb8')]=function(_0x1791a2,_0x2c5f6d,_0x103756){return db[_0xbfcb('0x36')][_0xbfcb('0x69')]({'where':{'id':_0x1791a2[_0xbfcb('0xa6')]['id']}})['then'](handleEntityNotFound(_0x2c5f6d,null))[_0xbfcb('0x2a')](function(_0x477d4e){if(_0x477d4e){return _0x477d4e[_0xbfcb('0xb9')](_0x1791a2[_0xbfcb('0x6c')]['ids'],_[_0xbfcb('0xb0')](_0x1791a2[_0xbfcb('0x6c')],[_0xbfcb('0xaf'),'id'])||{})['spread'](function(){return db[_0xbfcb('0x65')]['findAll']({'attributes':['id',_0xbfcb('0x2d'),_0xbfcb('0x45')],'where':{'id':_0x1791a2[_0xbfcb('0x6c')][_0xbfcb('0xaf')]}});})[_0xbfcb('0x2a')](function(_0x1197ca){socket[_0xbfcb('0xba')](_0xbfcb('0xbb'),{'id':Number(_0x1791a2[_0xbfcb('0xa6')]['id']),'tags':_0x1197ca||[]});return{'id':Number(_0x1791a2['params']['id']),'tags':_0x1197ca||[]};});}})[_0xbfcb('0x2a')](respondWithResult(_0x2c5f6d,null))[_0xbfcb('0xa4')](handleError(_0x2c5f6d,null));};exports[_0xbfcb('0xbc')]=function(_0xa6311b,_0x28094a,_0xea2e17){return db['SmsInteraction']['find']({'where':{'id':_0xa6311b[_0xbfcb('0xa6')]['id']}})[_0xbfcb('0x2a')](handleEntityNotFound(_0x28094a,null))[_0xbfcb('0x2a')](function(_0x1dcf8d){if(_0x1dcf8d){return _0x1dcf8d[_0xbfcb('0xbc')](_0xa6311b[_0xbfcb('0x39')][_0xbfcb('0xaf')]);}})[_0xbfcb('0x2a')](respondWithStatusCode(_0x28094a,null))['catch'](handleError(_0x28094a,null));};exports['download']=function(_0x3b86f5,_0xcf4f8c){var _0x17a4c9=moment()[_0xbfcb('0xbd')]()[_0xbfcb('0x92')]();var _0x3284c7=path[_0xbfcb('0xbe')](config[_0xbfcb('0xbf')],'server',_0xbfcb('0xc0'),_0xbfcb('0xc1'));var _0x495b04=path[_0xbfcb('0xbe')](config[_0xbfcb('0xbf')],_0xbfcb('0xc2'),_0xbfcb('0xc0'),_0xbfcb('0xc3'));var _0x31acb8=path['join'](_0x3284c7,_0x17a4c9);var _0x3ae443=util[_0xbfcb('0xb3')](_0xbfcb('0xc4'),_0x3b86f5[_0xbfcb('0xa6')]['id'],_0x17a4c9);var _0x36d5dd=path['join'](_0x3284c7,_0x3ae443);var _0x1ec8b8=[];_0x1ec8b8[_0xbfcb('0x35')]({'model':db[_0xbfcb('0xc5')],'as':_0xbfcb('0xc5'),'attributes':['id','fullname'],'raw':!![]});_0x1ec8b8[_0xbfcb('0x35')]({'model':db['CmContact'],'as':_0xbfcb('0xc6'),'attributes':['id',_0xbfcb('0xc7'),'lastName'],'raw':!![]});var _0x37f180=[{'model':db[_0xbfcb('0xae')],'as':'Messages','attributes':['id','body','createdAt','direction',_0xbfcb('0xc8'),_0xbfcb('0x78')],'include':_0x1ec8b8}];_0x37f180[_0xbfcb('0x35')]({'model':db[_0xbfcb('0xc9')],'as':_0xbfcb('0xca'),'attributes':['id','name']});_0x37f180[_0xbfcb('0x35')]({'model':db[_0xbfcb('0xc5')],'as':_0xbfcb('0xcb'),'attributes':['id',_0xbfcb('0x31')]});return db['SmsInteraction']['find']({'where':{'id':_0x3b86f5[_0xbfcb('0xa6')]['id']},'include':_0x37f180})[_0xbfcb('0x2a')](handleEntityNotFound(_0xcf4f8c,null))[_0xbfcb('0x2a')](function(_0x3033c0){if(_0x3033c0){var _0x3618c9=_0x3033c0[_0xbfcb('0xcc')]({'plain':!![]});fs[_0xbfcb('0xcd')](_0x31acb8);var _0x4c8f91={'format':'A4','border':_0xbfcb('0xce'),'header':{'height':_0xbfcb('0xcf'),'contents':{'first':_0xbfcb('0xd0')}},'footer':{'height':'30px','contents':{'default':util[_0xbfcb('0xb3')]('<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>',util[_0xbfcb('0xb3')]('%s\x20#%d','Sms',_0x3618c9['id']),moment()[_0xbfcb('0xb3')](_0xbfcb('0xd1'))[_0xbfcb('0x92')]())}}};var _0x3da815={'channel':_0xbfcb('0xd2'),'account':_0x3618c9['Account'][_0xbfcb('0x2d')],'agent':_0x3618c9[_0xbfcb('0xcb')]?_0x3618c9[_0xbfcb('0xcb')][_0xbfcb('0x31')]:_0xbfcb('0xd3'),'createdAt':moment(_0x3618c9['createdAt'])['format']('YYYY-MM-DD\x20HH:mm:ss')[_0xbfcb('0x92')](),'closedAt':_0x3618c9[_0xbfcb('0xd4')]?moment(_0x3618c9[_0xbfcb('0xd5')])[_0xbfcb('0xb3')]('YYYY-MM-DD\x20HH:mm:ss')[_0xbfcb('0x92')]():'','disposition':_0x3618c9[_0xbfcb('0xd6')],'messages':_(_0x3618c9['Messages'])[_0xbfcb('0x7c')]({'secret':![]})[_0xbfcb('0x30')](function(_0x11783d){return{'date':moment(_0x11783d['createdAt'])[_0xbfcb('0xb3')](_0xbfcb('0xb4'))[_0xbfcb('0x92')](),'sender':_0x11783d[_0xbfcb('0xd7')]===_0xbfcb('0xd8')?_0x11783d['User']?_0x11783d['User'][_0xbfcb('0x31')]:_0xbfcb('0xd9'):_0x11783d['Contact'][_0xbfcb('0xc7')]+(_0x11783d[_0xbfcb('0xc6')]['lastName']?'\x20'+_0x11783d[_0xbfcb('0xc6')]['lastName']:''),'body':_0x11783d[_0xbfcb('0x6c')],'direction':_0x11783d[_0xbfcb('0xd7')]===_0xbfcb('0xd8')?'A':'C','secret':_0x11783d[_0xbfcb('0xc8')],'read':_0x11783d[_0xbfcb('0x78')]};})['value']()};return ejs[_0xbfcb('0xda')](path['join'](config['root'],_0xbfcb('0xc2'),_0xbfcb('0xdb'),_0xbfcb('0xdc')),{'interaction':_0x3da815})[_0xbfcb('0x2a')](function(_0x267efd){return new BPromise(function(_0x5daa5d,_0x7715b8){pdf[_0xbfcb('0xab')](_0x267efd,_0x4c8f91)[_0xbfcb('0xdd')](path['join'](_0x31acb8,'transcript-'+_0x3618c9['id']+'-'+_0x17a4c9+'.pdf'),function(_0xe05a1,_0x3027b8){if(_0xe05a1)return _0x7715b8(_0xe05a1);_0x5daa5d(_0x3027b8);});});})['then'](function(){return new BPromise(function(_0x37c56c,_0x58b41e){zipdir(_0x31acb8,{'saveTo':_0x36d5dd},function(_0x493cfd,_0x3f1dea){if(_0x493cfd)return _0x58b41e(_0x493cfd);return _0x37c56c(_0x3f1dea);});})[_0xbfcb('0x2a')](function(){return new BPromise(function(_0x327039,_0x1e5aa0){rimraf(_0x31acb8,function(_0x28e7b4){if(_0x28e7b4)_0x1e5aa0(_0x28e7b4);return _0x327039();});});})[_0xbfcb('0x2a')](function(){return _0xcf4f8c[_0xbfcb('0xde')](_0x36d5dd,_0x3ae443,function(_0x39264d){if(_0x39264d){console['log'](_0xbfcb('0xdf'),_0x39264d);}else{fs[_0xbfcb('0xe0')](_0x36d5dd);}});});});}else{return _0xcf4f8c['sendStatus'](0xc8);}})[_0xbfcb('0xa4')](handleError(_0xcf4f8c,null));};
\ No newline at end of file
+var _0x5f5f=['nolimit','order','sort','where','pick','field','from','select','u.id','u.fullname','ui.SmsInteractionId','user_has_sms_interactions','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_messages','me.SmsInteractionId\x20=\x20i.id','sms_interaction_has_tags','it.SmsInteractionId\x20=\x20i.id','tools_tags','t.id\x20=\x20it.TagId','expr','search','parseSearch','conditions','find','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','split','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','text','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','some','compact','isEmpty','SmsAccountId','i.SmsAccountId\x20IN\x20?','concat','createdAt','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','`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)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','i.id','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','t.id\x20IN\x20?','i.SmsAccountId\x20IS\x20NOT\x20NULL','user','role','i.SmsAccountId\x20IS\x20NULL','agent','sequelize','toString','keyBy','merge','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','i.*','c.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.SmsInteractionId\x20IN\x20?','groupBy','all','rows','show','params','includeAll','options','catch','create','body','describe','addMessage','SmsMessage','ids','omit','getMessages','findOne','hasOwnProperty','include','findAll','setTags','Tag','color','emit','removeTags','download','unix','root','server','files','tmp','attachments','join','format','transcript-%d-%s.zip','User','fullname','CmContact','firstName','lastName','Messages','direction','secret','SmsAccount','Account','Owner','get','mkdirSync','10px','40px','<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>','30px','<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','YYYY-MM-DD\x20HH:mm:ss','System','out','renderFile','views','downloadInteraction.html','toFile','.pdf','log','err','unlinkSync','html-pdf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsInteraction.socket','status','end','json','count','offset','limit','set','Content-Range','apply','update','then','destroy','sendStatus','error','name','send','Tags','TagIds','forEach','push','index','map','SmsInteraction','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length'];(function(_0x1df9f4,_0x27c693){var _0x29f9c5=function(_0x264487){while(--_0x264487){_0x1df9f4['push'](_0x1df9f4['shift']());}};_0x29f9c5(++_0x27c693);}(_0x5f5f,0x1a9));var _0xf5f5=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x5f5f[_0x3dd15e];return _0x231fd0;};'use strict';var pdf=require(_0xf5f5('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xf5f5('0x1'));var jsonpatch=require(_0xf5f5('0x2'));var rp=require(_0xf5f5('0x3'));var moment=require(_0xf5f5('0x4'));var BPromise=require(_0xf5f5('0x5'));var Mustache=require('mustache');var util=require(_0xf5f5('0x6'));var path=require(_0xf5f5('0x7'));var sox=require('sox');var csv=require(_0xf5f5('0x8'));var ejs=require(_0xf5f5('0x9'));var fs=require('fs');var _=require(_0xf5f5('0xa'));var squel=require(_0xf5f5('0xb'));var crypto=require(_0xf5f5('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xf5f5('0xd'));var toCsv=require(_0xf5f5('0x8'));var querystring=require(_0xf5f5('0xe'));var Papa=require(_0xf5f5('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf5f5('0x10'));var logger=require(_0xf5f5('0x11'))(_0xf5f5('0x12'));var utils=require(_0xf5f5('0x13'));var config=require(_0xf5f5('0x14'));var licenseUtil=require(_0xf5f5('0x15'));var db=require(_0xf5f5('0x16'))['db'];config[_0xf5f5('0x17')]=_[_0xf5f5('0x18')](config[_0xf5f5('0x17')],{'host':_0xf5f5('0x19'),'port':0x18eb});var socket=require(_0xf5f5('0x1a'))(new Redis(config[_0xf5f5('0x17')]));require(_0xf5f5('0x1b'))['register'](socket);function respondWithStatusCode(_0x11db39,_0x17de8b){_0x17de8b=_0x17de8b||0xcc;return function(_0x1fcd49){if(_0x1fcd49){return _0x11db39['sendStatus'](_0x17de8b);}return _0x11db39[_0xf5f5('0x1c')](_0x17de8b)[_0xf5f5('0x1d')]();};}function respondWithResult(_0x16e075,_0xc79597){_0xc79597=_0xc79597||0xc8;return function(_0x1695d9){if(_0x1695d9){return _0x16e075['status'](_0xc79597)[_0xf5f5('0x1e')](_0x1695d9);}};}function respondWithFilteredResult(_0xfab25,_0x332332){return function(_0x1ccafd){if(_0x1ccafd){var _0x4384b2=_0x1ccafd[_0xf5f5('0x1f')],_0x82e9a8=_0x332332[_0xf5f5('0x20')],_0x1e4775=_0x332332['offset']+_0x332332[_0xf5f5('0x21')],_0x15a12f;if(_0x1e4775>=_0x4384b2){_0x1e4775=_0x4384b2;_0x15a12f=0xc8;}else{_0x15a12f=0xce;}_0xfab25[_0xf5f5('0x1c')](_0x15a12f);return _0xfab25[_0xf5f5('0x22')](_0xf5f5('0x23'),_0x82e9a8+'-'+_0x1e4775+'/'+_0x4384b2)[_0xf5f5('0x1e')](_0x1ccafd);}return null;};}function patchUpdates(_0x1f365c){return function(_0xba51b8){try{jsonpatch[_0xf5f5('0x24')](_0xba51b8,_0x1f365c,!![]);}catch(_0xb6f4ab){return BPromise['reject'](_0xb6f4ab);}return _0xba51b8['save']();};}function saveUpdates(_0x16bd78,_0x4956c6){return function(_0x38bf84){if(_0x38bf84){return _0x38bf84[_0xf5f5('0x25')](_0x16bd78)[_0xf5f5('0x26')](function(_0x53fc6c){return _0x53fc6c;});}return null;};}function removeEntity(_0x3440be,_0x3be3f7){return function(_0x16fe16){if(_0x16fe16){return _0x16fe16[_0xf5f5('0x27')]()[_0xf5f5('0x26')](function(){_0x3440be[_0xf5f5('0x1c')](0xcc)[_0xf5f5('0x1d')]();});}};}function handleEntityNotFound(_0x3787df,_0x586961){return function(_0xb9f31b){if(!_0xb9f31b){_0x3787df[_0xf5f5('0x28')](0x194);}return _0xb9f31b;};}function handleError(_0x519c16,_0xe97789){_0xe97789=_0xe97789||0x1f4;return function(_0x13c735){logger[_0xf5f5('0x29')](_0x13c735['stack']);if(_0x13c735[_0xf5f5('0x2a')]){delete _0x13c735[_0xf5f5('0x2a')];}_0x519c16['status'](_0xe97789)[_0xf5f5('0x2b')](_0x13c735);};}function getInteractionUsers(_0x325b3f,_0x2e1568){return new BPromise(function(_0x3a0e0f,_0x2b70a9){try{if(_0x2e1568[_0x325b3f['id']]){_0x325b3f['Users']=_['map'](_0x2e1568[_0x325b3f['id']],function(_0x34b74a){return{'id':_0x34b74a['id'],'fullname':_0x34b74a['fullname']};});}}catch(_0x506556){_0x2b70a9(_0x506556);}_0x3a0e0f(_0x325b3f);});}function getInteractionTags(_0x5bc99b,_0x46b720){return new BPromise(function(_0x579a70,_0x17e368){try{if(_0x5bc99b['TagIds']){_0x5bc99b[_0xf5f5('0x2c')]=[];_0x5bc99b[_0xf5f5('0x2d')]['split'](',')[_0xf5f5('0x2e')](function(_0x7f8fc2){_0x5bc99b[_0xf5f5('0x2c')][_0xf5f5('0x2f')](_0x46b720[_0x7f8fc2]);});}delete _0x5bc99b['TagIds'];}catch(_0x26e1d4){_0x17e368(_0x26e1d4);}_0x579a70(_0x5bc99b);});}function updateSmsInteraction(_0x238025,_0x5703a9,_0x56f0c4){return new BPromise(function(_0x125489,_0x26f488){return getInteractionUsers(_0x238025,_0x56f0c4)[_0xf5f5('0x26')](function(_0x3395e2){return getInteractionTags(_0x3395e2,_0x5703a9);})[_0xf5f5('0x26')](function(_0x33de90){_0x125489(_0x33de90);})['catch'](function(_0x20471e){_0x26f488(_0x20471e);});});}exports[_0xf5f5('0x30')]=function(_0x1645f1,_0x5c4682){var _0x4f00f7={},_0x5f0378={},_0x47ff86={'count':0x0,'rows':[]};var _0xd729e3=_[_0xf5f5('0x31')](db[_0xf5f5('0x32')][_0xf5f5('0x33')],function(_0x45166d){return{'name':_0x45166d[_0xf5f5('0x34')],'type':_0x45166d[_0xf5f5('0x35')][_0xf5f5('0x36')]};});_0x5f0378[_0xf5f5('0x37')]=_[_0xf5f5('0x31')](_0xd729e3,_0xf5f5('0x2a'));_0x5f0378[_0xf5f5('0x38')]=_[_0xf5f5('0x39')](_0x1645f1[_0xf5f5('0x38')]);_0x5f0378[_0xf5f5('0x3a')]=_['intersection'](_0x5f0378[_0xf5f5('0x37')],_0x5f0378[_0xf5f5('0x38')]);_0x4f00f7[_0xf5f5('0x3b')]=_[_0xf5f5('0x3c')](_0x5f0378[_0xf5f5('0x37')],qs['fields'](_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x3d')]));_0x4f00f7[_0xf5f5('0x3b')]=_0x4f00f7['attributes'][_0xf5f5('0x3e')]?_0x4f00f7[_0xf5f5('0x3b')]:_0x5f0378[_0xf5f5('0x37')];if(!_0x1645f1[_0xf5f5('0x38')]['hasOwnProperty'](_0xf5f5('0x3f'))){_0x4f00f7[_0xf5f5('0x21')]=qs[_0xf5f5('0x21')](_0x1645f1[_0xf5f5('0x38')]['limit']);_0x4f00f7[_0xf5f5('0x20')]=qs['offset'](_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x20')]);}_0x4f00f7[_0xf5f5('0x40')]=qs[_0xf5f5('0x41')](_0x1645f1[_0xf5f5('0x38')]['sort']);_0x4f00f7[_0xf5f5('0x42')]=qs['filters'](_[_0xf5f5('0x43')](_0x1645f1['query'],_0x5f0378[_0xf5f5('0x3a')]),_0xd729e3);var _0x1c59cf=[];var _0x4df02f=squel['select']()[_0xf5f5('0x44')]('id')[_0xf5f5('0x44')]('name')[_0xf5f5('0x44')]('color')[_0xf5f5('0x45')]('tools_tags');var _0x224bf5=squel[_0xf5f5('0x46')]()[_0xf5f5('0x44')](_0xf5f5('0x47'))[_0xf5f5('0x44')](_0xf5f5('0x48'))[_0xf5f5('0x44')](_0xf5f5('0x49'))['from'](_0xf5f5('0x4a'),'ui')[_0xf5f5('0x4b')](_0xf5f5('0x4c'),'u',_0xf5f5('0x4d'));var _0x4e27a1=squel[_0xf5f5('0x46')]()[_0xf5f5('0x45')](_0xf5f5('0x4e'),'i')[_0xf5f5('0x4b')]('cm_contacts','c',_0xf5f5('0x4f'))[_0xf5f5('0x4b')]('users','o',_0xf5f5('0x50'))['left_join'](_0xf5f5('0x51'),'a',_0xf5f5('0x52'))['left_join'](_0xf5f5('0x53'),'me',_0xf5f5('0x54'))[_0xf5f5('0x4b')](_0xf5f5('0x55'),'it',_0xf5f5('0x56'))[_0xf5f5('0x4b')](_0xf5f5('0x57'),'t',_0xf5f5('0x58'));var _0xe52fae=squel[_0xf5f5('0x59')]();var _0x2082c5=[];var _0x236411=squel[_0xf5f5('0x59')]();var _0x359b7e;if(_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x5a')]){_0x359b7e=as[_0xf5f5('0x5b')](_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x5a')]);var _0xc3d216=_0x359b7e['sqlOperator'];for(var _0x19bffc=0x0;_0x19bffc<_0x359b7e[_0xf5f5('0x5c')][_0xf5f5('0x3e')];_0x19bffc++){var _0x5dad2e=_0x359b7e[_0xf5f5('0x5c')][_0x19bffc];var _0x5aa6f9='i';var _0x5b71c2=_[_0xf5f5('0x5d')](_0xd729e3,[_0xf5f5('0x2a'),_0x5dad2e['field']]);if(!_0x5b71c2){switch(_0x5dad2e[_0xf5f5('0x44')]){case'unreadMessages':if(_0x5dad2e[_0xf5f5('0x5e')]==0x1){_0x4e27a1[_0xf5f5('0x5f')]('`'+_0x5dad2e[_0xf5f5('0x44')]+_0xf5f5('0x60'));}else{_0x4e27a1[_0xf5f5('0x5f')]('`'+_0x5dad2e[_0xf5f5('0x44')]+_0xf5f5('0x61'));}break;case _0xf5f5('0x62'):if(_0x5dad2e[_0xf5f5('0x63')]==='$substring'){if(_0x5dad2e['value'][_0xf5f5('0x64')]('\x20')[_0xf5f5('0x3e')]>0x1){_0xe52fae[_0xc3d216](_0xf5f5('0x65'),qs[_0xf5f5('0x66')](_0x5dad2e[_0xf5f5('0x5e')]),null);}else{var _0x5d1759='%'+_0x5dad2e[_0xf5f5('0x5e')]+'%';_0xe52fae[_0xc3d216](_0xf5f5('0x67'),_0x5d1759,_0x5d1759,_0x5d1759);}}else{_0x5b71c2=_[_0xf5f5('0x5d')](_0xd729e3,[_0xf5f5('0x2a'),'ContactId']);_0x5dad2e[_0xf5f5('0x44')]=_0xf5f5('0x68');_0x2e59b2=as['buildExpression'](_0x5aa6f9,_0x5b71c2[_0xf5f5('0x35')],_0x5dad2e);_0xe52fae[_0xc3d216](_0x2e59b2[_0xf5f5('0x69')],_0x2e59b2[_0xf5f5('0x5e')][_0xf5f5('0x6a')],_0x2e59b2['value']['end']);}break;case'Tag':var _0x2e0468=_0x5dad2e[_0xf5f5('0x5e')][_0xf5f5('0x64')](',')[_0xf5f5('0x31')](function(_0x47b4b8){return Number(_0x47b4b8);});_0x2e0468[_0xf5f5('0x2e')](function(_0x47a90a){_0x236411['or'](_0xf5f5('0x6b'),'%,'+_0x47a90a+',%');});_0x2082c5=_[_0xf5f5('0x6c')](_0x2082c5,_0x2e0468);break;case'User':if(_0x5dad2e[_0xf5f5('0x63')]===_0xf5f5('0x6d')){_0xe52fae[_0xc3d216](_0xf5f5('0x6e'),'%'+_0x5dad2e[_0xf5f5('0x5e')]+'%',null);}else{_0x5b71c2=_[_0xf5f5('0x5d')](_0xd729e3,[_0xf5f5('0x2a'),'UserId']);_0x5dad2e[_0xf5f5('0x44')]=_0xf5f5('0x6f');_0x2e59b2=as[_0xf5f5('0x70')](_0x5aa6f9,_0x5b71c2['type'],_0x5dad2e);_0xe52fae[_0xc3d216](_0x2e59b2[_0xf5f5('0x69')],_0x2e59b2[_0xf5f5('0x5e')]['start'],_0x2e59b2[_0xf5f5('0x5e')]['end']);}break;case'body':_0x2e59b2=as[_0xf5f5('0x70')]('me',null,_0x5dad2e);_0xe52fae[_0xc3d216](_0x2e59b2['text'],_0x2e59b2['value']['start'],_0x2e59b2[_0xf5f5('0x5e')][_0xf5f5('0x1d')]);break;}}else{var _0x2e59b2=as['buildExpression'](_0x5aa6f9,_0x5b71c2['type'],_0x5dad2e);_0xe52fae[_0xc3d216](_0x2e59b2[_0xf5f5('0x69')],_0x2e59b2[_0xf5f5('0x5e')][_0xf5f5('0x6a')],_0x2e59b2[_0xf5f5('0x5e')][_0xf5f5('0x1d')]);}}}else{var _0x166c7f=_(_0x1645f1['query'])[_0xf5f5('0x39')]()[_0xf5f5('0x31')](function(_0x1cc263){return _[_0xf5f5('0x71')](_0xd729e3,[_0xf5f5('0x2a'),_0x1cc263])?_0x1cc263:undefined;})[_0xf5f5('0x72')]()[_0xf5f5('0x5e')]();if(!_[_0xf5f5('0x73')](_0x166c7f)){_0x166c7f[_0xf5f5('0x2e')](function(_0x25bed){if(_0x25bed===_0xf5f5('0x74')){_0x4e27a1[_0xf5f5('0x42')](_0xf5f5('0x75'),[][_0xf5f5('0x76')](_0x1645f1['query'][_0x25bed]));}else if(_0x25bed===_0xf5f5('0x77')){var _0x2487c0=JSON['parse'](_0x1645f1[_0xf5f5('0x38')][_0x25bed])[_0xf5f5('0x78')];var _0x2e7565=JSON['parse'](_0x1645f1[_0xf5f5('0x38')][_0x25bed])[_0xf5f5('0x79')];_0x4e27a1['where'](_0xf5f5('0x7a'),_0x2487c0,_0x2e7565);}else{if(_0x1645f1['query'][_0x25bed]==='null'){_0x4e27a1['where']('i.'+_0x25bed+_0xf5f5('0x7b'));}else{_0x4e27a1[_0xf5f5('0x42')]('i.'+_0x25bed+'\x20=\x20?',_0x1645f1[_0xf5f5('0x38')][_0x25bed]);}}});}if(_0x1645f1[_0xf5f5('0x38')]['read']){if(_0x1645f1['query'][_0xf5f5('0x7c')]==0x1){_0x4e27a1[_0xf5f5('0x5f')](_0xf5f5('0x7d'));}else{_0x4e27a1[_0xf5f5('0x5f')](_0xf5f5('0x7e'));}}if(_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x7f')]){_0x2082c5=_[_0xf5f5('0x80')](_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x7f')])?_0x1645f1['query']['tag']:new Array(_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x7f')]);_0x2082c5[_0xf5f5('0x2e')](function(_0xdeceba){_0x236411['or'](_0xf5f5('0x6b'),'%,'+_0xdeceba+',%');});}if(_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x81')]){var _0x2b3909=_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x81')][_0xf5f5('0x82')]('\x5c','\x5c\x5c')[_0xf5f5('0x82')](/'/g,'\x27\x27');if(qs[_0xf5f5('0x83')](_0x2b3909)){_0xe52fae['or'](_0xf5f5('0x84'),_0x2b3909+'%')['or'](_0xf5f5('0x85'),_0x2b3909+'%');}else{_0xe52fae['or'](_0xf5f5('0x86'),qs[_0xf5f5('0x66')](_0x2b3909))['or'](_0xf5f5('0x87'),_0x2b3909+'%');}}}_0x4e27a1['where'](_0xe52fae);_0x4e27a1['group'](_0xf5f5('0x88'));var _0x413384={'type':db['Sequelize'][_0xf5f5('0x89')][_0xf5f5('0x8a')],'raw':!![]};var _0x188b1f=_0x4e27a1[_0xf5f5('0x8b')]();_0x188b1f[_0xf5f5('0x44')](_0xf5f5('0x88'));_0x188b1f['field'](_0xf5f5('0x8c'),'unreadMessages');if(_0x4f00f7[_0xf5f5('0x40')]){_0x4f00f7[_0xf5f5('0x40')][_0xf5f5('0x2e')](function(_0x191f1a){var _0x9e2ac8=_0x191f1a[0x0]===_0xf5f5('0x8d')?_0x191f1a[0x0]:'i.'+_0x191f1a[0x0];_0x4e27a1[_0xf5f5('0x40')](_0x9e2ac8,_0x191f1a[0x1]===_0xf5f5('0x8e')?![]:!![]);});}if(!_[_0xf5f5('0x73')](_0x2082c5)){_0x4e27a1[_0xf5f5('0x5f')](_0x236411);_0x188b1f['where'](_0xf5f5('0x8f'),_0x2082c5);}BPromise['resolve']()[_0xf5f5('0x26')](function(){if(!_0x359b7e){if(_0x1645f1['query'][_0xf5f5('0x74')])return;_0x188b1f['where'](_0xf5f5('0x90'));_0x4e27a1[_0xf5f5('0x42')](_0xf5f5('0x90'));return;}if(_0x1645f1[_0xf5f5('0x91')][_0xf5f5('0x92')]!=='agent')return;return _0x1645f1['user']['getSmsAccounts']({'attributes':['id'],'raw':!![]})['then'](function(_0x5d3967){if(_[_0xf5f5('0x73')](_0x5d3967)){_0x188b1f[_0xf5f5('0x42')](_0xf5f5('0x93'));_0x4e27a1[_0xf5f5('0x42')](_0xf5f5('0x93'));}else{_0x188b1f['where'](_0xf5f5('0x75'),_['map'](_0x5d3967,'id'));_0x4e27a1['where'](_0xf5f5('0x75'),_[_0xf5f5('0x31')](_0x5d3967,'id'));}});})[_0xf5f5('0x26')](function(){if(_0x1645f1[_0xf5f5('0x91')]['role']===_0xf5f5('0x94')&&!_0x359b7e&&!_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x74')])return[];return db[_0xf5f5('0x95')][_0xf5f5('0x38')](_0x188b1f[_0xf5f5('0x96')](),_0x413384);})[_0xf5f5('0x26')](function(_0xeebec8){_0x47ff86[_0xf5f5('0x1f')]=_0xeebec8[_0xf5f5('0x3e')];if(_0x47ff86[_0xf5f5('0x1f')]===0x0)return[];return db['sequelize'][_0xf5f5('0x38')](_0x4df02f[_0xf5f5('0x96')](),_0x413384)[_0xf5f5('0x26')](function(_0x571e4e){_0x1c59cf=_[_0xf5f5('0x97')](_0x571e4e,'id');_0x413384=_[_0xf5f5('0x98')](_0x413384,{'model':db[_0xf5f5('0x32')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1645f1[_0xf5f5('0x38')][_0xf5f5('0x3d')]){_0x4f00f7[_0xf5f5('0x3b')][_0xf5f5('0x2e')](function(_0xa63872){_0x4e27a1[_0xf5f5('0x44')]('i.'+_0xa63872);});}else{_0x4e27a1[_0xf5f5('0x44')](_0xf5f5('0x8c'),'unreadMessages');_0x4e27a1['field'](_0xf5f5('0x99'),_0xf5f5('0x9a'));_0x4e27a1[_0xf5f5('0x44')](_0xf5f5('0x9b'),_0xf5f5('0x9c'));_0x4e27a1['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',_0xf5f5('0x8d'));_0x4e27a1[_0xf5f5('0x44')](_0xf5f5('0x9d'));_0x4e27a1['field'](_0xf5f5('0x9e'),'Contact.firstName');_0x4e27a1[_0xf5f5('0x44')](_0xf5f5('0x9f'),_0xf5f5('0xa0'));_0x4e27a1['field'](_0xf5f5('0xa1'),_0xf5f5('0xa2'));_0x4e27a1[_0xf5f5('0x44')](_0xf5f5('0xa3'),'Contact.phone');_0x4e27a1[_0xf5f5('0x44')](_0xf5f5('0xa4'),_0xf5f5('0xa5'));_0x4e27a1[_0xf5f5('0x44')](_0xf5f5('0xa6'),_0xf5f5('0xa7'));_0x4e27a1[_0xf5f5('0x44')]('o.fullname',_0xf5f5('0xa8'));_0x4e27a1['field'](_0xf5f5('0xa9'),_0xf5f5('0xaa'));_0x4e27a1[_0xf5f5('0x44')](_0xf5f5('0xab'),_0xf5f5('0x2d'));}if(_0x4f00f7['limit'])_0x4e27a1[_0xf5f5('0x21')](_0x4f00f7['limit']);if(_0x4f00f7[_0xf5f5('0x20')])_0x4e27a1[_0xf5f5('0x20')](_0x4f00f7['offset']);return db['sequelize']['query'](_0x4e27a1['toString'](),_0x413384);})[_0xf5f5('0x26')](function(_0x338c09){_0x224bf5['where'](_0xf5f5('0xac'),_[_0xf5f5('0x31')](_0x338c09,'id'));return db[_0xf5f5('0x95')]['query'](_0x224bf5[_0xf5f5('0x96')](),_0x413384)[_0xf5f5('0x26')](function(_0x131281){var _0x32b4e3=_[_0xf5f5('0xad')](_0x131281,'SmsInteractionId');var _0x5e0042=[];_0x338c09[_0xf5f5('0x2e')](function(_0x1f8e79){_0x5e0042[_0xf5f5('0x2f')](updateSmsInteraction(_0x1f8e79,_0x1c59cf,_0x32b4e3));});return BPromise[_0xf5f5('0xae')](_0x5e0042);});});})[_0xf5f5('0x26')](function(_0x1be565){_0x47ff86[_0xf5f5('0xaf')]=_0x1be565;return _0x47ff86;})[_0xf5f5('0x26')](respondWithFilteredResult(_0x5c4682,_0x4f00f7))['catch'](handleError(_0x5c4682,null));};exports[_0xf5f5('0xb0')]=function(_0x3bcaf4,_0x18b987){var _0x3c4525={'raw':![],'where':{'id':_0x3bcaf4[_0xf5f5('0xb1')]['id']}},_0x577191={};_0x577191[_0xf5f5('0x37')]=_[_0xf5f5('0x39')](db[_0xf5f5('0x32')][_0xf5f5('0x33')]);_0x577191['query']=_[_0xf5f5('0x39')](_0x3bcaf4[_0xf5f5('0x38')]);_0x577191['filters']=_[_0xf5f5('0x3c')](_0x577191[_0xf5f5('0x37')],_0x577191[_0xf5f5('0x38')]);_0x3c4525['attributes']=_[_0xf5f5('0x3c')](_0x577191[_0xf5f5('0x37')],qs[_0xf5f5('0x3d')](_0x3bcaf4['query'][_0xf5f5('0x3d')]));_0x3c4525[_0xf5f5('0x3b')]=_0x3c4525['attributes'][_0xf5f5('0x3e')]?_0x3c4525['attributes']:_0x577191[_0xf5f5('0x37')];if(_0x3bcaf4[_0xf5f5('0x38')][_0xf5f5('0xb2')]){_0x3c4525['include']=[{'all':!![]}];}_0x3c4525=_[_0xf5f5('0x98')]({},_0x3c4525,_0x3bcaf4[_0xf5f5('0xb3')]);return db[_0xf5f5('0x32')]['find'](_0x3c4525)[_0xf5f5('0x26')](handleEntityNotFound(_0x18b987,null))[_0xf5f5('0x26')](respondWithResult(_0x18b987,null))[_0xf5f5('0xb4')](handleError(_0x18b987,null));};exports[_0xf5f5('0xb5')]=function(_0x1cf4bd,_0x57a9b5){return db[_0xf5f5('0x32')][_0xf5f5('0xb5')](_0x1cf4bd['body'],{})[_0xf5f5('0x26')](respondWithResult(_0x57a9b5,0xc9))['catch'](handleError(_0x57a9b5,null));};exports['update']=function(_0x28de99,_0x99473a){if(_0x28de99[_0xf5f5('0xb6')]['id']){delete _0x28de99[_0xf5f5('0xb6')]['id'];}return db[_0xf5f5('0x32')][_0xf5f5('0x5d')]({'where':{'id':_0x28de99[_0xf5f5('0xb1')]['id']}})[_0xf5f5('0x26')](handleEntityNotFound(_0x99473a,null))[_0xf5f5('0x26')](saveUpdates(_0x28de99[_0xf5f5('0xb6')],null))['then'](respondWithResult(_0x99473a,null))[_0xf5f5('0xb4')](handleError(_0x99473a,null));};exports['destroy']=function(_0x1b5a1e,_0x4d117c){return db[_0xf5f5('0x32')]['find']({'where':{'id':_0x1b5a1e[_0xf5f5('0xb1')]['id']}})[_0xf5f5('0x26')](handleEntityNotFound(_0x4d117c,null))['then'](removeEntity(_0x4d117c,null))[_0xf5f5('0xb4')](handleError(_0x4d117c,null));};exports[_0xf5f5('0xb7')]=function(_0x490423,_0x46edde){return db['SmsInteraction'][_0xf5f5('0xb7')]()[_0xf5f5('0x26')](respondWithResult(_0x46edde,null))[_0xf5f5('0xb4')](handleError(_0x46edde,null));};exports[_0xf5f5('0xb8')]=function(_0x2efde5,_0x5ef0b0,_0x37d26f){return db[_0xf5f5('0xb9')][_0xf5f5('0x5d')]({'where':{'id':_0x2efde5[_0xf5f5('0xb1')]['id']}})[_0xf5f5('0x26')](handleEntityNotFound(_0x5ef0b0,null))[_0xf5f5('0x26')](function(_0x56cf77){if(_0x56cf77){return _0x56cf77[_0xf5f5('0xb8')](_0x2efde5[_0xf5f5('0xb6')][_0xf5f5('0xba')],_[_0xf5f5('0xbb')](_0x2efde5[_0xf5f5('0xb6')],[_0xf5f5('0xba'),'id'])||{});}})[_0xf5f5('0x26')](respondWithResult(_0x5ef0b0,null))[_0xf5f5('0xb4')](handleError(_0x5ef0b0,null));};exports[_0xf5f5('0xbc')]=function(_0x1a7817,_0x471933,_0x541d1f){var _0x2f5715={'raw':![],'where':{}};var _0x10118f={};var _0x5edc2f={'count':0x0,'rows':[]};return db[_0xf5f5('0x32')][_0xf5f5('0xbd')]({'where':{'id':_0x1a7817['params']['id']}})[_0xf5f5('0x26')](handleEntityNotFound(_0x471933,null))[_0xf5f5('0x26')](function(_0x267495){if(_0x267495){_0x10118f[_0xf5f5('0x37')]=_[_0xf5f5('0x39')](db['SmsMessage']['rawAttributes']);_0x10118f[_0xf5f5('0x38')]=_['keys'](_0x1a7817[_0xf5f5('0x38')]);_0x10118f['filters']=_[_0xf5f5('0x3c')](_0x10118f[_0xf5f5('0x37')],_0x10118f[_0xf5f5('0x38')]);_0x2f5715['attributes']=_[_0xf5f5('0x3c')](_0x10118f[_0xf5f5('0x37')],qs[_0xf5f5('0x3d')](_0x1a7817['query'][_0xf5f5('0x3d')]));_0x2f5715[_0xf5f5('0x3b')]=_0x2f5715['attributes'][_0xf5f5('0x3e')]?_0x2f5715['attributes']:_0x10118f['model'];if(!_0x1a7817[_0xf5f5('0x38')][_0xf5f5('0xbe')]('nolimit')){_0x2f5715['limit']=qs[_0xf5f5('0x21')](_0x1a7817[_0xf5f5('0x38')][_0xf5f5('0x21')]);_0x2f5715[_0xf5f5('0x20')]=qs[_0xf5f5('0x20')](_0x1a7817[_0xf5f5('0x38')][_0xf5f5('0x20')]);}_0x2f5715[_0xf5f5('0x40')]=qs[_0xf5f5('0x41')](_0x1a7817['query']['sort']);_0x2f5715[_0xf5f5('0x42')]=qs['filters'](_[_0xf5f5('0x43')](_0x1a7817[_0xf5f5('0x38')],_0x10118f[_0xf5f5('0x3a')]));_0x2f5715[_0xf5f5('0x42')]['SmsInteractionId']=_0x267495['id'];if(_0x1a7817['query'][_0xf5f5('0x81')]){_0x2f5715[_0xf5f5('0x42')]=_[_0xf5f5('0x98')](_0x2f5715[_0xf5f5('0x42')],{'$or':_[_0xf5f5('0x31')](_0x2f5715['attributes'],function(_0x50bd2a){var _0x4d545d={};_0x4d545d[_0x50bd2a]={'$like':'%'+_0x1a7817['query']['filter']+'%'};return _0x4d545d;})});}if(_0x1a7817['query']['$gte']){var _0x4711c9=_0x1a7817[_0xf5f5('0x38')][_0xf5f5('0x78')][_0xf5f5('0x64')](',');var _0x163ee7={};_0x163ee7[_0x4711c9[0x0]]={'$gte':moment(_0x4711c9[0x1])['format']('YYYY-MM-DD\x20HH:mm:ss')};_0x2f5715[_0xf5f5('0x42')]=_[_0xf5f5('0x98')](_0x2f5715['where'],_0x163ee7);}_0x2f5715=_[_0xf5f5('0x98')]({},_0x2f5715,_0x1a7817[_0xf5f5('0xb3')]);return db[_0xf5f5('0xb9')][_0xf5f5('0x1f')]({'where':_0x2f5715['where']})[_0xf5f5('0x26')](function(_0x3242f4){_0x5edc2f[_0xf5f5('0x1f')]=_0x3242f4;if(_0x1a7817[_0xf5f5('0x38')][_0xf5f5('0xb2')]){_0x2f5715[_0xf5f5('0xbf')]=[{'all':!![]}];}return db['SmsMessage'][_0xf5f5('0xc0')](_0x2f5715);})[_0xf5f5('0x26')](function(_0x113d16){_0x5edc2f[_0xf5f5('0xaf')]=_0x113d16;return _0x5edc2f;});}})['then'](respondWithFilteredResult(_0x471933,_0x2f5715))['catch'](handleError(_0x471933,null));};exports['addTags']=function(_0x2fb030,_0x27a8c1,_0x418da3){return db[_0xf5f5('0x32')][_0xf5f5('0x5d')]({'where':{'id':_0x2fb030[_0xf5f5('0xb1')]['id']}})[_0xf5f5('0x26')](handleEntityNotFound(_0x27a8c1,null))['then'](function(_0x590bbb){if(_0x590bbb){return _0x590bbb[_0xf5f5('0xc1')](_0x2fb030[_0xf5f5('0xb6')]['ids'],_['omit'](_0x2fb030[_0xf5f5('0xb6')],['ids','id'])||{})['spread'](function(){return db[_0xf5f5('0xc2')][_0xf5f5('0xc0')]({'attributes':['id',_0xf5f5('0x2a'),_0xf5f5('0xc3')],'where':{'id':_0x2fb030[_0xf5f5('0xb6')]['ids']}});})[_0xf5f5('0x26')](function(_0x26e389){socket[_0xf5f5('0xc4')]('smsInteractionTags:save',{'id':Number(_0x2fb030[_0xf5f5('0xb1')]['id']),'tags':_0x26e389||[]});return{'id':Number(_0x2fb030['params']['id']),'tags':_0x26e389||[]};});}})[_0xf5f5('0x26')](respondWithResult(_0x27a8c1,null))['catch'](handleError(_0x27a8c1,null));};exports['removeTags']=function(_0x4e9d32,_0x251383,_0x521622){return db[_0xf5f5('0x32')][_0xf5f5('0x5d')]({'where':{'id':_0x4e9d32[_0xf5f5('0xb1')]['id']}})[_0xf5f5('0x26')](handleEntityNotFound(_0x251383,null))[_0xf5f5('0x26')](function(_0x451857){if(_0x451857){return _0x451857[_0xf5f5('0xc5')](_0x4e9d32[_0xf5f5('0x38')][_0xf5f5('0xba')]);}})[_0xf5f5('0x26')](respondWithStatusCode(_0x251383,null))['catch'](handleError(_0x251383,null));};exports[_0xf5f5('0xc6')]=function(_0x141b1a,_0x23a86e){var _0x175930=moment()[_0xf5f5('0xc7')]()[_0xf5f5('0x96')]();var _0x5debc0=path['join'](config[_0xf5f5('0xc8')],_0xf5f5('0xc9'),_0xf5f5('0xca'),_0xf5f5('0xcb'));var _0x23bf17=path['join'](config[_0xf5f5('0xc8')],_0xf5f5('0xc9'),_0xf5f5('0xca'),_0xf5f5('0xcc'));var _0x94282a=path[_0xf5f5('0xcd')](_0x5debc0,_0x175930);var _0x2040a8=util[_0xf5f5('0xce')](_0xf5f5('0xcf'),_0x141b1a[_0xf5f5('0xb1')]['id'],_0x175930);var _0x8fe5c1=path[_0xf5f5('0xcd')](_0x5debc0,_0x2040a8);var _0x2acac9=[];_0x2acac9[_0xf5f5('0x2f')]({'model':db[_0xf5f5('0xd0')],'as':_0xf5f5('0xd0'),'attributes':['id',_0xf5f5('0xd1')],'raw':!![]});_0x2acac9[_0xf5f5('0x2f')]({'model':db[_0xf5f5('0xd2')],'as':'Contact','attributes':['id',_0xf5f5('0xd3'),_0xf5f5('0xd4')],'raw':!![]});var _0x56a301=[{'model':db[_0xf5f5('0xb9')],'as':_0xf5f5('0xd5'),'attributes':['id',_0xf5f5('0xb6'),_0xf5f5('0x77'),_0xf5f5('0xd6'),_0xf5f5('0xd7'),'read'],'include':_0x2acac9}];_0x56a301[_0xf5f5('0x2f')]({'model':db[_0xf5f5('0xd8')],'as':_0xf5f5('0xd9'),'attributes':['id',_0xf5f5('0x2a')]});_0x56a301[_0xf5f5('0x2f')]({'model':db[_0xf5f5('0xd0')],'as':_0xf5f5('0xda'),'attributes':['id',_0xf5f5('0xd1')]});return db['SmsInteraction'][_0xf5f5('0x5d')]({'where':{'id':_0x141b1a[_0xf5f5('0xb1')]['id']},'include':_0x56a301})['then'](handleEntityNotFound(_0x23a86e,null))[_0xf5f5('0x26')](function(_0x116528){if(_0x116528){var _0x5a9728=_0x116528[_0xf5f5('0xdb')]({'plain':!![]});fs[_0xf5f5('0xdc')](_0x94282a);var _0xc3520c={'format':'A4','border':_0xf5f5('0xdd'),'header':{'height':_0xf5f5('0xde'),'contents':{'first':_0xf5f5('0xdf')}},'footer':{'height':_0xf5f5('0xe0'),'contents':{'default':util[_0xf5f5('0xce')](_0xf5f5('0xe1'),util[_0xf5f5('0xce')](_0xf5f5('0xe2'),_0xf5f5('0xe3'),_0x5a9728['id']),moment()[_0xf5f5('0xce')](_0xf5f5('0xe4'))[_0xf5f5('0x96')]())}}};var _0xdacb30={'channel':_0xf5f5('0xe3'),'account':_0x5a9728[_0xf5f5('0xd9')]['name'],'agent':_0x5a9728[_0xf5f5('0xda')]?_0x5a9728[_0xf5f5('0xda')][_0xf5f5('0xd1')]:_0xf5f5('0xe5'),'createdAt':moment(_0x5a9728[_0xf5f5('0x77')])['format']('YYYY-MM-DD\x20HH:mm:ss')[_0xf5f5('0x96')](),'closedAt':_0x5a9728[_0xf5f5('0xe6')]?moment(_0x5a9728[_0xf5f5('0xe7')])[_0xf5f5('0xce')]('YYYY-MM-DD\x20HH:mm:ss')[_0xf5f5('0x96')]():'','disposition':_0x5a9728[_0xf5f5('0xe8')],'messages':_(_0x5a9728[_0xf5f5('0xd5')])['filter']({'secret':![]})['map'](function(_0x7b7749){return{'date':moment(_0x7b7749[_0xf5f5('0x77')])['format'](_0xf5f5('0xe9'))[_0xf5f5('0x96')](),'sender':_0x7b7749['direction']==='out'?_0x7b7749[_0xf5f5('0xd0')]?_0x7b7749['User']['fullname']:_0xf5f5('0xea'):_0x7b7749[_0xf5f5('0x62')][_0xf5f5('0xd3')]+(_0x7b7749['Contact'][_0xf5f5('0xd4')]?'\x20'+_0x7b7749[_0xf5f5('0x62')][_0xf5f5('0xd4')]:''),'body':_0x7b7749[_0xf5f5('0xb6')],'direction':_0x7b7749[_0xf5f5('0xd6')]===_0xf5f5('0xeb')?'A':'C','secret':_0x7b7749[_0xf5f5('0xd7')],'read':_0x7b7749[_0xf5f5('0x7c')]};})['value']()};return ejs[_0xf5f5('0xec')](path[_0xf5f5('0xcd')](config[_0xf5f5('0xc8')],'server',_0xf5f5('0xed'),_0xf5f5('0xee')),{'interaction':_0xdacb30})[_0xf5f5('0x26')](function(_0x13f0b5){return new BPromise(function(_0x356a1f,_0x21877b){pdf[_0xf5f5('0xb5')](_0x13f0b5,_0xc3520c)[_0xf5f5('0xef')](path['join'](_0x94282a,'transcript-'+_0x5a9728['id']+'-'+_0x175930+_0xf5f5('0xf0')),function(_0x515a39,_0x58b824){if(_0x515a39)return _0x21877b(_0x515a39);_0x356a1f(_0x58b824);});});})[_0xf5f5('0x26')](function(){return new BPromise(function(_0x53f97a,_0x4a3833){zipdir(_0x94282a,{'saveTo':_0x8fe5c1},function(_0x5601ac,_0xa6496d){if(_0x5601ac)return _0x4a3833(_0x5601ac);return _0x53f97a(_0xa6496d);});})[_0xf5f5('0x26')](function(){return new BPromise(function(_0x16ca34,_0x44fe49){rimraf(_0x94282a,function(_0x2a9818){if(_0x2a9818)_0x44fe49(_0x2a9818);return _0x16ca34();});});})['then'](function(){return _0x23a86e[_0xf5f5('0xc6')](_0x8fe5c1,_0x2040a8,function(_0x2e6a24){if(_0x2e6a24){console[_0xf5f5('0xf1')](_0xf5f5('0xf2'),_0x2e6a24);}else{fs[_0xf5f5('0xf3')](_0x8fe5c1);}});});});}else{return _0x23a86e[_0xf5f5('0x28')](0xc8);}})[_0xf5f5('0xb4')](handleError(_0x23a86e,null));};
\ No newline at end of file