Built motion from commit b5a10faa.|2.6.13
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 96f112e..84f74ef 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf966=['secret','push','Account','Sms','Owner','N.A.','closed','closedAt','disposition','out','System','read','value','renderFile','downloadInteraction.ejs','transcript-','.pdf','log','unlinkSync','rimraf','zip-dir','moment','util','path','ejs','ioredis','../../components/interaction/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsInteraction.socket','register','status','json','offset','undefined','limit','count','Content-Range','destroy','end','sendStatus','error','stack','name','send','index','map','SmsInteraction','rawAttributes','fieldName','type','key','getOptions','findAll','sms','catch','show','params','model','keys','query','filters','intersection','attributes','fields','length','includeAll','include','merge','options','then','create','body','update','find','describe','addMessage','SmsMessage','ids','omit','getMessages','findOne','hasOwnProperty','nolimit','order','sort','where','pick','filter','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','addTags','setTags','spread','Tag','emit','removeTags','download','toString','join','root','server','files','tmp','transcript-%d-%s.zip','User','fullname','CmContact','Contact','firstName','lastName','Messages','createdAt','direction'];(function(_0x45dfb0,_0x2b4118){var _0x3c4a47=function(_0x58349c){while(--_0x58349c){_0x45dfb0['push'](_0x45dfb0['shift']());}};_0x3c4a47(++_0x2b4118);}(_0xf966,0x184));var _0x6f96=function(_0x1d6ba4,_0x39ac98){_0x1d6ba4=_0x1d6ba4-0x0;var _0x21a9cd=_0xf966[_0x1d6ba4];return _0x21a9cd;};'use strict';var rimraf=require(_0x6f96('0x0'));var zipdir=require(_0x6f96('0x1'));var moment=require(_0x6f96('0x2'));var BPromise=require('bluebird');var util=require(_0x6f96('0x3'));var path=require(_0x6f96('0x4'));var ejs=require(_0x6f96('0x5'));var fs=require('fs');var _=require('lodash');var Redis=require(_0x6f96('0x6'));var interaction=require(_0x6f96('0x7'));var qs=require(_0x6f96('0x8'));var pdf=require('../../components/export/pdf');var logger=require(_0x6f96('0x9'))(_0x6f96('0xa'));var config=require(_0x6f96('0xb'));var db=require(_0x6f96('0xc'))['db'];config[_0x6f96('0xd')]=_[_0x6f96('0xe')](config[_0x6f96('0xd')],{'host':_0x6f96('0xf'),'port':0x18eb});var socket=require(_0x6f96('0x10'))(new Redis(config[_0x6f96('0xd')]));require(_0x6f96('0x11'))[_0x6f96('0x12')](socket);function respondWithStatusCode(_0x1ec145,_0x32b642){_0x32b642=_0x32b642||0xcc;return function(_0x28a317){if(_0x28a317){return _0x1ec145['sendStatus'](_0x32b642);}return _0x1ec145[_0x6f96('0x13')](_0x32b642)['end']();};}function respondWithResult(_0x47fb80,_0x10b1fd){_0x10b1fd=_0x10b1fd||0xc8;return function(_0x358109){if(_0x358109){return _0x47fb80['status'](_0x10b1fd)[_0x6f96('0x14')](_0x358109);}};}function respondWithFilteredResult(_0x126b6a,_0x1dc6c2){return function(_0x1889e6){if(_0x1889e6){var _0x3689e3=typeof _0x1dc6c2[_0x6f96('0x15')]===_0x6f96('0x16')&&typeof _0x1dc6c2[_0x6f96('0x17')]==='undefined';var _0x3f8eb1=_0x1889e6[_0x6f96('0x18')];var _0x5a5602=_0x3689e3?0x0:_0x1dc6c2[_0x6f96('0x15')];var _0x2cd321=_0x3689e3?_0x1889e6['count']:_0x1dc6c2['offset']+_0x1dc6c2[_0x6f96('0x17')];var _0x3eb97e;if(_0x2cd321>=_0x3f8eb1){_0x2cd321=_0x3f8eb1;_0x3eb97e=0xc8;}else{_0x3eb97e=0xce;}_0x126b6a[_0x6f96('0x13')](_0x3eb97e);return _0x126b6a['set'](_0x6f96('0x19'),_0x5a5602+'-'+_0x2cd321+'/'+_0x3f8eb1)['json'](_0x1889e6);}return null;};}function saveUpdates(_0x19cd18){return function(_0x330d55){if(_0x330d55){return _0x330d55['update'](_0x19cd18)['then'](function(_0x75c2db){return _0x75c2db;});}return null;};}function removeEntity(_0x3d192b){return function(_0x593f91){if(_0x593f91){return _0x593f91[_0x6f96('0x1a')]()['then'](function(){_0x3d192b[_0x6f96('0x13')](0xcc)[_0x6f96('0x1b')]();});}};}function handleEntityNotFound(_0x1ef5e3){return function(_0x2515ca){if(!_0x2515ca){_0x1ef5e3[_0x6f96('0x1c')](0x194);}return _0x2515ca;};}function handleError(_0x5dc59b,_0x1d8dc7){_0x1d8dc7=_0x1d8dc7||0x1f4;return function(_0x5ec160){logger[_0x6f96('0x1d')](_0x5ec160[_0x6f96('0x1e')]);if(_0x5ec160['name']){delete _0x5ec160[_0x6f96('0x1f')];}_0x5dc59b['status'](_0x1d8dc7)[_0x6f96('0x20')](_0x5ec160);};}exports[_0x6f96('0x21')]=function(_0x542388,_0x2607b9){var _0x2a9cab={};var _0x21e93b=_[_0x6f96('0x22')](db[_0x6f96('0x23')][_0x6f96('0x24')],function(_0x4f33e7){return{'name':_0x4f33e7[_0x6f96('0x25')],'type':_0x4f33e7[_0x6f96('0x26')][_0x6f96('0x27')]};});_0x2a9cab=qs[_0x6f96('0x28')](_0x21e93b,_0x542388);return interaction[_0x6f96('0x29')](_0x6f96('0x2a'),_0x542388['query'],_0x542388['user'],_0x2a9cab,_0x21e93b)['then'](respondWithFilteredResult(_0x2607b9,_0x2a9cab))[_0x6f96('0x2b')](handleError(_0x2607b9,null));};exports[_0x6f96('0x2c')]=function(_0x37b404,_0x4821a8){var _0x19941b={'raw':![],'where':{'id':_0x37b404[_0x6f96('0x2d')]['id']}},_0x29c45e={};_0x29c45e[_0x6f96('0x2e')]=_[_0x6f96('0x2f')](db['SmsInteraction'][_0x6f96('0x24')]);_0x29c45e[_0x6f96('0x30')]=_['keys'](_0x37b404[_0x6f96('0x30')]);_0x29c45e[_0x6f96('0x31')]=_[_0x6f96('0x32')](_0x29c45e[_0x6f96('0x2e')],_0x29c45e[_0x6f96('0x30')]);_0x19941b[_0x6f96('0x33')]=_[_0x6f96('0x32')](_0x29c45e[_0x6f96('0x2e')],qs['fields'](_0x37b404[_0x6f96('0x30')][_0x6f96('0x34')]));_0x19941b[_0x6f96('0x33')]=_0x19941b[_0x6f96('0x33')][_0x6f96('0x35')]?_0x19941b[_0x6f96('0x33')]:_0x29c45e['model'];if(_0x37b404[_0x6f96('0x30')][_0x6f96('0x36')]){_0x19941b[_0x6f96('0x37')]=[{'all':!![]}];}_0x19941b=_[_0x6f96('0x38')]({},_0x19941b,_0x37b404[_0x6f96('0x39')]);return db[_0x6f96('0x23')]['find'](_0x19941b)[_0x6f96('0x3a')](handleEntityNotFound(_0x4821a8,null))['then'](respondWithResult(_0x4821a8,null))[_0x6f96('0x2b')](handleError(_0x4821a8,null));};exports[_0x6f96('0x3b')]=function(_0x4cbd50,_0x34b72f){return db['SmsInteraction'][_0x6f96('0x3b')](_0x4cbd50[_0x6f96('0x3c')],{})[_0x6f96('0x3a')](respondWithResult(_0x34b72f,0xc9))[_0x6f96('0x2b')](handleError(_0x34b72f,null));};exports[_0x6f96('0x3d')]=function(_0x3352e9,_0x530520){if(_0x3352e9['body']['id']){delete _0x3352e9[_0x6f96('0x3c')]['id'];}return db['SmsInteraction'][_0x6f96('0x3e')]({'where':{'id':_0x3352e9['params']['id']}})[_0x6f96('0x3a')](handleEntityNotFound(_0x530520,null))[_0x6f96('0x3a')](saveUpdates(_0x3352e9[_0x6f96('0x3c')],null))[_0x6f96('0x3a')](respondWithResult(_0x530520,null))[_0x6f96('0x2b')](handleError(_0x530520,null));};exports[_0x6f96('0x1a')]=function(_0x57dd3f,_0x1d8fab){return db[_0x6f96('0x23')][_0x6f96('0x3e')]({'where':{'id':_0x57dd3f[_0x6f96('0x2d')]['id']}})['then'](handleEntityNotFound(_0x1d8fab,null))[_0x6f96('0x3a')](removeEntity(_0x1d8fab,null))[_0x6f96('0x2b')](handleError(_0x1d8fab,null));};exports[_0x6f96('0x3f')]=function(_0x2fa5a1,_0x5299de){return db[_0x6f96('0x23')][_0x6f96('0x3f')]()[_0x6f96('0x3a')](respondWithResult(_0x5299de,null))[_0x6f96('0x2b')](handleError(_0x5299de,null));};exports[_0x6f96('0x40')]=function(_0x4449d3,_0x32851a){return db[_0x6f96('0x41')][_0x6f96('0x3e')]({'where':{'id':_0x4449d3[_0x6f96('0x2d')]['id']}})['then'](handleEntityNotFound(_0x32851a,null))[_0x6f96('0x3a')](function(_0x59cf8f){if(_0x59cf8f){return _0x59cf8f['addMessage'](_0x4449d3[_0x6f96('0x3c')][_0x6f96('0x42')],_[_0x6f96('0x43')](_0x4449d3[_0x6f96('0x3c')],[_0x6f96('0x42'),'id'])||{});}})['then'](respondWithResult(_0x32851a,null))[_0x6f96('0x2b')](handleError(_0x32851a,null));};exports[_0x6f96('0x44')]=function(_0x38058c,_0x2e4ce6){var _0x56dbe9={'raw':![],'where':{}};var _0x88ae60={};var _0x2dd7a4={'count':0x0,'rows':[]};return db[_0x6f96('0x23')][_0x6f96('0x45')]({'where':{'id':_0x38058c['params']['id']}})[_0x6f96('0x3a')](handleEntityNotFound(_0x2e4ce6,null))[_0x6f96('0x3a')](function(_0x184d38){if(_0x184d38){_0x88ae60[_0x6f96('0x2e')]=_[_0x6f96('0x2f')](db[_0x6f96('0x41')][_0x6f96('0x24')]);_0x88ae60[_0x6f96('0x30')]=_['keys'](_0x38058c['query']);_0x88ae60[_0x6f96('0x31')]=_[_0x6f96('0x32')](_0x88ae60[_0x6f96('0x2e')],_0x88ae60[_0x6f96('0x30')]);_0x56dbe9[_0x6f96('0x33')]=_['intersection'](_0x88ae60[_0x6f96('0x2e')],qs[_0x6f96('0x34')](_0x38058c[_0x6f96('0x30')][_0x6f96('0x34')]));_0x56dbe9[_0x6f96('0x33')]=_0x56dbe9[_0x6f96('0x33')][_0x6f96('0x35')]?_0x56dbe9[_0x6f96('0x33')]:_0x88ae60[_0x6f96('0x2e')];if(!_0x38058c[_0x6f96('0x30')][_0x6f96('0x46')](_0x6f96('0x47'))){_0x56dbe9[_0x6f96('0x17')]=qs[_0x6f96('0x17')](_0x38058c[_0x6f96('0x30')][_0x6f96('0x17')]);_0x56dbe9[_0x6f96('0x15')]=qs[_0x6f96('0x15')](_0x38058c['query'][_0x6f96('0x15')]);}_0x56dbe9[_0x6f96('0x48')]=qs['sort'](_0x38058c[_0x6f96('0x30')][_0x6f96('0x49')]);_0x56dbe9[_0x6f96('0x4a')]=qs['filters'](_[_0x6f96('0x4b')](_0x38058c[_0x6f96('0x30')],_0x88ae60['filters']));_0x56dbe9[_0x6f96('0x4a')]['SmsInteractionId']=_0x184d38['id'];if(_0x38058c['query'][_0x6f96('0x4c')]){_0x56dbe9[_0x6f96('0x4a')]=_[_0x6f96('0x38')](_0x56dbe9[_0x6f96('0x4a')],{'$or':_[_0x6f96('0x22')](_0x56dbe9[_0x6f96('0x33')],function(_0x5e0dd8){var _0x4fc754={};_0x4fc754[_0x5e0dd8]={'$like':'%'+_0x38058c[_0x6f96('0x30')][_0x6f96('0x4c')]+'%'};return _0x4fc754;})});}if(_0x38058c[_0x6f96('0x30')][_0x6f96('0x4d')]){var _0x3ef5a3=_0x38058c[_0x6f96('0x30')]['$gte'][_0x6f96('0x4e')](',');var _0x4e36a7={};_0x4e36a7[_0x3ef5a3[0x0]]={'$gte':moment(_0x3ef5a3[0x1])[_0x6f96('0x4f')](_0x6f96('0x50'))};_0x56dbe9[_0x6f96('0x4a')]=_[_0x6f96('0x38')](_0x56dbe9[_0x6f96('0x4a')],_0x4e36a7);}_0x56dbe9=_[_0x6f96('0x38')]({},_0x56dbe9,_0x38058c['options']);return db[_0x6f96('0x41')]['count']({'where':_0x56dbe9[_0x6f96('0x4a')]})['then'](function(_0x550d6a){_0x2dd7a4[_0x6f96('0x18')]=_0x550d6a;if(_0x38058c[_0x6f96('0x30')][_0x6f96('0x36')]){_0x56dbe9[_0x6f96('0x37')]=[{'all':!![]}];}return db['SmsMessage'][_0x6f96('0x29')](_0x56dbe9);})[_0x6f96('0x3a')](function(_0x1721e5){_0x2dd7a4['rows']=_0x1721e5;return _0x2dd7a4;});}})[_0x6f96('0x3a')](respondWithFilteredResult(_0x2e4ce6,_0x56dbe9))[_0x6f96('0x2b')](handleError(_0x2e4ce6,null));};exports[_0x6f96('0x51')]=function(_0x396a7a,_0x524c74){return db['SmsInteraction']['find']({'where':{'id':_0x396a7a[_0x6f96('0x2d')]['id']}})['then'](handleEntityNotFound(_0x524c74,null))['then'](function(_0x5876be){if(_0x5876be){return _0x5876be[_0x6f96('0x52')](_0x396a7a['body']['ids'],_['omit'](_0x396a7a[_0x6f96('0x3c')],['ids','id'])||{})[_0x6f96('0x53')](function(){return db[_0x6f96('0x54')][_0x6f96('0x29')]({'attributes':['id','name','color'],'where':{'id':_0x396a7a[_0x6f96('0x3c')][_0x6f96('0x42')]}});})[_0x6f96('0x3a')](function(_0x182a3a){socket[_0x6f96('0x55')]('smsInteractionTags:save',{'id':Number(_0x396a7a['params']['id']),'tags':_0x182a3a||[]});return{'id':Number(_0x396a7a[_0x6f96('0x2d')]['id']),'tags':_0x182a3a||[]};});}})[_0x6f96('0x3a')](respondWithResult(_0x524c74,null))[_0x6f96('0x2b')](handleError(_0x524c74,null));};exports[_0x6f96('0x56')]=function(_0x28b585,_0x236ded){return db[_0x6f96('0x23')]['find']({'where':{'id':_0x28b585[_0x6f96('0x2d')]['id']}})['then'](handleEntityNotFound(_0x236ded,null))['then'](function(_0x5a14d2){if(_0x5a14d2){return _0x5a14d2[_0x6f96('0x56')](_0x28b585[_0x6f96('0x30')][_0x6f96('0x42')]);}})[_0x6f96('0x3a')](respondWithStatusCode(_0x236ded,null))['catch'](handleError(_0x236ded,null));};exports[_0x6f96('0x57')]=function(_0x4c3778,_0x406ff3){var _0x2eed3a=moment()['unix']()[_0x6f96('0x58')]();var _0x3b0f2d=path[_0x6f96('0x59')](config[_0x6f96('0x5a')],_0x6f96('0x5b'),_0x6f96('0x5c'),_0x6f96('0x5d'));var _0x552e4b=path[_0x6f96('0x59')](_0x3b0f2d,_0x2eed3a);var _0x31ea85=util[_0x6f96('0x4f')](_0x6f96('0x5e'),_0x4c3778[_0x6f96('0x2d')]['id'],_0x2eed3a);var _0x1d7530=path[_0x6f96('0x59')](_0x3b0f2d,_0x31ea85);var _0x4c96b6=[];_0x4c96b6['push']({'model':db[_0x6f96('0x5f')],'as':_0x6f96('0x5f'),'attributes':['id',_0x6f96('0x60')],'raw':!![]});_0x4c96b6['push']({'model':db[_0x6f96('0x61')],'as':_0x6f96('0x62'),'attributes':['id',_0x6f96('0x63'),_0x6f96('0x64')],'raw':!![]});var _0x48b34e=[{'model':db[_0x6f96('0x41')],'as':_0x6f96('0x65'),'attributes':['id',_0x6f96('0x3c'),_0x6f96('0x66'),_0x6f96('0x67'),_0x6f96('0x68'),'read'],'include':_0x4c96b6}];_0x48b34e[_0x6f96('0x69')]({'model':db['SmsAccount'],'as':_0x6f96('0x6a'),'attributes':['id',_0x6f96('0x1f')]});_0x48b34e['push']({'model':db[_0x6f96('0x5f')],'as':'Owner','attributes':['id','fullname']});return db['SmsInteraction'][_0x6f96('0x3e')]({'where':{'id':_0x4c3778[_0x6f96('0x2d')]['id']},'include':_0x48b34e})['then'](handleEntityNotFound(_0x406ff3,null))['then'](function(_0x454339){if(_0x454339){var _0x57bd27=_0x454339['get']({'plain':!![]});fs['mkdirSync'](_0x552e4b);var _0x36950b={'channel':_0x6f96('0x6b'),'account':_0x57bd27[_0x6f96('0x6a')][_0x6f96('0x1f')],'agent':_0x57bd27[_0x6f96('0x6c')]?_0x57bd27[_0x6f96('0x6c')][_0x6f96('0x60')]:_0x6f96('0x6d'),'createdAt':moment(_0x57bd27[_0x6f96('0x66')])[_0x6f96('0x4f')](_0x6f96('0x50'))[_0x6f96('0x58')](),'closedAt':_0x57bd27[_0x6f96('0x6e')]?moment(_0x57bd27[_0x6f96('0x6f')])['format'](_0x6f96('0x50'))['toString']():'','disposition':_0x57bd27[_0x6f96('0x70')],'messages':_(_0x57bd27['Messages'])[_0x6f96('0x4c')]({'secret':![]})[_0x6f96('0x22')](function(_0x2f1dac){return{'date':moment(_0x2f1dac['createdAt'])[_0x6f96('0x4f')](_0x6f96('0x50'))['toString'](),'sender':_0x2f1dac[_0x6f96('0x67')]===_0x6f96('0x71')?_0x2f1dac[_0x6f96('0x5f')]?_0x2f1dac['User'][_0x6f96('0x60')]:_0x6f96('0x72'):_0x2f1dac[_0x6f96('0x62')]['firstName']+(_0x2f1dac[_0x6f96('0x62')][_0x6f96('0x64')]?'\x20'+_0x2f1dac[_0x6f96('0x62')][_0x6f96('0x64')]:''),'body':_0x2f1dac[_0x6f96('0x3c')],'direction':_0x2f1dac[_0x6f96('0x67')]==='out'?'A':'C','secret':_0x2f1dac[_0x6f96('0x68')],'read':_0x2f1dac[_0x6f96('0x73')]};})[_0x6f96('0x74')]()};return ejs[_0x6f96('0x75')](path['join'](config[_0x6f96('0x5a')],_0x6f96('0x5b'),'views',_0x6f96('0x76')),{'interaction':_0x36950b})[_0x6f96('0x3a')](function(_0x3af029){var _0x3a9904=path[_0x6f96('0x59')](_0x552e4b,_0x6f96('0x77')+_0x57bd27['id']+'-'+_0x2eed3a+_0x6f96('0x78'));var _0x1b7734={'path':_0x3a9904,'channel':_0x6f96('0x6b'),'interactionId':_0x57bd27['id']};return pdf['createPdfFromHTML'](_0x3af029,_0x1b7734);})['then'](function(){return new BPromise(function(_0x2b92eb,_0x184c62){zipdir(_0x552e4b,{'saveTo':_0x1d7530},function(_0x12b89a,_0x48d230){if(_0x12b89a)return _0x184c62(_0x12b89a);return _0x2b92eb(_0x48d230);});})[_0x6f96('0x3a')](function(){return new BPromise(function(_0x4d9016,_0x37c745){rimraf(_0x552e4b,function(_0x52f30d){if(_0x52f30d)_0x37c745(_0x52f30d);return _0x4d9016();});});})['then'](function(){return _0x406ff3['download'](_0x1d7530,_0x31ea85,function(_0x4552a2){if(_0x4552a2){console[_0x6f96('0x79')]('err',_0x4552a2);}else{fs[_0x6f96('0x7a')](_0x1d7530);}});});});}else{return _0x406ff3['sendStatus'](0xc8);}})[_0x6f96('0x2b')](handleError(_0x406ff3,null));};
\ No newline at end of file
+var _0x3f59=['attributes','nolimit','limit','order','sort','where','filters','SmsInteractionId','filter','$gte','format','YYYY-MM-DD\x20HH:mm:ss','rows','addTags','setTags','spread','Tag','color','emit','smsInteractionTags:save','removeTags','download','unix','toString','join','root','server','push','User','fullname','CmContact','Contact','lastName','Messages','createdAt','secret','read','SmsAccount','Owner','get','mkdirSync','Account','N.A.','closedAt','disposition','map','System','firstName','direction','out','value','renderFile','views','downloadInteraction.ejs','transcript-','.pdf','log','unlinkSync','zip-dir','moment','bluebird','util','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','../../config/environment','redis','localhost','./smsInteraction.socket','register','sendStatus','end','status','offset','undefined','count','set','Content-Range','json','update','then','destroy','error','stack','name','SmsInteraction','rawAttributes','fieldName','type','key','getOptions','findAll','sms','query','user','show','params','model','keys','intersection','fields','length','includeAll','merge','options','find','catch','create','body','describe','addMessage','SmsMessage','ids','omit','getMessages'];(function(_0x31a576,_0x424419){var _0x30b1d3=function(_0x4710e8){while(--_0x4710e8){_0x31a576['push'](_0x31a576['shift']());}};_0x30b1d3(++_0x424419);}(_0x3f59,0x12a));var _0x93f5=function(_0x4fa0f9,_0x5027c8){_0x4fa0f9=_0x4fa0f9-0x0;var _0x496eb0=_0x3f59[_0x4fa0f9];return _0x496eb0;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0x93f5('0x0'));var moment=require(_0x93f5('0x1'));var BPromise=require(_0x93f5('0x2'));var util=require(_0x93f5('0x3'));var path=require(_0x93f5('0x4'));var ejs=require(_0x93f5('0x5'));var fs=require('fs');var _=require(_0x93f5('0x6'));var Redis=require(_0x93f5('0x7'));var interaction=require(_0x93f5('0x8'));var qs=require(_0x93f5('0x9'));var pdf=require(_0x93f5('0xa'));var logger=require(_0x93f5('0xb'))('api');var config=require(_0x93f5('0xc'));var db=require('../../mysqldb')['db'];config[_0x93f5('0xd')]=_['defaults'](config[_0x93f5('0xd')],{'host':_0x93f5('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x93f5('0xd')]));require(_0x93f5('0xf'))[_0x93f5('0x10')](socket);function respondWithStatusCode(_0x35abaf,_0x4e0b5d){_0x4e0b5d=_0x4e0b5d||0xcc;return function(_0xde944a){if(_0xde944a){return _0x35abaf[_0x93f5('0x11')](_0x4e0b5d);}return _0x35abaf['status'](_0x4e0b5d)[_0x93f5('0x12')]();};}function respondWithResult(_0x2823e2,_0x33b54c){_0x33b54c=_0x33b54c||0xc8;return function(_0x3963ba){if(_0x3963ba){return _0x2823e2[_0x93f5('0x13')](_0x33b54c)['json'](_0x3963ba);}};}function respondWithFilteredResult(_0x153f2c,_0x1a8aff){return function(_0xc511fc){if(_0xc511fc){var _0x17bc09=typeof _0x1a8aff[_0x93f5('0x14')]===_0x93f5('0x15')&&typeof _0x1a8aff['limit']===_0x93f5('0x15');var _0x2960d9=_0xc511fc['count'];var _0x356609=_0x17bc09?0x0:_0x1a8aff[_0x93f5('0x14')];var _0x2b04dc=_0x17bc09?_0xc511fc[_0x93f5('0x16')]:_0x1a8aff[_0x93f5('0x14')]+_0x1a8aff['limit'];var _0x2ba62d;if(_0x2b04dc>=_0x2960d9){_0x2b04dc=_0x2960d9;_0x2ba62d=0xc8;}else{_0x2ba62d=0xce;}_0x153f2c[_0x93f5('0x13')](_0x2ba62d);return _0x153f2c[_0x93f5('0x17')](_0x93f5('0x18'),_0x356609+'-'+_0x2b04dc+'/'+_0x2960d9)[_0x93f5('0x19')](_0xc511fc);}return null;};}function saveUpdates(_0xce8f15){return function(_0x2db45c){if(_0x2db45c){return _0x2db45c[_0x93f5('0x1a')](_0xce8f15)[_0x93f5('0x1b')](function(_0x3f3c79){return _0x3f3c79;});}return null;};}function removeEntity(_0x2615d1){return function(_0x1501fd){if(_0x1501fd){return _0x1501fd[_0x93f5('0x1c')]()[_0x93f5('0x1b')](function(){_0x2615d1[_0x93f5('0x13')](0xcc)['end']();});}};}function handleEntityNotFound(_0x442ed8){return function(_0x1ebb5c){if(!_0x1ebb5c){_0x442ed8[_0x93f5('0x11')](0x194);}return _0x1ebb5c;};}function handleError(_0x57548e,_0x30c5a8){_0x30c5a8=_0x30c5a8||0x1f4;return function(_0x480530){logger[_0x93f5('0x1d')](_0x480530[_0x93f5('0x1e')]);if(_0x480530['name']){delete _0x480530[_0x93f5('0x1f')];}_0x57548e[_0x93f5('0x13')](_0x30c5a8)['send'](_0x480530);};}exports['index']=function(_0x3bb941,_0x3b2ee0){var _0x57fe35={};var _0x35c1fc=_['map'](db[_0x93f5('0x20')][_0x93f5('0x21')],function(_0x5d4fa7){return{'name':_0x5d4fa7[_0x93f5('0x22')],'type':_0x5d4fa7[_0x93f5('0x23')][_0x93f5('0x24')]};});_0x57fe35=qs[_0x93f5('0x25')](_0x35c1fc,_0x3bb941);return interaction[_0x93f5('0x26')](_0x93f5('0x27'),_0x3bb941[_0x93f5('0x28')],_0x3bb941[_0x93f5('0x29')],_0x57fe35,_0x35c1fc)[_0x93f5('0x1b')](respondWithFilteredResult(_0x3b2ee0,_0x57fe35))['catch'](handleError(_0x3b2ee0,null));};exports[_0x93f5('0x2a')]=function(_0x49c3c6,_0x2da7d6){var _0x40f593={'raw':![],'where':{'id':_0x49c3c6[_0x93f5('0x2b')]['id']}},_0x52b509={};_0x52b509[_0x93f5('0x2c')]=_[_0x93f5('0x2d')](db[_0x93f5('0x20')]['rawAttributes']);_0x52b509[_0x93f5('0x28')]=_[_0x93f5('0x2d')](_0x49c3c6[_0x93f5('0x28')]);_0x52b509['filters']=_[_0x93f5('0x2e')](_0x52b509['model'],_0x52b509['query']);_0x40f593['attributes']=_['intersection'](_0x52b509[_0x93f5('0x2c')],qs[_0x93f5('0x2f')](_0x49c3c6['query']['fields']));_0x40f593['attributes']=_0x40f593['attributes'][_0x93f5('0x30')]?_0x40f593['attributes']:_0x52b509[_0x93f5('0x2c')];if(_0x49c3c6[_0x93f5('0x28')][_0x93f5('0x31')]){_0x40f593['include']=[{'all':!![]}];}_0x40f593=_[_0x93f5('0x32')]({},_0x40f593,_0x49c3c6[_0x93f5('0x33')]);return db[_0x93f5('0x20')][_0x93f5('0x34')](_0x40f593)[_0x93f5('0x1b')](handleEntityNotFound(_0x2da7d6,null))['then'](respondWithResult(_0x2da7d6,null))[_0x93f5('0x35')](handleError(_0x2da7d6,null));};exports[_0x93f5('0x36')]=function(_0x15721c,_0x2052fd){return db[_0x93f5('0x20')][_0x93f5('0x36')](_0x15721c[_0x93f5('0x37')],{})[_0x93f5('0x1b')](respondWithResult(_0x2052fd,0xc9))[_0x93f5('0x35')](handleError(_0x2052fd,null));};exports[_0x93f5('0x1a')]=function(_0x5674d4,_0xbbec6f){if(_0x5674d4[_0x93f5('0x37')]['id']){delete _0x5674d4['body']['id'];}return db[_0x93f5('0x20')]['find']({'where':{'id':_0x5674d4[_0x93f5('0x2b')]['id']}})['then'](handleEntityNotFound(_0xbbec6f,null))[_0x93f5('0x1b')](saveUpdates(_0x5674d4['body'],null))[_0x93f5('0x1b')](respondWithResult(_0xbbec6f,null))['catch'](handleError(_0xbbec6f,null));};exports[_0x93f5('0x1c')]=function(_0x4a27d7,_0x32c3e1){return db['SmsInteraction'][_0x93f5('0x34')]({'where':{'id':_0x4a27d7['params']['id']}})[_0x93f5('0x1b')](handleEntityNotFound(_0x32c3e1,null))[_0x93f5('0x1b')](removeEntity(_0x32c3e1,null))['catch'](handleError(_0x32c3e1,null));};exports[_0x93f5('0x38')]=function(_0xf22415,_0x4dad47){return db[_0x93f5('0x20')][_0x93f5('0x38')]()[_0x93f5('0x1b')](respondWithResult(_0x4dad47,null))[_0x93f5('0x35')](handleError(_0x4dad47,null));};exports[_0x93f5('0x39')]=function(_0x2f5c40,_0x5a44dc){return db[_0x93f5('0x3a')][_0x93f5('0x34')]({'where':{'id':_0x2f5c40[_0x93f5('0x2b')]['id']}})[_0x93f5('0x1b')](handleEntityNotFound(_0x5a44dc,null))[_0x93f5('0x1b')](function(_0x334801){if(_0x334801){return _0x334801[_0x93f5('0x39')](_0x2f5c40[_0x93f5('0x37')][_0x93f5('0x3b')],_[_0x93f5('0x3c')](_0x2f5c40[_0x93f5('0x37')],[_0x93f5('0x3b'),'id'])||{});}})[_0x93f5('0x1b')](respondWithResult(_0x5a44dc,null))[_0x93f5('0x35')](handleError(_0x5a44dc,null));};exports[_0x93f5('0x3d')]=function(_0x2f3ccd,_0x5bb33f){var _0x62c23a={'raw':![],'where':{}};var _0x32f94e={};var _0x31faec={'count':0x0,'rows':[]};return db['SmsInteraction']['findOne']({'where':{'id':_0x2f3ccd[_0x93f5('0x2b')]['id']}})['then'](handleEntityNotFound(_0x5bb33f,null))[_0x93f5('0x1b')](function(_0xa85094){if(_0xa85094){_0x32f94e[_0x93f5('0x2c')]=_['keys'](db[_0x93f5('0x3a')]['rawAttributes']);_0x32f94e['query']=_[_0x93f5('0x2d')](_0x2f3ccd[_0x93f5('0x28')]);_0x32f94e['filters']=_[_0x93f5('0x2e')](_0x32f94e[_0x93f5('0x2c')],_0x32f94e[_0x93f5('0x28')]);_0x62c23a['attributes']=_['intersection'](_0x32f94e[_0x93f5('0x2c')],qs[_0x93f5('0x2f')](_0x2f3ccd[_0x93f5('0x28')][_0x93f5('0x2f')]));_0x62c23a[_0x93f5('0x3e')]=_0x62c23a['attributes']['length']?_0x62c23a['attributes']:_0x32f94e[_0x93f5('0x2c')];if(!_0x2f3ccd['query']['hasOwnProperty'](_0x93f5('0x3f'))){_0x62c23a[_0x93f5('0x40')]=qs[_0x93f5('0x40')](_0x2f3ccd[_0x93f5('0x28')][_0x93f5('0x40')]);_0x62c23a[_0x93f5('0x14')]=qs[_0x93f5('0x14')](_0x2f3ccd[_0x93f5('0x28')][_0x93f5('0x14')]);}_0x62c23a[_0x93f5('0x41')]=qs[_0x93f5('0x42')](_0x2f3ccd[_0x93f5('0x28')][_0x93f5('0x42')]);_0x62c23a[_0x93f5('0x43')]=qs['filters'](_['pick'](_0x2f3ccd[_0x93f5('0x28')],_0x32f94e[_0x93f5('0x44')]));_0x62c23a[_0x93f5('0x43')][_0x93f5('0x45')]=_0xa85094['id'];if(_0x2f3ccd[_0x93f5('0x28')][_0x93f5('0x46')]){_0x62c23a[_0x93f5('0x43')]=_[_0x93f5('0x32')](_0x62c23a[_0x93f5('0x43')],{'$or':_['map'](_0x62c23a[_0x93f5('0x3e')],function(_0x2da666){var _0x45bcc1={};_0x45bcc1[_0x2da666]={'$like':'%'+_0x2f3ccd[_0x93f5('0x28')][_0x93f5('0x46')]+'%'};return _0x45bcc1;})});}if(_0x2f3ccd[_0x93f5('0x28')][_0x93f5('0x47')]){var _0x28f117=_0x2f3ccd[_0x93f5('0x28')][_0x93f5('0x47')]['split'](',');var _0x2df57e={};_0x2df57e[_0x28f117[0x0]]={'$gte':moment(_0x28f117[0x1])[_0x93f5('0x48')](_0x93f5('0x49'))};_0x62c23a[_0x93f5('0x43')]=_['merge'](_0x62c23a[_0x93f5('0x43')],_0x2df57e);}_0x62c23a=_['merge']({},_0x62c23a,_0x2f3ccd['options']);return db[_0x93f5('0x3a')][_0x93f5('0x16')]({'where':_0x62c23a[_0x93f5('0x43')]})[_0x93f5('0x1b')](function(_0x215005){_0x31faec['count']=_0x215005;if(_0x2f3ccd[_0x93f5('0x28')][_0x93f5('0x31')]){_0x62c23a['include']=[{'all':!![]}];}return db[_0x93f5('0x3a')][_0x93f5('0x26')](_0x62c23a);})[_0x93f5('0x1b')](function(_0x1f1415){_0x31faec[_0x93f5('0x4a')]=_0x1f1415;return _0x31faec;});}})[_0x93f5('0x1b')](respondWithFilteredResult(_0x5bb33f,_0x62c23a))[_0x93f5('0x35')](handleError(_0x5bb33f,null));};exports[_0x93f5('0x4b')]=function(_0x7c0bf3,_0x28600a){return db[_0x93f5('0x20')][_0x93f5('0x34')]({'where':{'id':_0x7c0bf3['params']['id']}})['then'](handleEntityNotFound(_0x28600a,null))['then'](function(_0x1235d7){if(_0x1235d7){return _0x1235d7[_0x93f5('0x4c')](_0x7c0bf3[_0x93f5('0x37')]['ids'],_[_0x93f5('0x3c')](_0x7c0bf3[_0x93f5('0x37')],[_0x93f5('0x3b'),'id'])||{})[_0x93f5('0x4d')](function(){return db[_0x93f5('0x4e')][_0x93f5('0x26')]({'attributes':['id','name',_0x93f5('0x4f')],'where':{'id':_0x7c0bf3[_0x93f5('0x37')][_0x93f5('0x3b')]}});})[_0x93f5('0x1b')](function(_0x54b5ba){socket[_0x93f5('0x50')](_0x93f5('0x51'),{'id':Number(_0x7c0bf3[_0x93f5('0x2b')]['id']),'tags':_0x54b5ba||[]});return{'id':Number(_0x7c0bf3[_0x93f5('0x2b')]['id']),'tags':_0x54b5ba||[]};});}})[_0x93f5('0x1b')](respondWithResult(_0x28600a,null))['catch'](handleError(_0x28600a,null));};exports['removeTags']=function(_0x378d11,_0x45aa47){return db[_0x93f5('0x20')][_0x93f5('0x34')]({'where':{'id':_0x378d11[_0x93f5('0x2b')]['id']}})[_0x93f5('0x1b')](handleEntityNotFound(_0x45aa47,null))[_0x93f5('0x1b')](function(_0x3d5c6c){if(_0x3d5c6c){return _0x3d5c6c[_0x93f5('0x52')](_0x378d11[_0x93f5('0x28')][_0x93f5('0x3b')]);}})['then'](respondWithStatusCode(_0x45aa47,null))[_0x93f5('0x35')](handleError(_0x45aa47,null));};exports[_0x93f5('0x53')]=function(_0x408194,_0x10178a){var _0x5b0a7c=moment()[_0x93f5('0x54')]()[_0x93f5('0x55')]();var _0x88a7e7=path[_0x93f5('0x56')](config[_0x93f5('0x57')],_0x93f5('0x58'),'files','tmp');var _0x2fa35a=path[_0x93f5('0x56')](_0x88a7e7,_0x5b0a7c);var _0x51dd8e=util[_0x93f5('0x48')]('transcript-%d-%s.zip',_0x408194[_0x93f5('0x2b')]['id'],_0x5b0a7c);var _0x58cd3d=path['join'](_0x88a7e7,_0x51dd8e);var _0x25a8c8=[];_0x25a8c8[_0x93f5('0x59')]({'model':db[_0x93f5('0x5a')],'as':_0x93f5('0x5a'),'attributes':['id',_0x93f5('0x5b')],'raw':!![]});_0x25a8c8['push']({'model':db[_0x93f5('0x5c')],'as':_0x93f5('0x5d'),'attributes':['id','firstName',_0x93f5('0x5e')],'raw':!![]});var _0x37707e=[{'model':db[_0x93f5('0x3a')],'as':_0x93f5('0x5f'),'attributes':['id','body',_0x93f5('0x60'),'direction',_0x93f5('0x61'),_0x93f5('0x62')],'include':_0x25a8c8}];_0x37707e[_0x93f5('0x59')]({'model':db[_0x93f5('0x63')],'as':'Account','attributes':['id',_0x93f5('0x1f')]});_0x37707e['push']({'model':db['User'],'as':_0x93f5('0x64'),'attributes':['id','fullname']});return db['SmsInteraction'][_0x93f5('0x34')]({'where':{'id':_0x408194[_0x93f5('0x2b')]['id']},'include':_0x37707e})[_0x93f5('0x1b')](handleEntityNotFound(_0x10178a,null))[_0x93f5('0x1b')](function(_0x23ccc8){if(_0x23ccc8){var _0x1e9bd0=_0x23ccc8[_0x93f5('0x65')]({'plain':!![]});fs[_0x93f5('0x66')](_0x2fa35a);var _0x20d823={'channel':'Sms','account':_0x1e9bd0[_0x93f5('0x67')]['name'],'agent':_0x1e9bd0['Owner']?_0x1e9bd0[_0x93f5('0x64')][_0x93f5('0x5b')]:_0x93f5('0x68'),'createdAt':moment(_0x1e9bd0[_0x93f5('0x60')])[_0x93f5('0x48')](_0x93f5('0x49'))[_0x93f5('0x55')](),'closedAt':_0x1e9bd0['closed']?moment(_0x1e9bd0[_0x93f5('0x69')])['format']('YYYY-MM-DD\x20HH:mm:ss')[_0x93f5('0x55')]():'','disposition':_0x1e9bd0[_0x93f5('0x6a')],'messages':_(_0x1e9bd0[_0x93f5('0x5f')])[_0x93f5('0x46')]({'secret':![]})[_0x93f5('0x6b')](function(_0x142595){return{'date':moment(_0x142595[_0x93f5('0x60')])[_0x93f5('0x48')](_0x93f5('0x49'))[_0x93f5('0x55')](),'sender':_0x142595['direction']==='out'?_0x142595['User']?_0x142595[_0x93f5('0x5a')]['fullname']:_0x93f5('0x6c'):_0x142595[_0x93f5('0x5d')][_0x93f5('0x6d')]+(_0x142595[_0x93f5('0x5d')][_0x93f5('0x5e')]?'\x20'+_0x142595[_0x93f5('0x5d')][_0x93f5('0x5e')]:''),'body':_0x142595[_0x93f5('0x37')],'direction':_0x142595[_0x93f5('0x6e')]===_0x93f5('0x6f')?'A':'C','secret':_0x142595[_0x93f5('0x61')],'read':_0x142595[_0x93f5('0x62')]};})[_0x93f5('0x70')]()};return ejs[_0x93f5('0x71')](path[_0x93f5('0x56')](config[_0x93f5('0x57')],'server',_0x93f5('0x72'),_0x93f5('0x73')),{'interaction':_0x20d823})[_0x93f5('0x1b')](function(_0x8e88a8){var _0x1f17a6=path[_0x93f5('0x56')](_0x2fa35a,_0x93f5('0x74')+_0x1e9bd0['id']+'-'+_0x5b0a7c+_0x93f5('0x75'));var _0x3cfc1c={'path':_0x1f17a6,'channel':'Sms','interactionId':_0x1e9bd0['id']};return pdf['createPdfFromHTML'](_0x8e88a8,_0x3cfc1c);})['then'](function(){return new BPromise(function(_0x5be9f3,_0x2ea0f1){zipdir(_0x2fa35a,{'saveTo':_0x58cd3d},function(_0x2c4ab1,_0x404b0e){if(_0x2c4ab1)return _0x2ea0f1(_0x2c4ab1);return _0x5be9f3(_0x404b0e);});})['then'](function(){return new BPromise(function(_0x23635d,_0x34e1e9){rimraf(_0x2fa35a,function(_0x35f4f0){if(_0x35f4f0)_0x34e1e9(_0x35f4f0);return _0x23635d();});});})[_0x93f5('0x1b')](function(){return _0x10178a[_0x93f5('0x53')](_0x58cd3d,_0x51dd8e,function(_0x3e9d0d){if(_0x3e9d0d){console[_0x93f5('0x76')]('err',_0x3e9d0d);}else{fs[_0x93f5('0x77')](_0x58cd3d);}});});});}else{return _0x10178a['sendStatus'](0xc8);}})[_0x93f5('0x35')](handleError(_0x10178a,null));};
\ No newline at end of file