Built motion from commit fe909640.|2.6.8
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 282a874..2a3ad41 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x60fc=['i.SmsAccountId\x20IN\x20?','role','sequelize','toString','keyBy','merge','a.key','Account.key','i.*','Contact.firstName','c.lastName','Contact.lastName','c.email','c.phone','c.mobile','Contact.mobile','o.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.SmsInteractionId\x20IN\x20?','all','rows','rawAttributes','includeAll','include','options','create','params','describe','SmsMessage','omit','ids','getMessages','findOne','hasOwnProperty','SmsInteractionId','format','YYYY-MM-DD\x20HH:mm:ss','addTags','setTags','spread','findAll','emit','removeTags','download','unix','join','root','server','tmp','attachments','CmContact','lastName','Messages','direction','secret','SmsAccount','Account','Owner','get','mkdirSync','firstName','views','Sms','createPdfFromHTML','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','to-csv','ejs','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','localhost','./smsInteraction.socket','register','sendStatus','json','offset','undefined','limit','count','status','set','apply','reject','save','update','then','destroy','end','error','name','send','Users','map','fullname','Tags','split','forEach','push','TagIds','catch','waiting','answered','unmanaged','total','closed','UserId','talking','SmsInteraction','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','select','field','color','from','tools_tags','u.fullname','ui.SmsInteractionId','left_join','users','u.id\x20=\x20ui.UserId','sms_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','sms_accounts','sms_messages','me.SmsInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','conditions','find','unreadMessages','value','having','`\x20>\x200','Contact','operator','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','ContactId','text','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','buildExpression','start','body','type','some','compact','isEmpty','SmsAccountId','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','tag','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?','group','i.id','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','t.id\x20IN\x20?','resolve','i.SmsAccountId\x20IS\x20NOT\x20NULL','agent','user','i.SmsAccountId\x20IS\x20NULL'];(function(_0x1049b7,_0xc4573b){var _0x3763a4=function(_0x2620e1){while(--_0x2620e1){_0x1049b7['push'](_0x1049b7['shift']());}};_0x3763a4(++_0xc4573b);}(_0x60fc,0x128));var _0xc60f=function(_0x3bec1f,_0x135f71){_0x3bec1f=_0x3bec1f-0x0;var _0x332192=_0x60fc[_0x3bec1f];return _0x332192;};'use strict';var emlformat=require(_0xc60f('0x0'));var rimraf=require(_0xc60f('0x1'));var zipdir=require(_0xc60f('0x2'));var jsonpatch=require(_0xc60f('0x3'));var rp=require('request-promise');var moment=require(_0xc60f('0x4'));var BPromise=require(_0xc60f('0x5'));var Mustache=require(_0xc60f('0x6'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0xc60f('0x7'));var ejs=require(_0xc60f('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xc60f('0x9'));var deskjs=require(_0xc60f('0xa'));var toCsv=require(_0xc60f('0x7'));var querystring=require(_0xc60f('0xb'));var Papa=require(_0xc60f('0xc'));var Redis=require(_0xc60f('0xd'));var authService=require(_0xc60f('0xe'));var qs=require(_0xc60f('0xf'));var as=require(_0xc60f('0x10'));var pdf=require('../../components/export/pdf');var hardwareService=require(_0xc60f('0x11'));var logger=require(_0xc60f('0x12'))(_0xc60f('0x13'));var utils=require(_0xc60f('0x14'));var config=require(_0xc60f('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0xc60f('0x16'))['db'];config[_0xc60f('0x17')]=_['defaults'](config[_0xc60f('0x17')],{'host':_0xc60f('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xc60f('0x17')]));require(_0xc60f('0x19'))[_0xc60f('0x1a')](socket);function respondWithStatusCode(_0x244e15,_0x594361){_0x594361=_0x594361||0xcc;return function(_0x4f3b3e){if(_0x4f3b3e){return _0x244e15[_0xc60f('0x1b')](_0x594361);}return _0x244e15['status'](_0x594361)['end']();};}function respondWithResult(_0x29acc6,_0x466d65){_0x466d65=_0x466d65||0xc8;return function(_0x3c26bf){if(_0x3c26bf){return _0x29acc6['status'](_0x466d65)[_0xc60f('0x1c')](_0x3c26bf);}};}function respondWithFilteredResult(_0x5b2b89,_0x56be40){return function(_0x1eb196){if(_0x1eb196){var _0x158927=typeof _0x56be40[_0xc60f('0x1d')]===_0xc60f('0x1e')&&typeof _0x56be40[_0xc60f('0x1f')]===_0xc60f('0x1e');var _0xfabbc3=_0x1eb196['count'];var _0x55ffb2=_0x158927?0x0:_0x56be40[_0xc60f('0x1d')];var _0x2c0d60=_0x158927?_0x1eb196[_0xc60f('0x20')]:_0x56be40[_0xc60f('0x1d')]+_0x56be40['limit'];var _0x90951d;if(_0x2c0d60>=_0xfabbc3){_0x2c0d60=_0xfabbc3;_0x90951d=0xc8;}else{_0x90951d=0xce;}_0x5b2b89[_0xc60f('0x21')](_0x90951d);return _0x5b2b89[_0xc60f('0x22')]('Content-Range',_0x55ffb2+'-'+_0x2c0d60+'/'+_0xfabbc3)['json'](_0x1eb196);}return null;};}function patchUpdates(_0x19683f){return function(_0x1d937b){try{jsonpatch[_0xc60f('0x23')](_0x1d937b,_0x19683f,!![]);}catch(_0x3b892e){return BPromise[_0xc60f('0x24')](_0x3b892e);}return _0x1d937b[_0xc60f('0x25')]();};}function saveUpdates(_0x246641,_0x3d9f6c){return function(_0x2eab69){if(_0x2eab69){return _0x2eab69[_0xc60f('0x26')](_0x246641)[_0xc60f('0x27')](function(_0x585345){return _0x585345;});}return null;};}function removeEntity(_0x3d7bac,_0x5802a1){return function(_0x3ef226){if(_0x3ef226){return _0x3ef226[_0xc60f('0x28')]()['then'](function(){_0x3d7bac[_0xc60f('0x21')](0xcc)[_0xc60f('0x29')]();});}};}function handleEntityNotFound(_0x18c8fa,_0x3e9575){return function(_0x18a72a){if(!_0x18a72a){_0x18c8fa[_0xc60f('0x1b')](0x194);}return _0x18a72a;};}function handleError(_0x10fa31,_0x46bae2){_0x46bae2=_0x46bae2||0x1f4;return function(_0x124d58){logger[_0xc60f('0x2a')](_0x124d58['stack']);if(_0x124d58['name']){delete _0x124d58[_0xc60f('0x2b')];}_0x10fa31[_0xc60f('0x21')](_0x46bae2)[_0xc60f('0x2c')](_0x124d58);};}function getInteractionUsers(_0x3d9467,_0x17ea85){return new BPromise(function(_0x2aa387,_0x250f5d){try{if(_0x17ea85[_0x3d9467['id']]){_0x3d9467[_0xc60f('0x2d')]=_[_0xc60f('0x2e')](_0x17ea85[_0x3d9467['id']],function(_0x227b35){return{'id':_0x227b35['id'],'fullname':_0x227b35[_0xc60f('0x2f')]};});}}catch(_0x47f621){_0x250f5d(_0x47f621);}_0x2aa387(_0x3d9467);});}function getInteractionTags(_0x1f27f4,_0x1bb150){return new BPromise(function(_0xb390e6,_0x4db602){try{if(_0x1f27f4['TagIds']){_0x1f27f4[_0xc60f('0x30')]=[];_0x1f27f4['TagIds'][_0xc60f('0x31')](',')[_0xc60f('0x32')](function(_0x7d8e40){_0x1f27f4[_0xc60f('0x30')][_0xc60f('0x33')](_0x1bb150[_0x7d8e40]);});}delete _0x1f27f4[_0xc60f('0x34')];}catch(_0x3b6305){_0x4db602(_0x3b6305);}_0xb390e6(_0x1f27f4);});}function updateSmsInteraction(_0x52917c,_0x1d3b1f,_0x15c4c7){return new BPromise(function(_0x583362,_0x4f4bfe){return getInteractionUsers(_0x52917c,_0x15c4c7)[_0xc60f('0x27')](function(_0x1b628e){return getInteractionTags(_0x1b628e,_0x1d3b1f);})[_0xc60f('0x27')](function(_0x35dfc3){return getStateInteraction(_0x35dfc3);})[_0xc60f('0x27')](function(_0x578c94){_0x583362(_0x578c94);})[_0xc60f('0x35')](function(_0x34122d){_0x4f4bfe(_0x34122d);});});}function getStateInteraction(_0x4fa176){return new BPromise(function(_0xeeebfc){_0x4fa176[_0xc60f('0x36')]=0x0;_0x4fa176['talking']=0x0;_0x4fa176[_0xc60f('0x37')]=0x0;_0x4fa176[_0xc60f('0x38')]=0x0;_0x4fa176[_0xc60f('0x39')]=0x0;if(!_0x4fa176[_0xc60f('0x3a')]&&!_0x4fa176[_0xc60f('0x3b')]){_0x4fa176['waiting']+=0x1;}if(!_0x4fa176[_0xc60f('0x3a')]&&_0x4fa176['UserId']){_0x4fa176[_0xc60f('0x3c')]+=0x1;if(_0x4fa176[_0xc60f('0x36')]){_0x4fa176[_0xc60f('0x36')]-=0x1;}}if(_0x4fa176['closed']&&_0x4fa176[_0xc60f('0x3b')]){_0x4fa176[_0xc60f('0x37')]+=0x1;if(_0x4fa176[_0xc60f('0x3c')]){_0x4fa176['talking']-=0x1;}}if(_0x4fa176['closed']&&!_0x4fa176[_0xc60f('0x3b')]){_0x4fa176[_0xc60f('0x38')]+=0x1;if(_0x4fa176[_0xc60f('0x36')]){_0x4fa176[_0xc60f('0x36')]-=0x1;}}_0x4fa176[_0xc60f('0x39')]+=0x1;_0xeeebfc(_0x4fa176);});}exports['index']=function(_0x1877d2,_0x254eaa){var _0x490e17={},_0x360eb8={},_0x4274c6={'count':0x0,'rows':[]};var _0x4dac3e=_[_0xc60f('0x2e')](db[_0xc60f('0x3d')]['rawAttributes'],function(_0x37598e){return{'name':_0x37598e[_0xc60f('0x3e')],'type':_0x37598e['type'][_0xc60f('0x3f')]};});_0x360eb8[_0xc60f('0x40')]=_[_0xc60f('0x2e')](_0x4dac3e,'name');_0x360eb8[_0xc60f('0x41')]=_[_0xc60f('0x42')](_0x1877d2[_0xc60f('0x41')]);_0x360eb8[_0xc60f('0x43')]=_[_0xc60f('0x44')](_0x360eb8[_0xc60f('0x40')],_0x360eb8[_0xc60f('0x41')]);_0x490e17[_0xc60f('0x45')]=_[_0xc60f('0x44')](_0x360eb8[_0xc60f('0x40')],qs[_0xc60f('0x46')](_0x1877d2[_0xc60f('0x41')][_0xc60f('0x46')]));_0x490e17[_0xc60f('0x45')]=_0x490e17[_0xc60f('0x45')][_0xc60f('0x47')]?_0x490e17[_0xc60f('0x45')]:_0x360eb8[_0xc60f('0x40')];if(!_0x1877d2[_0xc60f('0x41')]['hasOwnProperty'](_0xc60f('0x48'))){_0x490e17[_0xc60f('0x1f')]=qs['limit'](_0x1877d2[_0xc60f('0x41')][_0xc60f('0x1f')]);_0x490e17['offset']=qs[_0xc60f('0x1d')](_0x1877d2[_0xc60f('0x41')][_0xc60f('0x1d')]);}_0x490e17[_0xc60f('0x49')]=qs[_0xc60f('0x4a')](_0x1877d2[_0xc60f('0x41')][_0xc60f('0x4a')]);_0x490e17[_0xc60f('0x4b')]=qs['filters'](_[_0xc60f('0x4c')](_0x1877d2[_0xc60f('0x41')],_0x360eb8[_0xc60f('0x43')]),_0x4dac3e);var _0x486ffb=[];var _0x134bc3=squel[_0xc60f('0x4d')]()[_0xc60f('0x4e')]('id')[_0xc60f('0x4e')](_0xc60f('0x2b'))['field'](_0xc60f('0x4f'))[_0xc60f('0x50')](_0xc60f('0x51'));var _0x41eb66=squel['select']()['field']('u.id')[_0xc60f('0x4e')](_0xc60f('0x52'))['field'](_0xc60f('0x53'))[_0xc60f('0x50')]('user_has_sms_interactions','ui')[_0xc60f('0x54')](_0xc60f('0x55'),'u',_0xc60f('0x56'));var _0x425e8b=squel['select']()[_0xc60f('0x50')](_0xc60f('0x57'),'i')['left_join'](_0xc60f('0x58'),'c',_0xc60f('0x59'))[_0xc60f('0x54')](_0xc60f('0x55'),'o',_0xc60f('0x5a'))[_0xc60f('0x54')](_0xc60f('0x5b'),'a','a.id\x20=\x20i.SmsAccountId')[_0xc60f('0x54')](_0xc60f('0x5c'),'me',_0xc60f('0x5d'))['left_join']('sms_interaction_has_tags','it','it.SmsInteractionId\x20=\x20i.id')[_0xc60f('0x54')]('tools_tags','t',_0xc60f('0x5e'));var _0x58a82b=squel['expr']();var _0x4e5803=[];var _0x5b5777=squel[_0xc60f('0x5f')]();var _0x299cc9;if(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x60')]){_0x299cc9=as[_0xc60f('0x61')](_0x1877d2[_0xc60f('0x41')]['search']);var _0x342f0d=_0x299cc9['sqlOperator'];for(var _0x4ff8e8=0x0;_0x4ff8e8<_0x299cc9[_0xc60f('0x62')][_0xc60f('0x47')];_0x4ff8e8++){var _0xd2db32=_0x299cc9['conditions'][_0x4ff8e8];var _0x19d925='i';var _0x25ea3f=_[_0xc60f('0x63')](_0x4dac3e,[_0xc60f('0x2b'),_0xd2db32[_0xc60f('0x4e')]]);if(!_0x25ea3f){switch(_0xd2db32['field']){case _0xc60f('0x64'):if(_0xd2db32[_0xc60f('0x65')]==0x1){_0x425e8b[_0xc60f('0x66')]('`'+_0xd2db32[_0xc60f('0x4e')]+'`\x20=\x200');}else{_0x425e8b[_0xc60f('0x66')]('`'+_0xd2db32[_0xc60f('0x4e')]+_0xc60f('0x67'));}break;case _0xc60f('0x68'):if(_0xd2db32[_0xc60f('0x69')]==='$substring'){if(_0xd2db32[_0xc60f('0x65')][_0xc60f('0x31')]('\x20')[_0xc60f('0x47')]>0x1){_0x58a82b[_0x342f0d](_0xc60f('0x6a'),qs[_0xc60f('0x6b')](_0xd2db32[_0xc60f('0x65')]),null);}else{var _0x912cac='%'+_0xd2db32[_0xc60f('0x65')]+'%';_0x58a82b[_0x342f0d]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x912cac,_0x912cac,_0x912cac);}}else{_0x25ea3f=_[_0xc60f('0x63')](_0x4dac3e,[_0xc60f('0x2b'),_0xc60f('0x6c')]);_0xd2db32[_0xc60f('0x4e')]='ContactId';_0xa25fdc=as['buildExpression'](_0x19d925,_0x25ea3f['type'],_0xd2db32);_0x58a82b[_0x342f0d](_0xa25fdc[_0xc60f('0x6d')],_0xa25fdc['value']['start'],_0xa25fdc[_0xc60f('0x65')][_0xc60f('0x29')]);}break;case _0xc60f('0x6e'):var _0x25a2b6=_0xd2db32[_0xc60f('0x65')][_0xc60f('0x31')](',')[_0xc60f('0x2e')](function(_0x57306d){return Number(_0x57306d);});_0x25a2b6[_0xc60f('0x32')](function(_0x1bc25c){_0x5b5777['or'](_0xc60f('0x6f'),'%,'+_0x1bc25c+',%');});_0x4e5803=_[_0xc60f('0x70')](_0x4e5803,_0x25a2b6);break;case _0xc60f('0x71'):if(_0xd2db32[_0xc60f('0x69')]===_0xc60f('0x72')){_0x58a82b[_0x342f0d](_0xc60f('0x73'),'%'+_0xd2db32['value']+'%',null);}else{_0x25ea3f=_[_0xc60f('0x63')](_0x4dac3e,[_0xc60f('0x2b'),_0xc60f('0x3b')]);_0xd2db32[_0xc60f('0x4e')]='UserId';_0xa25fdc=as[_0xc60f('0x74')](_0x19d925,_0x25ea3f['type'],_0xd2db32);_0x58a82b[_0x342f0d](_0xa25fdc[_0xc60f('0x6d')],_0xa25fdc[_0xc60f('0x65')][_0xc60f('0x75')],_0xa25fdc[_0xc60f('0x65')]['end']);}break;case _0xc60f('0x76'):_0xa25fdc=as[_0xc60f('0x74')]('me',null,_0xd2db32);_0x58a82b[_0x342f0d](_0xa25fdc[_0xc60f('0x6d')],_0xa25fdc[_0xc60f('0x65')]['start'],_0xa25fdc[_0xc60f('0x65')][_0xc60f('0x29')]);break;}}else{var _0xa25fdc=as[_0xc60f('0x74')](_0x19d925,_0x25ea3f[_0xc60f('0x77')],_0xd2db32);_0x58a82b[_0x342f0d](_0xa25fdc[_0xc60f('0x6d')],_0xa25fdc[_0xc60f('0x65')][_0xc60f('0x75')],_0xa25fdc[_0xc60f('0x65')][_0xc60f('0x29')]);}}}else{var _0x4091b4=_(_0x1877d2['query'])[_0xc60f('0x42')]()[_0xc60f('0x2e')](function(_0x3431b7){return _[_0xc60f('0x78')](_0x4dac3e,['name',_0x3431b7])?_0x3431b7:undefined;})[_0xc60f('0x79')]()['value']();if(!_[_0xc60f('0x7a')](_0x4091b4)){_0x4091b4[_0xc60f('0x32')](function(_0x4c3bbf){if(_0x4c3bbf===_0xc60f('0x7b')){_0x425e8b[_0xc60f('0x4b')]('i.SmsAccountId\x20IN\x20?',[][_0xc60f('0x7c')](_0x1877d2[_0xc60f('0x41')][_0x4c3bbf]));}else if(_0x4c3bbf===_0xc60f('0x7d')){var _0x2e3719=JSON[_0xc60f('0x7e')](_0x1877d2[_0xc60f('0x41')][_0x4c3bbf])[_0xc60f('0x7f')];var _0x14049c=JSON[_0xc60f('0x7e')](_0x1877d2[_0xc60f('0x41')][_0x4c3bbf])[_0xc60f('0x80')];_0x425e8b[_0xc60f('0x4b')](_0xc60f('0x81'),_0x2e3719,_0x14049c);}else{if(_0x1877d2[_0xc60f('0x41')][_0x4c3bbf]===_0xc60f('0x82')){_0x425e8b['where']('i.'+_0x4c3bbf+_0xc60f('0x83'));}else{_0x425e8b[_0xc60f('0x4b')]('i.'+_0x4c3bbf+_0xc60f('0x84'),_0x1877d2['query'][_0x4c3bbf]);}}});}if(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x85')]){if(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x85')]==0x1){_0x425e8b[_0xc60f('0x66')](_0xc60f('0x86'));}else{_0x425e8b[_0xc60f('0x66')]('`unreadMessages`\x20>\x200');}}if(_0x1877d2[_0xc60f('0x41')]['tag']){_0x4e5803=_['isArray'](_0x1877d2[_0xc60f('0x41')][_0xc60f('0x87')])?_0x1877d2[_0xc60f('0x41')]['tag']:new Array(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x87')]);_0x4e5803[_0xc60f('0x32')](function(_0x2526e2){_0x5b5777['or'](_0xc60f('0x6f'),'%,'+_0x2526e2+',%');});}if(_0x1877d2['query'][_0xc60f('0x88')]){var _0x2a0231=_0x1877d2[_0xc60f('0x41')]['filter'][_0xc60f('0x89')]('\x5c','\x5c\x5c')[_0xc60f('0x89')](/'/g,'\x27\x27');if(qs[_0xc60f('0x8a')](_0x2a0231)){_0x58a82b['or'](_0xc60f('0x8b'),_0x2a0231+'%')['or'](_0xc60f('0x8c'),_0x2a0231+'%');}else{_0x58a82b['or'](_0xc60f('0x8d'),qs[_0xc60f('0x6b')](_0x2a0231))['or'](_0xc60f('0x8e'),_0x2a0231+'%');}}}_0x425e8b[_0xc60f('0x4b')](_0x58a82b);_0x425e8b[_0xc60f('0x8f')](_0xc60f('0x90'));var _0x5f10b5={'type':db[_0xc60f('0x91')][_0xc60f('0x92')][_0xc60f('0x93')],'raw':!![]};var _0x191e64=_0x425e8b[_0xc60f('0x94')]();_0x191e64[_0xc60f('0x4e')]('i.id');_0x191e64[_0xc60f('0x4e')](_0xc60f('0x95'),_0xc60f('0x64'));if(_0x490e17[_0xc60f('0x49')]){_0x490e17[_0xc60f('0x49')][_0xc60f('0x32')](function(_0x27310e){var _0x3c841f=_0x27310e[0x0]===_0xc60f('0x96')?_0x27310e[0x0]:'i.'+_0x27310e[0x0];_0x425e8b[_0xc60f('0x49')](_0x3c841f,_0x27310e[0x1]===_0xc60f('0x97')?![]:!![]);});}if(!_['isEmpty'](_0x4e5803)){_0x425e8b[_0xc60f('0x66')](_0x5b5777);_0x191e64['where'](_0xc60f('0x98'),_0x4e5803);}BPromise[_0xc60f('0x99')]()[_0xc60f('0x27')](function(){if(!_0x299cc9){if(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x7b')])return;_0x191e64[_0xc60f('0x4b')](_0xc60f('0x9a'));_0x425e8b[_0xc60f('0x4b')](_0xc60f('0x9a'));return;}if(_0x1877d2['user']['role']!==_0xc60f('0x9b'))return;return _0x1877d2[_0xc60f('0x9c')]['getSmsAccounts']({'attributes':['id'],'raw':!![]})['then'](function(_0x8a96fc){if(_[_0xc60f('0x7a')](_0x8a96fc)){_0x191e64['where'](_0xc60f('0x9d'));_0x425e8b[_0xc60f('0x4b')](_0xc60f('0x9d'));}else{_0x191e64[_0xc60f('0x4b')](_0xc60f('0x9e'),_[_0xc60f('0x2e')](_0x8a96fc,'id'));_0x425e8b['where'](_0xc60f('0x9e'),_[_0xc60f('0x2e')](_0x8a96fc,'id'));}});})[_0xc60f('0x27')](function(){if(_0x1877d2[_0xc60f('0x9c')][_0xc60f('0x9f')]===_0xc60f('0x9b')&&!_0x299cc9&&!_0x1877d2[_0xc60f('0x41')][_0xc60f('0x7b')])return[];return db[_0xc60f('0xa0')][_0xc60f('0x41')](_0x191e64[_0xc60f('0xa1')](),_0x5f10b5);})[_0xc60f('0x27')](function(_0x19a6a2){_0x4274c6[_0xc60f('0x20')]=_0x19a6a2['length'];if(_0x4274c6[_0xc60f('0x20')]===0x0)return[];return db[_0xc60f('0xa0')]['query'](_0x134bc3['toString'](),_0x5f10b5)[_0xc60f('0x27')](function(_0x565f9d){_0x486ffb=_[_0xc60f('0xa2')](_0x565f9d,'id');_0x5f10b5=_[_0xc60f('0xa3')](_0x5f10b5,{'model':db[_0xc60f('0x3d')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1877d2[_0xc60f('0x41')][_0xc60f('0x46')]){_0x490e17[_0xc60f('0x45')][_0xc60f('0x32')](function(_0x369812){_0x425e8b[_0xc60f('0x4e')]('i.'+_0x369812);});}else{_0x425e8b[_0xc60f('0x4e')](_0xc60f('0x95'),_0xc60f('0x64'));_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xa4'),_0xc60f('0xa5'));_0x425e8b['field']('a.mandatoryDisposition','Account.mandatoryDisposition');_0x425e8b[_0xc60f('0x4e')]('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',_0xc60f('0x96'));_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xa6'));_0x425e8b[_0xc60f('0x4e')]('c.firstName',_0xc60f('0xa7'));_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xa8'),_0xc60f('0xa9'));_0x425e8b['field'](_0xc60f('0xaa'),'Contact.email');_0x425e8b['field'](_0xc60f('0xab'),'Contact.phone');_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xac'),_0xc60f('0xad'));_0x425e8b[_0xc60f('0x4e')]('c.fax','Contact.fax');_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xae'),'Owner.fullname');_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xaf'),_0xc60f('0xb0'));_0x425e8b[_0xc60f('0x4e')](_0xc60f('0xb1'),_0xc60f('0x34'));}if(_0x490e17[_0xc60f('0x1f')])_0x425e8b[_0xc60f('0x1f')](_0x490e17[_0xc60f('0x1f')]);if(_0x490e17[_0xc60f('0x1d')])_0x425e8b['offset'](_0x490e17[_0xc60f('0x1d')]);return db[_0xc60f('0xa0')][_0xc60f('0x41')](_0x425e8b[_0xc60f('0xa1')](),_0x5f10b5);})[_0xc60f('0x27')](function(_0x42799f){if(_0x42799f['length']>0x0)_0x41eb66[_0xc60f('0x4b')](_0xc60f('0xb2'),_[_0xc60f('0x2e')](_0x42799f,'id'));return db['sequelize'][_0xc60f('0x41')](_0x41eb66[_0xc60f('0xa1')](),_0x5f10b5)['then'](function(_0x58ffc9){var _0x5e8b9a=_['groupBy'](_0x58ffc9,'SmsInteractionId');var _0x1f208f=[];_0x42799f['forEach'](function(_0x13c785){_0x1f208f[_0xc60f('0x33')](updateSmsInteraction(_0x13c785,_0x486ffb,_0x5e8b9a));});return BPromise[_0xc60f('0xb3')](_0x1f208f);});});})[_0xc60f('0x27')](function(_0x5f418b){_0x4274c6[_0xc60f('0xb4')]=_0x5f418b;return _0x4274c6;})[_0xc60f('0x27')](respondWithFilteredResult(_0x254eaa,_0x490e17))['catch'](handleError(_0x254eaa,null));};exports['show']=function(_0x394d28,_0x2710b2){var _0x146be0={'raw':![],'where':{'id':_0x394d28['params']['id']}},_0x49b0a3={};_0x49b0a3['model']=_[_0xc60f('0x42')](db[_0xc60f('0x3d')][_0xc60f('0xb5')]);_0x49b0a3[_0xc60f('0x41')]=_[_0xc60f('0x42')](_0x394d28[_0xc60f('0x41')]);_0x49b0a3['filters']=_[_0xc60f('0x44')](_0x49b0a3[_0xc60f('0x40')],_0x49b0a3[_0xc60f('0x41')]);_0x146be0[_0xc60f('0x45')]=_[_0xc60f('0x44')](_0x49b0a3[_0xc60f('0x40')],qs[_0xc60f('0x46')](_0x394d28[_0xc60f('0x41')][_0xc60f('0x46')]));_0x146be0[_0xc60f('0x45')]=_0x146be0[_0xc60f('0x45')]['length']?_0x146be0[_0xc60f('0x45')]:_0x49b0a3['model'];if(_0x394d28[_0xc60f('0x41')][_0xc60f('0xb6')]){_0x146be0[_0xc60f('0xb7')]=[{'all':!![]}];}_0x146be0=_[_0xc60f('0xa3')]({},_0x146be0,_0x394d28[_0xc60f('0xb8')]);return db[_0xc60f('0x3d')][_0xc60f('0x63')](_0x146be0)[_0xc60f('0x27')](handleEntityNotFound(_0x2710b2,null))[_0xc60f('0x27')](respondWithResult(_0x2710b2,null))[_0xc60f('0x35')](handleError(_0x2710b2,null));};exports[_0xc60f('0xb9')]=function(_0x4d54cd,_0x45e9ba){return db[_0xc60f('0x3d')][_0xc60f('0xb9')](_0x4d54cd[_0xc60f('0x76')],{})[_0xc60f('0x27')](respondWithResult(_0x45e9ba,0xc9))[_0xc60f('0x35')](handleError(_0x45e9ba,null));};exports[_0xc60f('0x26')]=function(_0x10d795,_0x119a2e){if(_0x10d795[_0xc60f('0x76')]['id']){delete _0x10d795[_0xc60f('0x76')]['id'];}return db['SmsInteraction']['find']({'where':{'id':_0x10d795[_0xc60f('0xba')]['id']}})[_0xc60f('0x27')](handleEntityNotFound(_0x119a2e,null))[_0xc60f('0x27')](saveUpdates(_0x10d795[_0xc60f('0x76')],null))['then'](respondWithResult(_0x119a2e,null))[_0xc60f('0x35')](handleError(_0x119a2e,null));};exports[_0xc60f('0x28')]=function(_0x2a64a6,_0x19fbf2){return db[_0xc60f('0x3d')][_0xc60f('0x63')]({'where':{'id':_0x2a64a6[_0xc60f('0xba')]['id']}})[_0xc60f('0x27')](handleEntityNotFound(_0x19fbf2,null))[_0xc60f('0x27')](removeEntity(_0x19fbf2,null))['catch'](handleError(_0x19fbf2,null));};exports[_0xc60f('0xbb')]=function(_0x3e3b6c,_0x5c99ef){return db['SmsInteraction'][_0xc60f('0xbb')]()[_0xc60f('0x27')](respondWithResult(_0x5c99ef,null))[_0xc60f('0x35')](handleError(_0x5c99ef,null));};exports['addMessage']=function(_0x83d520,_0x4c0208,_0x2d318f){return db[_0xc60f('0xbc')][_0xc60f('0x63')]({'where':{'id':_0x83d520[_0xc60f('0xba')]['id']}})[_0xc60f('0x27')](handleEntityNotFound(_0x4c0208,null))[_0xc60f('0x27')](function(_0x440f63){if(_0x440f63){return _0x440f63['addMessage'](_0x83d520[_0xc60f('0x76')]['ids'],_[_0xc60f('0xbd')](_0x83d520[_0xc60f('0x76')],[_0xc60f('0xbe'),'id'])||{});}})[_0xc60f('0x27')](respondWithResult(_0x4c0208,null))[_0xc60f('0x35')](handleError(_0x4c0208,null));};exports[_0xc60f('0xbf')]=function(_0x3a5ad4,_0x21564e,_0x43fc47){var _0x35a22b={'raw':![],'where':{}};var _0x5389dd={};var _0x466cd1={'count':0x0,'rows':[]};return db[_0xc60f('0x3d')][_0xc60f('0xc0')]({'where':{'id':_0x3a5ad4[_0xc60f('0xba')]['id']}})[_0xc60f('0x27')](handleEntityNotFound(_0x21564e,null))[_0xc60f('0x27')](function(_0x4036a5){if(_0x4036a5){_0x5389dd[_0xc60f('0x40')]=_[_0xc60f('0x42')](db['SmsMessage'][_0xc60f('0xb5')]);_0x5389dd[_0xc60f('0x41')]=_['keys'](_0x3a5ad4[_0xc60f('0x41')]);_0x5389dd['filters']=_[_0xc60f('0x44')](_0x5389dd[_0xc60f('0x40')],_0x5389dd[_0xc60f('0x41')]);_0x35a22b[_0xc60f('0x45')]=_['intersection'](_0x5389dd[_0xc60f('0x40')],qs[_0xc60f('0x46')](_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x46')]));_0x35a22b[_0xc60f('0x45')]=_0x35a22b[_0xc60f('0x45')][_0xc60f('0x47')]?_0x35a22b[_0xc60f('0x45')]:_0x5389dd[_0xc60f('0x40')];if(!_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0xc1')](_0xc60f('0x48'))){_0x35a22b[_0xc60f('0x1f')]=qs['limit'](_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x1f')]);_0x35a22b[_0xc60f('0x1d')]=qs[_0xc60f('0x1d')](_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x1d')]);}_0x35a22b[_0xc60f('0x49')]=qs[_0xc60f('0x4a')](_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x4a')]);_0x35a22b[_0xc60f('0x4b')]=qs[_0xc60f('0x43')](_[_0xc60f('0x4c')](_0x3a5ad4[_0xc60f('0x41')],_0x5389dd['filters']));_0x35a22b[_0xc60f('0x4b')][_0xc60f('0xc2')]=_0x4036a5['id'];if(_0x3a5ad4[_0xc60f('0x41')]['filter']){_0x35a22b[_0xc60f('0x4b')]=_[_0xc60f('0xa3')](_0x35a22b[_0xc60f('0x4b')],{'$or':_['map'](_0x35a22b[_0xc60f('0x45')],function(_0x2a36ca){var _0xaba9d5={};_0xaba9d5[_0x2a36ca]={'$like':'%'+_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x88')]+'%'};return _0xaba9d5;})});}if(_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x7f')]){var _0x57893f=_0x3a5ad4[_0xc60f('0x41')][_0xc60f('0x7f')][_0xc60f('0x31')](',');var _0x2068a3={};_0x2068a3[_0x57893f[0x0]]={'$gte':moment(_0x57893f[0x1])[_0xc60f('0xc3')](_0xc60f('0xc4'))};_0x35a22b[_0xc60f('0x4b')]=_[_0xc60f('0xa3')](_0x35a22b['where'],_0x2068a3);}_0x35a22b=_['merge']({},_0x35a22b,_0x3a5ad4[_0xc60f('0xb8')]);return db[_0xc60f('0xbc')][_0xc60f('0x20')]({'where':_0x35a22b[_0xc60f('0x4b')]})['then'](function(_0x385db3){_0x466cd1['count']=_0x385db3;if(_0x3a5ad4['query']['includeAll']){_0x35a22b['include']=[{'all':!![]}];}return db[_0xc60f('0xbc')]['findAll'](_0x35a22b);})[_0xc60f('0x27')](function(_0x433aa1){_0x466cd1[_0xc60f('0xb4')]=_0x433aa1;return _0x466cd1;});}})[_0xc60f('0x27')](respondWithFilteredResult(_0x21564e,_0x35a22b))[_0xc60f('0x35')](handleError(_0x21564e,null));};exports[_0xc60f('0xc5')]=function(_0x337f40,_0x397995,_0x472bab){return db[_0xc60f('0x3d')][_0xc60f('0x63')]({'where':{'id':_0x337f40[_0xc60f('0xba')]['id']}})['then'](handleEntityNotFound(_0x397995,null))[_0xc60f('0x27')](function(_0x39fc63){if(_0x39fc63){return _0x39fc63[_0xc60f('0xc6')](_0x337f40[_0xc60f('0x76')][_0xc60f('0xbe')],_[_0xc60f('0xbd')](_0x337f40[_0xc60f('0x76')],[_0xc60f('0xbe'),'id'])||{})[_0xc60f('0xc7')](function(){return db[_0xc60f('0x6e')][_0xc60f('0xc8')]({'attributes':['id','name',_0xc60f('0x4f')],'where':{'id':_0x337f40[_0xc60f('0x76')][_0xc60f('0xbe')]}});})['then'](function(_0x3cdabd){socket[_0xc60f('0xc9')]('smsInteractionTags:save',{'id':Number(_0x337f40[_0xc60f('0xba')]['id']),'tags':_0x3cdabd||[]});return{'id':Number(_0x337f40[_0xc60f('0xba')]['id']),'tags':_0x3cdabd||[]};});}})[_0xc60f('0x27')](respondWithResult(_0x397995,null))['catch'](handleError(_0x397995,null));};exports[_0xc60f('0xca')]=function(_0x4fdaec,_0x193c51,_0x210e3a){return db['SmsInteraction'][_0xc60f('0x63')]({'where':{'id':_0x4fdaec[_0xc60f('0xba')]['id']}})['then'](handleEntityNotFound(_0x193c51,null))['then'](function(_0x1855d8){if(_0x1855d8){return _0x1855d8[_0xc60f('0xca')](_0x4fdaec[_0xc60f('0x41')][_0xc60f('0xbe')]);}})[_0xc60f('0x27')](respondWithStatusCode(_0x193c51,null))[_0xc60f('0x35')](handleError(_0x193c51,null));};exports[_0xc60f('0xcb')]=function(_0x526eb8,_0xdf49){var _0x193fc8=moment()[_0xc60f('0xcc')]()[_0xc60f('0xa1')]();var _0x31b5ec=path[_0xc60f('0xcd')](config[_0xc60f('0xce')],_0xc60f('0xcf'),'files',_0xc60f('0xd0'));var _0x5cae3a=path[_0xc60f('0xcd')](config[_0xc60f('0xce')],_0xc60f('0xcf'),'files',_0xc60f('0xd1'));var _0x3cba5c=path[_0xc60f('0xcd')](_0x31b5ec,_0x193fc8);var _0x5c0ca1=util['format']('transcript-%d-%s.zip',_0x526eb8['params']['id'],_0x193fc8);var _0x14c7e4=path[_0xc60f('0xcd')](_0x31b5ec,_0x5c0ca1);var _0x4619b8=[];_0x4619b8[_0xc60f('0x33')]({'model':db[_0xc60f('0x71')],'as':'User','attributes':['id','fullname'],'raw':!![]});_0x4619b8['push']({'model':db[_0xc60f('0xd2')],'as':_0xc60f('0x68'),'attributes':['id','firstName',_0xc60f('0xd3')],'raw':!![]});var _0x61ccfe=[{'model':db[_0xc60f('0xbc')],'as':_0xc60f('0xd4'),'attributes':['id',_0xc60f('0x76'),'createdAt',_0xc60f('0xd5'),_0xc60f('0xd6'),_0xc60f('0x85')],'include':_0x4619b8}];_0x61ccfe['push']({'model':db[_0xc60f('0xd7')],'as':_0xc60f('0xd8'),'attributes':['id',_0xc60f('0x2b')]});_0x61ccfe[_0xc60f('0x33')]({'model':db[_0xc60f('0x71')],'as':_0xc60f('0xd9'),'attributes':['id','fullname']});return db[_0xc60f('0x3d')]['find']({'where':{'id':_0x526eb8[_0xc60f('0xba')]['id']},'include':_0x61ccfe})[_0xc60f('0x27')](handleEntityNotFound(_0xdf49,null))[_0xc60f('0x27')](function(_0x1bf987){if(_0x1bf987){var _0x56315b=_0x1bf987[_0xc60f('0xda')]({'plain':!![]});fs[_0xc60f('0xdb')](_0x3cba5c);var _0x3051df={'channel':'Sms','account':_0x56315b[_0xc60f('0xd8')]['name'],'agent':_0x56315b[_0xc60f('0xd9')]?_0x56315b[_0xc60f('0xd9')]['fullname']:'N.A.','createdAt':moment(_0x56315b[_0xc60f('0x7d')])[_0xc60f('0xc3')](_0xc60f('0xc4'))[_0xc60f('0xa1')](),'closedAt':_0x56315b[_0xc60f('0x3a')]?moment(_0x56315b['closedAt'])['format']('YYYY-MM-DD\x20HH:mm:ss')['toString']():'','disposition':_0x56315b['disposition'],'messages':_(_0x56315b['Messages'])['filter']({'secret':![]})[_0xc60f('0x2e')](function(_0x4d89ca){return{'date':moment(_0x4d89ca['createdAt'])[_0xc60f('0xc3')](_0xc60f('0xc4'))[_0xc60f('0xa1')](),'sender':_0x4d89ca[_0xc60f('0xd5')]==='out'?_0x4d89ca['User']?_0x4d89ca[_0xc60f('0x71')][_0xc60f('0x2f')]:'System':_0x4d89ca[_0xc60f('0x68')][_0xc60f('0xdc')]+(_0x4d89ca[_0xc60f('0x68')][_0xc60f('0xd3')]?'\x20'+_0x4d89ca[_0xc60f('0x68')]['lastName']:''),'body':_0x4d89ca[_0xc60f('0x76')],'direction':_0x4d89ca[_0xc60f('0xd5')]==='out'?'A':'C','secret':_0x4d89ca[_0xc60f('0xd6')],'read':_0x4d89ca[_0xc60f('0x85')]};})['value']()};return ejs['renderFile'](path[_0xc60f('0xcd')](config[_0xc60f('0xce')],'server',_0xc60f('0xdd'),'downloadInteraction.ejs'),{'interaction':_0x3051df})['then'](function(_0x4c0bdf){var _0x47019d=path[_0xc60f('0xcd')](_0x3cba5c,'transcript-'+_0x56315b['id']+'-'+_0x193fc8+'.pdf');var _0x35a5da={'path':_0x47019d,'channel':_0xc60f('0xde'),'interactionId':_0x56315b['id']};return pdf[_0xc60f('0xdf')](_0x4c0bdf,_0x35a5da);})[_0xc60f('0x27')](function(){return new BPromise(function(_0x22f328,_0x1e200f){zipdir(_0x3cba5c,{'saveTo':_0x14c7e4},function(_0x2c5ef1,_0x5c82b1){if(_0x2c5ef1)return _0x1e200f(_0x2c5ef1);return _0x22f328(_0x5c82b1);});})[_0xc60f('0x27')](function(){return new BPromise(function(_0x294d22,_0x52cab2){rimraf(_0x3cba5c,function(_0x2941e4){if(_0x2941e4)_0x52cab2(_0x2941e4);return _0x294d22();});});})[_0xc60f('0x27')](function(){return _0xdf49['download'](_0x14c7e4,_0x5c0ca1,function(_0x1c92e8){if(_0x1c92e8){console[_0xc60f('0xe0')](_0xc60f('0xe1'),_0x1c92e8);}else{fs[_0xc60f('0xe2')](_0x14c7e4);}});});});}else{return _0xdf49[_0xc60f('0x1b')](0xc8);}})[_0xc60f('0x35')](handleError(_0xdf49,null));};
\ No newline at end of file
+var _0x1555=['../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./smsInteraction.socket','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','update','destroy','then','end','error','stack','name','send','index','map','SmsInteraction','rawAttributes','type','key','getOptions','query','user','show','params','keys','filters','model','attributes','fields','length','include','merge','options','find','create','body','catch','describe','addMessage','omit','ids','getMessages','findOne','SmsMessage','intersection','hasOwnProperty','nolimit','order','where','SmsInteractionId','filter','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','includeAll','findAll','addTags','spread','Tag','emit','smsInteractionTags:save','removeTags','join','server','files','tmp','transcript-%d-%s.zip','push','fullname','CmContact','Contact','firstName','lastName','Messages','secret','read','SmsAccount','Account','User','Owner','get','mkdirSync','Sms','N.A.','createdAt','toString','closed','closedAt','disposition','direction','System','out','value','renderFile','root','downloadInteraction.ejs','.pdf','createPdfFromHTML','download','log','err','unlinkSync','zip-dir','moment','path','lodash','ioredis','../../components/interaction/service'];(function(_0x3b380d,_0x4bf247){var _0x54502b=function(_0x35d207){while(--_0x35d207){_0x3b380d['push'](_0x3b380d['shift']());}};_0x54502b(++_0x4bf247);}(_0x1555,0x1e6));var _0x5155=function(_0x16495c,_0x413d7e){_0x16495c=_0x16495c-0x0;var _0x5d3458=_0x1555[_0x16495c];return _0x5d3458;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0x5155('0x0'));var moment=require(_0x5155('0x1'));var BPromise=require('bluebird');var util=require('util');var path=require(_0x5155('0x2'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x5155('0x3'));var Redis=require(_0x5155('0x4'));var interaction=require(_0x5155('0x5'));var qs=require(_0x5155('0x6'));var pdf=require(_0x5155('0x7'));var logger=require(_0x5155('0x8'))(_0x5155('0x9'));var config=require(_0x5155('0xa'));var db=require(_0x5155('0xb'))['db'];config[_0x5155('0xc')]=_[_0x5155('0xd')](config[_0x5155('0xc')],{'host':'localhost','port':0x18eb});var socket=require(_0x5155('0xe'))(new Redis(config['redis']));require(_0x5155('0xf'))['register'](socket);function respondWithStatusCode(_0x58496e,_0x3f60a3){_0x3f60a3=_0x3f60a3||0xcc;return function(_0x38bf8d){if(_0x38bf8d){return _0x58496e[_0x5155('0x10')](_0x3f60a3);}return _0x58496e['status'](_0x3f60a3)['end']();};}function respondWithResult(_0x316466,_0x3c11c1){_0x3c11c1=_0x3c11c1||0xc8;return function(_0x1b515e){if(_0x1b515e){return _0x316466[_0x5155('0x11')](_0x3c11c1)[_0x5155('0x12')](_0x1b515e);}};}function respondWithFilteredResult(_0x1e0cfd,_0x4137c4){return function(_0x20287f){if(_0x20287f){var _0xc22c90=typeof _0x4137c4[_0x5155('0x13')]===_0x5155('0x14')&&typeof _0x4137c4[_0x5155('0x15')]==='undefined';var _0x5a6d76=_0x20287f[_0x5155('0x16')];var _0x27abca=_0xc22c90?0x0:_0x4137c4[_0x5155('0x13')];var _0x5b9d1e=_0xc22c90?_0x20287f[_0x5155('0x16')]:_0x4137c4[_0x5155('0x13')]+_0x4137c4['limit'];var _0xd3b110;if(_0x5b9d1e>=_0x5a6d76){_0x5b9d1e=_0x5a6d76;_0xd3b110=0xc8;}else{_0xd3b110=0xce;}_0x1e0cfd['status'](_0xd3b110);return _0x1e0cfd[_0x5155('0x17')](_0x5155('0x18'),_0x27abca+'-'+_0x5b9d1e+'/'+_0x5a6d76)[_0x5155('0x12')](_0x20287f);}return null;};}function saveUpdates(_0x313f74){return function(_0x2c0079){if(_0x2c0079){return _0x2c0079[_0x5155('0x19')](_0x313f74)['then'](function(_0x6c4b0){return _0x6c4b0;});}return null;};}function removeEntity(_0x1f6f26){return function(_0x138a90){if(_0x138a90){return _0x138a90[_0x5155('0x1a')]()[_0x5155('0x1b')](function(){_0x1f6f26['status'](0xcc)[_0x5155('0x1c')]();});}};}function handleEntityNotFound(_0x31e111){return function(_0x389485){if(!_0x389485){_0x31e111[_0x5155('0x10')](0x194);}return _0x389485;};}function handleError(_0xa2c494,_0xa174c3){_0xa174c3=_0xa174c3||0x1f4;return function(_0x40e101){logger[_0x5155('0x1d')](_0x40e101[_0x5155('0x1e')]);if(_0x40e101['name']){delete _0x40e101[_0x5155('0x1f')];}_0xa2c494[_0x5155('0x11')](_0xa174c3)[_0x5155('0x20')](_0x40e101);};}exports[_0x5155('0x21')]=function(_0x4ba9f2,_0x3c0409){var _0x391b6d={};var _0x1f6f7b=_[_0x5155('0x22')](db[_0x5155('0x23')][_0x5155('0x24')],function(_0x400002){return{'name':_0x400002['fieldName'],'type':_0x400002[_0x5155('0x25')][_0x5155('0x26')]};});_0x391b6d=qs[_0x5155('0x27')](_0x1f6f7b,_0x4ba9f2);return interaction['findAll']('sms',_0x4ba9f2[_0x5155('0x28')],_0x4ba9f2[_0x5155('0x29')],_0x391b6d,_0x1f6f7b)[_0x5155('0x1b')](respondWithFilteredResult(_0x3c0409,_0x391b6d))['catch'](handleError(_0x3c0409,null));};exports[_0x5155('0x2a')]=function(_0x91c7f5,_0xa91caa){var _0x5a1d8f={'raw':![],'where':{'id':_0x91c7f5[_0x5155('0x2b')]['id']}},_0x441131={};_0x441131['model']=_[_0x5155('0x2c')](db[_0x5155('0x23')]['rawAttributes']);_0x441131['query']=_[_0x5155('0x2c')](_0x91c7f5['query']);_0x441131[_0x5155('0x2d')]=_['intersection'](_0x441131[_0x5155('0x2e')],_0x441131[_0x5155('0x28')]);_0x5a1d8f[_0x5155('0x2f')]=_['intersection'](_0x441131[_0x5155('0x2e')],qs[_0x5155('0x30')](_0x91c7f5['query']['fields']));_0x5a1d8f[_0x5155('0x2f')]=_0x5a1d8f[_0x5155('0x2f')][_0x5155('0x31')]?_0x5a1d8f[_0x5155('0x2f')]:_0x441131[_0x5155('0x2e')];if(_0x91c7f5['query']['includeAll']){_0x5a1d8f[_0x5155('0x32')]=[{'all':!![]}];}_0x5a1d8f=_[_0x5155('0x33')]({},_0x5a1d8f,_0x91c7f5[_0x5155('0x34')]);return db['SmsInteraction'][_0x5155('0x35')](_0x5a1d8f)['then'](handleEntityNotFound(_0xa91caa,null))['then'](respondWithResult(_0xa91caa,null))['catch'](handleError(_0xa91caa,null));};exports[_0x5155('0x36')]=function(_0x51840e,_0x5a5b41){return db[_0x5155('0x23')][_0x5155('0x36')](_0x51840e[_0x5155('0x37')],{})[_0x5155('0x1b')](respondWithResult(_0x5a5b41,0xc9))[_0x5155('0x38')](handleError(_0x5a5b41,null));};exports[_0x5155('0x19')]=function(_0xa936f2,_0x203d02){if(_0xa936f2['body']['id']){delete _0xa936f2[_0x5155('0x37')]['id'];}return db['SmsInteraction'][_0x5155('0x35')]({'where':{'id':_0xa936f2[_0x5155('0x2b')]['id']}})[_0x5155('0x1b')](handleEntityNotFound(_0x203d02,null))[_0x5155('0x1b')](saveUpdates(_0xa936f2['body'],null))[_0x5155('0x1b')](respondWithResult(_0x203d02,null))[_0x5155('0x38')](handleError(_0x203d02,null));};exports[_0x5155('0x1a')]=function(_0x3eed29,_0x361369){return db[_0x5155('0x23')][_0x5155('0x35')]({'where':{'id':_0x3eed29['params']['id']}})[_0x5155('0x1b')](handleEntityNotFound(_0x361369,null))[_0x5155('0x1b')](removeEntity(_0x361369,null))[_0x5155('0x38')](handleError(_0x361369,null));};exports[_0x5155('0x39')]=function(_0x6c62c5,_0x373df7){return db['SmsInteraction'][_0x5155('0x39')]()[_0x5155('0x1b')](respondWithResult(_0x373df7,null))['catch'](handleError(_0x373df7,null));};exports[_0x5155('0x3a')]=function(_0x57b89d,_0x869e81){return db['SmsMessage'][_0x5155('0x35')]({'where':{'id':_0x57b89d[_0x5155('0x2b')]['id']}})[_0x5155('0x1b')](handleEntityNotFound(_0x869e81,null))['then'](function(_0x1d5cb8){if(_0x1d5cb8){return _0x1d5cb8[_0x5155('0x3a')](_0x57b89d[_0x5155('0x37')]['ids'],_[_0x5155('0x3b')](_0x57b89d['body'],[_0x5155('0x3c'),'id'])||{});}})[_0x5155('0x1b')](respondWithResult(_0x869e81,null))['catch'](handleError(_0x869e81,null));};exports[_0x5155('0x3d')]=function(_0x5a63c7,_0x5e2c98){var _0x4ead10={'raw':![],'where':{}};var _0x557cbe={};var _0x19a930={'count':0x0,'rows':[]};return db[_0x5155('0x23')][_0x5155('0x3e')]({'where':{'id':_0x5a63c7[_0x5155('0x2b')]['id']}})['then'](handleEntityNotFound(_0x5e2c98,null))['then'](function(_0x5deab0){if(_0x5deab0){_0x557cbe[_0x5155('0x2e')]=_[_0x5155('0x2c')](db[_0x5155('0x3f')]['rawAttributes']);_0x557cbe[_0x5155('0x28')]=_[_0x5155('0x2c')](_0x5a63c7[_0x5155('0x28')]);_0x557cbe[_0x5155('0x2d')]=_[_0x5155('0x40')](_0x557cbe[_0x5155('0x2e')],_0x557cbe[_0x5155('0x28')]);_0x4ead10[_0x5155('0x2f')]=_[_0x5155('0x40')](_0x557cbe[_0x5155('0x2e')],qs[_0x5155('0x30')](_0x5a63c7[_0x5155('0x28')][_0x5155('0x30')]));_0x4ead10['attributes']=_0x4ead10[_0x5155('0x2f')][_0x5155('0x31')]?_0x4ead10[_0x5155('0x2f')]:_0x557cbe[_0x5155('0x2e')];if(!_0x5a63c7['query'][_0x5155('0x41')](_0x5155('0x42'))){_0x4ead10[_0x5155('0x15')]=qs[_0x5155('0x15')](_0x5a63c7[_0x5155('0x28')]['limit']);_0x4ead10[_0x5155('0x13')]=qs[_0x5155('0x13')](_0x5a63c7[_0x5155('0x28')][_0x5155('0x13')]);}_0x4ead10[_0x5155('0x43')]=qs['sort'](_0x5a63c7[_0x5155('0x28')]['sort']);_0x4ead10[_0x5155('0x44')]=qs[_0x5155('0x2d')](_['pick'](_0x5a63c7[_0x5155('0x28')],_0x557cbe[_0x5155('0x2d')]));_0x4ead10[_0x5155('0x44')][_0x5155('0x45')]=_0x5deab0['id'];if(_0x5a63c7[_0x5155('0x28')][_0x5155('0x46')]){_0x4ead10[_0x5155('0x44')]=_[_0x5155('0x33')](_0x4ead10[_0x5155('0x44')],{'$or':_[_0x5155('0x22')](_0x4ead10['attributes'],function(_0x1fbd1a){var _0x3b9097={};_0x3b9097[_0x1fbd1a]={'$like':'%'+_0x5a63c7[_0x5155('0x28')][_0x5155('0x46')]+'%'};return _0x3b9097;})});}if(_0x5a63c7['query'][_0x5155('0x47')]){var _0x4eafe2=_0x5a63c7[_0x5155('0x28')]['$gte'][_0x5155('0x48')](',');var _0x48748f={};_0x48748f[_0x4eafe2[0x0]]={'$gte':moment(_0x4eafe2[0x1])[_0x5155('0x49')](_0x5155('0x4a'))};_0x4ead10[_0x5155('0x44')]=_[_0x5155('0x33')](_0x4ead10[_0x5155('0x44')],_0x48748f);}_0x4ead10=_[_0x5155('0x33')]({},_0x4ead10,_0x5a63c7[_0x5155('0x34')]);return db[_0x5155('0x3f')][_0x5155('0x16')]({'where':_0x4ead10['where']})[_0x5155('0x1b')](function(_0x4f2007){_0x19a930[_0x5155('0x16')]=_0x4f2007;if(_0x5a63c7[_0x5155('0x28')][_0x5155('0x4b')]){_0x4ead10['include']=[{'all':!![]}];}return db[_0x5155('0x3f')][_0x5155('0x4c')](_0x4ead10);})[_0x5155('0x1b')](function(_0x274968){_0x19a930['rows']=_0x274968;return _0x19a930;});}})['then'](respondWithFilteredResult(_0x5e2c98,_0x4ead10))['catch'](handleError(_0x5e2c98,null));};exports[_0x5155('0x4d')]=function(_0x1e2250,_0x1c3c9b){return db[_0x5155('0x23')][_0x5155('0x35')]({'where':{'id':_0x1e2250[_0x5155('0x2b')]['id']}})['then'](handleEntityNotFound(_0x1c3c9b,null))['then'](function(_0x2b6144){if(_0x2b6144){return _0x2b6144['setTags'](_0x1e2250[_0x5155('0x37')][_0x5155('0x3c')],_['omit'](_0x1e2250[_0x5155('0x37')],[_0x5155('0x3c'),'id'])||{})[_0x5155('0x4e')](function(){return db[_0x5155('0x4f')][_0x5155('0x4c')]({'attributes':['id','name','color'],'where':{'id':_0x1e2250[_0x5155('0x37')][_0x5155('0x3c')]}});})[_0x5155('0x1b')](function(_0x552baa){socket[_0x5155('0x50')](_0x5155('0x51'),{'id':Number(_0x1e2250[_0x5155('0x2b')]['id']),'tags':_0x552baa||[]});return{'id':Number(_0x1e2250[_0x5155('0x2b')]['id']),'tags':_0x552baa||[]};});}})[_0x5155('0x1b')](respondWithResult(_0x1c3c9b,null))['catch'](handleError(_0x1c3c9b,null));};exports[_0x5155('0x52')]=function(_0x267200,_0x16df62){return db['SmsInteraction'][_0x5155('0x35')]({'where':{'id':_0x267200[_0x5155('0x2b')]['id']}})[_0x5155('0x1b')](handleEntityNotFound(_0x16df62,null))[_0x5155('0x1b')](function(_0x428925){if(_0x428925){return _0x428925['removeTags'](_0x267200[_0x5155('0x28')][_0x5155('0x3c')]);}})[_0x5155('0x1b')](respondWithStatusCode(_0x16df62,null))[_0x5155('0x38')](handleError(_0x16df62,null));};exports['download']=function(_0x2227a3,_0x5579c0){var _0x1cf1e7=moment()['unix']()['toString']();var _0x4ff99a=path[_0x5155('0x53')](config['root'],_0x5155('0x54'),_0x5155('0x55'),_0x5155('0x56'));var _0x258f3c=path[_0x5155('0x53')](_0x4ff99a,_0x1cf1e7);var _0x41fa6a=util['format'](_0x5155('0x57'),_0x2227a3[_0x5155('0x2b')]['id'],_0x1cf1e7);var _0x28f9bc=path['join'](_0x4ff99a,_0x41fa6a);var _0x509ab9=[];_0x509ab9[_0x5155('0x58')]({'model':db['User'],'as':'User','attributes':['id',_0x5155('0x59')],'raw':!![]});_0x509ab9[_0x5155('0x58')]({'model':db[_0x5155('0x5a')],'as':_0x5155('0x5b'),'attributes':['id',_0x5155('0x5c'),_0x5155('0x5d')],'raw':!![]});var _0x47fc1f=[{'model':db[_0x5155('0x3f')],'as':_0x5155('0x5e'),'attributes':['id',_0x5155('0x37'),'createdAt','direction',_0x5155('0x5f'),_0x5155('0x60')],'include':_0x509ab9}];_0x47fc1f[_0x5155('0x58')]({'model':db[_0x5155('0x61')],'as':_0x5155('0x62'),'attributes':['id','name']});_0x47fc1f[_0x5155('0x58')]({'model':db[_0x5155('0x63')],'as':_0x5155('0x64'),'attributes':['id',_0x5155('0x59')]});return db[_0x5155('0x23')][_0x5155('0x35')]({'where':{'id':_0x2227a3[_0x5155('0x2b')]['id']},'include':_0x47fc1f})[_0x5155('0x1b')](handleEntityNotFound(_0x5579c0,null))[_0x5155('0x1b')](function(_0x507eb6){if(_0x507eb6){var _0x136cea=_0x507eb6[_0x5155('0x65')]({'plain':!![]});fs[_0x5155('0x66')](_0x258f3c);var _0x59853a={'channel':_0x5155('0x67'),'account':_0x136cea[_0x5155('0x62')][_0x5155('0x1f')],'agent':_0x136cea[_0x5155('0x64')]?_0x136cea[_0x5155('0x64')]['fullname']:_0x5155('0x68'),'createdAt':moment(_0x136cea[_0x5155('0x69')])['format'](_0x5155('0x4a'))[_0x5155('0x6a')](),'closedAt':_0x136cea[_0x5155('0x6b')]?moment(_0x136cea[_0x5155('0x6c')])[_0x5155('0x49')]('YYYY-MM-DD\x20HH:mm:ss')[_0x5155('0x6a')]():'','disposition':_0x136cea[_0x5155('0x6d')],'messages':_(_0x136cea[_0x5155('0x5e')])[_0x5155('0x46')]({'secret':![]})[_0x5155('0x22')](function(_0x482361){return{'date':moment(_0x482361[_0x5155('0x69')])['format'](_0x5155('0x4a'))[_0x5155('0x6a')](),'sender':_0x482361[_0x5155('0x6e')]==='out'?_0x482361[_0x5155('0x63')]?_0x482361[_0x5155('0x63')][_0x5155('0x59')]:_0x5155('0x6f'):_0x482361[_0x5155('0x5b')][_0x5155('0x5c')]+(_0x482361[_0x5155('0x5b')]['lastName']?'\x20'+_0x482361['Contact'][_0x5155('0x5d')]:''),'body':_0x482361[_0x5155('0x37')],'direction':_0x482361[_0x5155('0x6e')]===_0x5155('0x70')?'A':'C','secret':_0x482361[_0x5155('0x5f')],'read':_0x482361[_0x5155('0x60')]};})[_0x5155('0x71')]()};return ejs[_0x5155('0x72')](path[_0x5155('0x53')](config[_0x5155('0x73')],_0x5155('0x54'),'views',_0x5155('0x74')),{'interaction':_0x59853a})[_0x5155('0x1b')](function(_0x1132b8){var _0x4cdcdc=path['join'](_0x258f3c,'transcript-'+_0x136cea['id']+'-'+_0x1cf1e7+_0x5155('0x75'));var _0x4fdb2c={'path':_0x4cdcdc,'channel':_0x5155('0x67'),'interactionId':_0x136cea['id']};return pdf[_0x5155('0x76')](_0x1132b8,_0x4fdb2c);})[_0x5155('0x1b')](function(){return new BPromise(function(_0x4cd5e5,_0x2d7682){zipdir(_0x258f3c,{'saveTo':_0x28f9bc},function(_0x343cce,_0x4f9fda){if(_0x343cce)return _0x2d7682(_0x343cce);return _0x4cd5e5(_0x4f9fda);});})[_0x5155('0x1b')](function(){return new BPromise(function(_0x1ee4f5,_0xe206f5){rimraf(_0x258f3c,function(_0x1f484c){if(_0x1f484c)_0xe206f5(_0x1f484c);return _0x1ee4f5();});});})[_0x5155('0x1b')](function(){return _0x5579c0[_0x5155('0x77')](_0x28f9bc,_0x41fa6a,function(_0x399f56){if(_0x399f56){console[_0x5155('0x78')](_0x5155('0x79'),_0x399f56);}else{fs[_0x5155('0x7a')](_0x28f9bc);}});});});}else{return _0x5579c0[_0x5155('0x10')](0xc8);}})[_0x5155('0x38')](handleError(_0x5579c0,null));};
\ No newline at end of file