Built motion from commit (unavailable).|2.3.4
[motion2.git] / server / api / chatInteraction / chatInteraction.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xb010=['attributes','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','map','type','key','field','options','include','push','Tag','Tags','tag','distinct','read','ChatMessage','direction','then','includeAll','User','Users','CmContact','Owner','fullname','internal','ChatWebsite','Account','Messages','createdAt','color','catch','show','params','find','create','body','describe','customUpdate','abandon','entity\x20not\x20found','closed','disposition','AbandonInteraction','file','originalname','basename','filename','mimetype','Attachment','attachmentDownload','Unauthorized','findOne','attachId','download','root','server/files/attachments/','close','mailTranscript','join','server/files/chat/upload/','format','transcript-%s.txt','now','pathTranscript','ChatWebsiteId','UserId','%s%d','agentAlias','System','customer','Visitor','ContactId','agentIdentifier','website_alias','agent_alias','alias','agent_fullname','[%s]\x20%s:\x20%s\x0a','MM/DD/YYYY\x20HH:mm:ss','secret','MailAccount','Smtp','service','host','port','secure','authentication','auth','user','pass','SendMail','sendMail','\x22%s\x22\x20<%s>','email','Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a','addMessage','rawAttributes','ChatInteractionId','$gte','split','YYYY-MM-DD\x20HH:mm:ss','findAll','rows','order','includeAgent','addTags','setTags','omit','ids','spread','emit','chatInteractionTags:save','removeTags','unix','toString','server','files','tmp','attachments','Contact','firstName','Letter','1cm','mkdirSync','<h1>Chat\x20Interaction:\x20#%d</h1>','MMMM\x20Do\x20YYYY,\x20HH:mm:ss','<hr>','<div\x20style=\x22border-style:\x20solid;\x20border-width:\x201px;\x20margin:\x203px;\x22>','existsSync','createReadStream','pipe','.pdf','unlinkSync','eml-format','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../config/license/hardware','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./chatInteraction.socket','register','client','http','request','info','ChatInteraction,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','sendStatus','status','end','json','count','offset','limit','set','Content-Range','reject','save','update','destroy','name','send','index','ChatInteraction','keys','query','filters','model','intersection','fields'];(function(_0x436f06,_0x11c990){var _0x3f66a2=function(_0x4ae430){while(--_0x4ae430){_0x436f06['push'](_0x436f06['shift']());}};_0x3f66a2(++_0x11c990);}(_0xb010,0x8b));var _0x0b01=function(_0x178e48,_0x3c9509){_0x178e48=_0x178e48-0x0;var _0x440d7e=_0xb010[_0x178e48];return _0x440d7e;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x0b01('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x0b01('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x0b01('0x2'));var moment=require('moment');var BPromise=require(_0x0b01('0x3'));var Mustache=require(_0x0b01('0x4'));var util=require(_0x0b01('0x5'));var path=require(_0x0b01('0x6'));var sox=require(_0x0b01('0x7'));var csv=require(_0x0b01('0x8'));var ejs=require(_0x0b01('0x9'));var fs=require('fs');var _=require(_0x0b01('0xa'));var squel=require(_0x0b01('0xb'));var crypto=require(_0x0b01('0xc'));var jsforce=require(_0x0b01('0xd'));var deskjs=require(_0x0b01('0xe'));var toCsv=require(_0x0b01('0x8'));var querystring=require('querystring');var Papa=require(_0x0b01('0xf'));var authService=require(_0x0b01('0x10'));var hardwareService=require(_0x0b01('0x11'));var Redis=require(_0x0b01('0x12'));var qs=require(_0x0b01('0x13'));var logger=require(_0x0b01('0x14'))(_0x0b01('0x15'));var utils=require(_0x0b01('0x16'));var config=require(_0x0b01('0x17'));var db=require(_0x0b01('0x18'))['db'];config['redis']=_[_0x0b01('0x19')](config[_0x0b01('0x1a')],{'host':_0x0b01('0x1b'),'port':0x18eb});var socket=require(_0x0b01('0x1c'))(new Redis(config[_0x0b01('0x1a')]));require(_0x0b01('0x1d'))[_0x0b01('0x1e')](socket);var jayson=require('jayson/promise');var client=jayson[_0x0b01('0x1f')][_0x0b01('0x20')]({'port':0x232b});var client9004=jayson[_0x0b01('0x1f')][_0x0b01('0x20')]({'port':0x232c});function respondWithRpcPromise(_0x4074c2,_0x2448a4,_0x24c0d4,_0x2348ef){return new BPromise(function(_0x9a813d,_0x15bfdf){var _0x458baf=_0x2348ef||client;return _0x458baf[_0x0b01('0x21')](_0x4074c2,_0x24c0d4)['then'](function(_0x2f399c){logger[_0x0b01('0x22')](_0x0b01('0x23'),_0x2448a4,'request\x20sent');logger['debug']('ChatInteraction,\x20%s,\x20%s,\x20%s',_0x2448a4,_0x0b01('0x24'),JSON[_0x0b01('0x25')](_0x2f399c));if(_0x2f399c[_0x0b01('0x26')]){if(_0x2f399c[_0x0b01('0x26')][_0x0b01('0x27')]===0x1f4){logger[_0x0b01('0x26')]('ChatInteraction,\x20%s,\x20%s',_0x2448a4,_0x2f399c[_0x0b01('0x26')][_0x0b01('0x28')]);return _0x15bfdf(_0x2f399c[_0x0b01('0x26')][_0x0b01('0x28')]);}logger[_0x0b01('0x26')]('ChatInteraction,\x20%s,\x20%s',_0x2448a4,_0x2f399c['error'][_0x0b01('0x28')]);return _0x9a813d(_0x2f399c[_0x0b01('0x26')][_0x0b01('0x28')]);}else{logger[_0x0b01('0x22')]('ChatInteraction,\x20%s,\x20%s',_0x2448a4,'request\x20sent');_0x9a813d(_0x2f399c['result'][_0x0b01('0x28')]);}})['catch'](function(_0x4af9f6){logger['error'](_0x0b01('0x23'),_0x2448a4,_0x4af9f6);_0x15bfdf(_0x4af9f6);});});}function respondWithStatusCode(_0x80c47,_0xed5e34){_0xed5e34=_0xed5e34||0xcc;return function(_0xf9fbfc){if(_0xf9fbfc){return _0x80c47[_0x0b01('0x29')](_0xed5e34);}return _0x80c47[_0x0b01('0x2a')](_0xed5e34)[_0x0b01('0x2b')]();};}function respondWithResult(_0xdaaf81,_0x5cff03){_0x5cff03=_0x5cff03||0xc8;return function(_0xe33073){if(_0xe33073){return _0xdaaf81[_0x0b01('0x2a')](_0x5cff03)[_0x0b01('0x2c')](_0xe33073);}};}function respondWithFilteredResult(_0x513f07,_0x53b17a){return function(_0x29799c){if(_0x29799c){var _0x4b1e21=_0x29799c[_0x0b01('0x2d')],_0x48f7a6=_0x53b17a['offset'],_0x40f202=_0x53b17a[_0x0b01('0x2e')]+_0x53b17a[_0x0b01('0x2f')],_0x3c9e5e;if(_0x40f202>=_0x4b1e21){_0x40f202=_0x4b1e21;_0x3c9e5e=0xc8;}else{_0x3c9e5e=0xce;}_0x513f07[_0x0b01('0x2a')](_0x3c9e5e);return _0x513f07[_0x0b01('0x30')](_0x0b01('0x31'),_0x48f7a6+'-'+_0x40f202+'/'+_0x4b1e21)[_0x0b01('0x2c')](_0x29799c);}return null;};}function patchUpdates(_0x41e532){return function(_0x13b534){try{jsonpatch['apply'](_0x13b534,_0x41e532,!![]);}catch(_0x3bb0b0){return BPromise[_0x0b01('0x32')](_0x3bb0b0);}return _0x13b534[_0x0b01('0x33')]();};}function saveUpdates(_0x494313,_0x2aa19d){return function(_0x526d91){if(_0x526d91){return _0x526d91[_0x0b01('0x34')](_0x494313)['then'](function(_0x1eaf31){return _0x1eaf31;});}return null;};}function removeEntity(_0x479a46,_0x418d78){return function(_0x1100fc){if(_0x1100fc){return _0x1100fc[_0x0b01('0x35')]()['then'](function(){_0x479a46[_0x0b01('0x2a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x7704d3,_0x98fe04){return function(_0x584c59){if(!_0x584c59){_0x7704d3[_0x0b01('0x29')](0x194);}return _0x584c59;};}function handleError(_0x5236d7,_0x5dc1d4){_0x5dc1d4=_0x5dc1d4||0x1f4;return function(_0x5b7743){logger[_0x0b01('0x26')](_0x5b7743['stack']);if(_0x5b7743[_0x0b01('0x36')]){delete _0x5b7743['name'];}_0x5236d7[_0x0b01('0x2a')](_0x5dc1d4)[_0x0b01('0x37')](_0x5b7743);};}exports[_0x0b01('0x38')]=function(_0x120a10,_0x16c26e){var _0x596534={},_0x5cfba3={},_0x2304b6={'count':0x0,'rows':[]};var _0x3c0dc3=db[_0x0b01('0x39')]['rawAttributes'];_0x5cfba3['model']=_[_0x0b01('0x3a')](_0x3c0dc3);_0x5cfba3['query']=_[_0x0b01('0x3a')](_0x120a10[_0x0b01('0x3b')]);_0x5cfba3[_0x0b01('0x3c')]=_['intersection'](_0x5cfba3[_0x0b01('0x3d')],_0x5cfba3[_0x0b01('0x3b')]);_0x596534['attributes']=_[_0x0b01('0x3e')](_0x5cfba3[_0x0b01('0x3d')],qs[_0x0b01('0x3f')](_0x120a10[_0x0b01('0x3b')][_0x0b01('0x3f')]));_0x596534[_0x0b01('0x40')]=_0x596534[_0x0b01('0x40')][_0x0b01('0x41')]?_0x596534['attributes']:_0x5cfba3[_0x0b01('0x3d')];if(!_0x120a10[_0x0b01('0x3b')][_0x0b01('0x42')](_0x0b01('0x43'))){_0x596534['limit']=qs[_0x0b01('0x2f')](_0x120a10[_0x0b01('0x3b')][_0x0b01('0x2f')]);_0x596534[_0x0b01('0x2e')]=qs[_0x0b01('0x2e')](_0x120a10['query']['offset']);}_0x596534['order']=qs[_0x0b01('0x44')](_0x120a10[_0x0b01('0x3b')][_0x0b01('0x44')]);_0x596534[_0x0b01('0x45')]=qs[_0x0b01('0x3c')](_[_0x0b01('0x46')](_0x120a10[_0x0b01('0x3b')],_0x5cfba3[_0x0b01('0x3c')]));if(_0x120a10[_0x0b01('0x3b')][_0x0b01('0x47')]){_0x596534[_0x0b01('0x45')]=_[_0x0b01('0x48')](_0x596534[_0x0b01('0x45')],{'$or':_[_0x0b01('0x49')](_0x3c0dc3,function(_0x581160){if(_0x581160[_0x0b01('0x4a')][_0x0b01('0x4b')]!=='VIRTUAL'){var _0x194f29={};_0x194f29[_0x581160[_0x0b01('0x4c')]]={'$like':'%'+_0x120a10[_0x0b01('0x3b')]['filter']+'%'};return _0x194f29;}})});}_0x596534=_[_0x0b01('0x48')]({},_0x596534,_0x120a10[_0x0b01('0x4d')]);var _0x38f213={'where':_0x596534['where']};_0x38f213[_0x0b01('0x4e')]=[];if(_0x120a10[_0x0b01('0x3b')]['tag']){_0x38f213['include'][_0x0b01('0x4f')]({'model':db[_0x0b01('0x50')],'as':_0x0b01('0x51'),'attributes':['id'],'where':{'id':_0x120a10['query'][_0x0b01('0x52')]},'required':!![]});_0x38f213[_0x0b01('0x53')]=!![];}if(_0x120a10[_0x0b01('0x3b')][_0x0b01('0x54')]){_0x38f213[_0x0b01('0x4e')]['push']({'model':db[_0x0b01('0x55')],'as':'Messages','attributes':['id',_0x0b01('0x56'),'createdAt','read'],'where':{'direction':'in','read':_0x120a10['query'][_0x0b01('0x54')]||![]},'required':!![]});_0x38f213['distinct']=!![];}return db[_0x0b01('0x39')][_0x0b01('0x2d')](_0x38f213)[_0x0b01('0x57')](function(_0x1932d9){_0x2304b6[_0x0b01('0x2d')]=_0x1932d9;if(_0x120a10['query'][_0x0b01('0x58')]){_0x596534['include']=[{'model':db[_0x0b01('0x59')],'as':_0x0b01('0x5a'),'required':![],'attributes':['id','name','fullname']},{'model':db[_0x0b01('0x5b')],'as':'Contact','required':![]},{'model':db[_0x0b01('0x59')],'as':_0x0b01('0x5c'),'attributes':[_0x0b01('0x36'),_0x0b01('0x5d'),_0x0b01('0x5e')],'required':![]},{'model':db[_0x0b01('0x5f')],'as':_0x0b01('0x60'),'attributes':[_0x0b01('0x36'),_0x0b01('0x4b')],'required':![]},{'model':db[_0x0b01('0x55')],'as':_0x0b01('0x61'),'attributes':['id','direction',_0x0b01('0x62'),_0x0b01('0x54')],'where':{'direction':'in','read':_0x120a10[_0x0b01('0x3b')]['read']||![]},'required':_0x120a10[_0x0b01('0x3b')]['read']||![]},{'model':db[_0x0b01('0x50')],'as':_0x0b01('0x51'),'attributes':['id',_0x0b01('0x36'),'color'],'required':_0x120a10[_0x0b01('0x3b')][_0x0b01('0x52')]?!![]:![]},{'model':db[_0x0b01('0x50')],'as':'ThroughTags','attributes':['id',_0x0b01('0x36'),_0x0b01('0x63')],'through':_0x120a10['query'][_0x0b01('0x52')]?{'attributes':[],'where':{'TagId':_0x120a10[_0x0b01('0x3b')][_0x0b01('0x52')]||undefined}}:{},'required':_0x120a10['query'][_0x0b01('0x52')]?!![]:![]}];}return db[_0x0b01('0x39')]['findAll'](_0x596534);})[_0x0b01('0x57')](function(_0x1102d8){_0x2304b6['rows']=_0x1102d8;return _0x2304b6;})[_0x0b01('0x57')](respondWithFilteredResult(_0x16c26e,_0x596534))[_0x0b01('0x64')](handleError(_0x16c26e,null));};exports[_0x0b01('0x65')]=function(_0x54eb2c,_0x17d335){var _0x41cb00={'raw':![],'where':{'id':_0x54eb2c[_0x0b01('0x66')]['id']}},_0x15fa46={};_0x15fa46[_0x0b01('0x3d')]=_['keys'](db[_0x0b01('0x39')]['rawAttributes']);_0x15fa46[_0x0b01('0x3b')]=_[_0x0b01('0x3a')](_0x54eb2c[_0x0b01('0x3b')]);_0x15fa46[_0x0b01('0x3c')]=_[_0x0b01('0x3e')](_0x15fa46[_0x0b01('0x3d')],_0x15fa46[_0x0b01('0x3b')]);_0x41cb00[_0x0b01('0x40')]=_['intersection'](_0x15fa46[_0x0b01('0x3d')],qs[_0x0b01('0x3f')](_0x54eb2c[_0x0b01('0x3b')]['fields']));_0x41cb00['attributes']=_0x41cb00['attributes'][_0x0b01('0x41')]?_0x41cb00[_0x0b01('0x40')]:_0x15fa46['model'];if(_0x54eb2c[_0x0b01('0x3b')][_0x0b01('0x58')]){_0x41cb00[_0x0b01('0x4e')]=[{'all':!![]}];}_0x41cb00=_[_0x0b01('0x48')]({},_0x41cb00,_0x54eb2c['options']);return db['ChatInteraction'][_0x0b01('0x67')](_0x41cb00)[_0x0b01('0x57')](handleEntityNotFound(_0x17d335,null))[_0x0b01('0x57')](respondWithResult(_0x17d335,null))[_0x0b01('0x64')](handleError(_0x17d335,null));};exports[_0x0b01('0x68')]=function(_0x1ae7d2,_0x55d1e0){return db[_0x0b01('0x39')]['create'](_0x1ae7d2[_0x0b01('0x69')],{})[_0x0b01('0x57')](respondWithResult(_0x55d1e0,0xc9))[_0x0b01('0x64')](handleError(_0x55d1e0,null));};exports[_0x0b01('0x34')]=function(_0x1fd0ab,_0x473f51){if(_0x1fd0ab['body']['id']){delete _0x1fd0ab[_0x0b01('0x69')]['id'];}return db[_0x0b01('0x39')]['find']({'where':{'id':_0x1fd0ab[_0x0b01('0x66')]['id']}})[_0x0b01('0x57')](handleEntityNotFound(_0x473f51,null))[_0x0b01('0x57')](saveUpdates(_0x1fd0ab['body'],null))[_0x0b01('0x57')](respondWithResult(_0x473f51,null))[_0x0b01('0x64')](handleError(_0x473f51,null));};exports[_0x0b01('0x35')]=function(_0xb8fedd,_0x3a19dd){return db[_0x0b01('0x39')][_0x0b01('0x67')]({'where':{'id':_0xb8fedd[_0x0b01('0x66')]['id']}})[_0x0b01('0x57')](handleEntityNotFound(_0x3a19dd,null))['then'](removeEntity(_0x3a19dd,null))[_0x0b01('0x64')](handleError(_0x3a19dd,null));};exports['describe']=function(_0x2e835f,_0x3833cf){return db['ChatInteraction'][_0x0b01('0x6a')]()[_0x0b01('0x57')](respondWithResult(_0x3833cf,null))['catch'](handleError(_0x3833cf,null));};exports[_0x0b01('0x6b')]=function(_0x39446d,_0x143ac0){if(_0x39446d['body']['id']){delete _0x39446d[_0x0b01('0x69')]['id'];}return db[_0x0b01('0x39')]['find']({'where':{'id':_0x39446d['params']['id']}})[_0x0b01('0x57')](handleEntityNotFound(_0x143ac0,null))[_0x0b01('0x57')](saveUpdates(_0x39446d[_0x0b01('0x69')],null))[_0x0b01('0x57')](respondWithResult(_0x143ac0,null))['catch'](handleError(_0x143ac0,null));};exports[_0x0b01('0x6c')]=function(_0x589a0b,_0xa1073c,_0x1eb05b){if(_0x589a0b[_0x0b01('0x69')]['id']){delete _0x589a0b[_0x0b01('0x69')]['id'];}return db[_0x0b01('0x39')][_0x0b01('0x67')]({'where':{'id':_0x589a0b[_0x0b01('0x66')]['id']}})[_0x0b01('0x57')](function(_0x381dc3){if(!_0x381dc3){logger[_0x0b01('0x26')]('abandonInteraction,\x20%s,\x20%s,\x20%s',_0x0b01('0x6c'),0x194,_0x0b01('0x6d'));_0xa1073c[_0x0b01('0x29')](0x194);}else{if(_0x381dc3['UserId']){throw new db['Sequelize']['ValidationError']('Interaction\x20already\x20assigned');}}return _0x381dc3;})[_0x0b01('0x57')](function(_0x66465a){if(_0x66465a){return _0x66465a['update']({'closed':_0x589a0b['body'][_0x0b01('0x6e')],'disposition':_0x589a0b['body'][_0x0b01('0x6f')]})[_0x0b01('0x57')](function(_0x4e6d8d){return _0x4e6d8d;});}})[_0x0b01('0x57')](function(_0x4a2a03){return respondWithRpcPromise(_0x0b01('0x70'),_0x0b01('0x6c'),_0x589a0b[_0x0b01('0x69')],client9004);})[_0x0b01('0x57')](respondWithResult(_0xa1073c,null))['catch'](handleError(_0xa1073c,null));};exports['attachmentUpload']=function(_0x4520b1,_0x57b7c0,_0x33be18){_0x4520b1['body'][_0x0b01('0x36')]=_0x4520b1[_0x0b01('0x71')][_0x0b01('0x72')];_0x4520b1['body'][_0x0b01('0x73')]=_0x4520b1[_0x0b01('0x71')][_0x0b01('0x74')];_0x4520b1[_0x0b01('0x69')][_0x0b01('0x4a')]=_0x4520b1['file'][_0x0b01('0x75')];return db[_0x0b01('0x76')][_0x0b01('0x68')](_0x4520b1['body'])['then'](respondWithResult(_0x57b7c0,0xc9))['catch'](handleError(_0x57b7c0,null));};exports[_0x0b01('0x77')]=function(_0x1c2535,_0xdcccb9,_0x28a706){return db['ChatInteraction']['findOne']({'where':{'id':_0x1c2535[_0x0b01('0x66')]['id']},'raw':!![]})['then'](handleEntityNotFound(_0xdcccb9,null))['then'](function(_0x330404){if(_0x330404){if(_0x330404[_0x0b01('0x6e')]){return _0xdcccb9[_0x0b01('0x2a')](0x193)[_0x0b01('0x2c')]({'status':0x193,'message':_0x0b01('0x78')});}return db[_0x0b01('0x76')][_0x0b01('0x79')]({'where':{'id':_0x1c2535['query'][_0x0b01('0x7a')]},'raw':!![]})[_0x0b01('0x57')](handleEntityNotFound(_0xdcccb9,null));}})['then'](function(_0x57223d){if(_0x57223d){return _0xdcccb9[_0x0b01('0x7b')](path['join'](config[_0x0b01('0x7c')],_0x0b01('0x7d'),_0x57223d[_0x0b01('0x73')]));}})[_0x0b01('0x64')](handleError(_0xdcccb9,null));};exports[_0x0b01('0x7e')]=function(_0x2f45e0,_0x592a71){var _0x5bbe95=null;var _0x3949e4=null;var _0x2bc03d=null;var _0x45a4fc=null;if(_0x2f45e0[_0x0b01('0x69')]['id']){delete _0x2f45e0[_0x0b01('0x69')]['id'];}if(_0x2f45e0[_0x0b01('0x69')][_0x0b01('0x7f')]){_0x45a4fc=path[_0x0b01('0x80')](config[_0x0b01('0x7c')],_0x0b01('0x81'),util[_0x0b01('0x82')](_0x0b01('0x83'),Date[_0x0b01('0x84')]()));_0x2f45e0['body'][_0x0b01('0x85')]=_0x45a4fc;}return db[_0x0b01('0x39')][_0x0b01('0x67')]({'where':{'id':_0x2f45e0[_0x0b01('0x66')]['id']},'include':[{'model':db[_0x0b01('0x55')],'as':'Messages','include':[{'model':db['User'],'as':_0x0b01('0x59')}]}]})[_0x0b01('0x57')](handleEntityNotFound(_0x592a71,null))['then'](saveUpdates(_0x2f45e0[_0x0b01('0x69')],null))[_0x0b01('0x57')](function(_0x10eb8f){if(_0x10eb8f){_0x5bbe95=_0x10eb8f;return db[_0x0b01('0x5f')][_0x0b01('0x67')]({'where':{'id':_0x5bbe95[_0x0b01('0x86')]}});}})[_0x0b01('0x57')](function(_0xcd8b17){if(_0xcd8b17){_0x2bc03d=_0xcd8b17;return db[_0x0b01('0x5b')][_0x0b01('0x67')]({'where':{'id':_0x5bbe95['ContactId']}});}})[_0x0b01('0x57')](function(_0x108c3a){if(_0x108c3a){_0x3949e4=_0x108c3a;if(_0x45a4fc){var _0x4e69af=null;for(var _0x372d57=0x1;_0x372d57<_0x5bbe95[_0x0b01('0x61')][_0x0b01('0x41')];++_0x372d57){_0x4e69af=_0x5bbe95[_0x0b01('0x61')][_0x372d57];var _0x1e4aa4=_0x4e69af[_0x0b01('0x87')]?util['format'](_0x0b01('0x88'),_0x2bc03d[_0x0b01('0x89')],_0x4e69af[_0x0b01('0x87')]):_0x0b01('0x8a');var _0x53373b=_0x2f45e0[_0x0b01('0x69')][_0x0b01('0x8b')]||util[_0x0b01('0x82')](_0x0b01('0x88'),_0x0b01('0x8c'),_0x4e69af[_0x0b01('0x8d')]);switch(_0x2bc03d[_0x0b01('0x8e')]){case _0x0b01('0x8f'):_0x1e4aa4=_0x4e69af[_0x0b01('0x87')]?util[_0x0b01('0x82')]('%s%d',_0x2bc03d['agentAlias'],_0x4e69af[_0x0b01('0x87')]):_0x0b01('0x8a');break;case _0x0b01('0x90'):_0x1e4aa4=_0x4e69af[_0x0b01('0x87')]?_0x4e69af[_0x0b01('0x59')][_0x0b01('0x91')]||_0x4e69af[_0x0b01('0x59')][_0x0b01('0x5d')]:'System';break;case _0x0b01('0x92'):_0x1e4aa4=_0x4e69af[_0x0b01('0x87')]?_0x4e69af['User']['fullname']:_0x0b01('0x8a');break;default:_0x1e4aa4=_0x4e69af[_0x0b01('0x87')]?util['format'](_0x0b01('0x88'),_0x2bc03d['agentAlias'],_0x4e69af[_0x0b01('0x87')]):_0x0b01('0x8a');}var _0xf59c3a=util['format'](_0x0b01('0x93'),moment(_0x4e69af[_0x0b01('0x62')])[_0x0b01('0x82')](_0x0b01('0x94')),_0x4e69af['direction']==='in'?_0x53373b:_0x1e4aa4,_0x4e69af['body']);if(!_0x4e69af[_0x0b01('0x95')]){fs['appendFileSync'](_0x45a4fc,_0xf59c3a);}}return db[_0x0b01('0x96')][_0x0b01('0x79')]({'where':{'service':!![]},'include':[{'model':db['MailServerOut'],'as':_0x0b01('0x97'),'raw':!![]}]});}}})[_0x0b01('0x57')](function(_0x330204){if(_0x330204&&_0x330204[_0x0b01('0x97')]&&_0x2f45e0['body']){var _0x37a2ca={'tls':{'rejectUnauthorized':![]}};if(_0x330204['Smtp']['service']){_0x37a2ca['service']=_0x330204[_0x0b01('0x97')][_0x0b01('0x98')];}else{_0x37a2ca[_0x0b01('0x99')]=_0x330204['Smtp'][_0x0b01('0x99')];_0x37a2ca[_0x0b01('0x9a')]=_0x330204['Smtp']['port'];_0x37a2ca[_0x0b01('0x9b')]=_0x330204[_0x0b01('0x97')]['secure'];}if(_0x330204[_0x0b01('0x97')][_0x0b01('0x9c')]){_0x37a2ca[_0x0b01('0x9d')]={'user':_0x330204[_0x0b01('0x97')][_0x0b01('0x9e')],'pass':_0x330204[_0x0b01('0x97')][_0x0b01('0x9f')]};}return respondWithRpcPromise(_0x0b01('0xa0'),_0x0b01('0xa1'),{'account':_0x37a2ca,'message':{'from':util['format'](_0x0b01('0xa2'),_0x330204[_0x0b01('0x36')],_0x330204[_0x0b01('0xa3')]||_0x330204[_0x0b01('0x97')]['user']),'to':_0x2f45e0['body'][_0x0b01('0x7f')],'subject':'Mail\x20Transcript','text':util['format'](_0x0b01('0xa4'),_0x2f45e0[_0x0b01('0x69')]['mailTranscript']),'attachments':[{'path':_0x45a4fc}]}})[_0x0b01('0x57')](function(){return _0x5bbe95;})[_0x0b01('0x64')](function(_0x583e33){console[_0x0b01('0x26')](_0x583e33);});}else{return _0x5bbe95;}})['then'](respondWithStatusCode(_0x592a71,0xc8))[_0x0b01('0x64')](handleError(_0x592a71,null));};exports[_0x0b01('0xa5')]=function(_0x1cd059,_0x6953fe,_0x5cbdb7){return db['ChatMessage'][_0x0b01('0x67')]({'where':{'id':_0x1cd059[_0x0b01('0x66')]['id']}})[_0x0b01('0x57')](handleEntityNotFound(_0x6953fe,null))[_0x0b01('0x57')](function(_0x411c2e){if(_0x411c2e){return _0x411c2e[_0x0b01('0xa5')](_0x1cd059[_0x0b01('0x69')]['ids'],_['omit'](_0x1cd059[_0x0b01('0x69')],['ids','id'])||{});}})[_0x0b01('0x57')](respondWithResult(_0x6953fe,null))[_0x0b01('0x64')](handleError(_0x6953fe,null));};exports['getMessages']=function(_0x179aab,_0x602b53,_0x2d71d3){var _0x29ac3f={'raw':![],'where':{}};var _0x345443={};var _0x2215fb={'count':0x0,'rows':[]};return db[_0x0b01('0x39')][_0x0b01('0x79')]({'where':{'id':_0x179aab[_0x0b01('0x66')]['id']}})[_0x0b01('0x57')](handleEntityNotFound(_0x602b53,null))['then'](function(_0x148e86){if(_0x148e86){_0x345443[_0x0b01('0x3d')]=_[_0x0b01('0x3a')](db[_0x0b01('0x55')][_0x0b01('0xa6')]);_0x345443[_0x0b01('0x3b')]=_[_0x0b01('0x3a')](_0x179aab[_0x0b01('0x3b')]);_0x345443[_0x0b01('0x3c')]=_[_0x0b01('0x3e')](_0x345443[_0x0b01('0x3d')],_0x345443[_0x0b01('0x3b')]);_0x29ac3f[_0x0b01('0x40')]=_[_0x0b01('0x3e')](_0x345443[_0x0b01('0x3d')],qs['fields'](_0x179aab[_0x0b01('0x3b')][_0x0b01('0x3f')]));_0x29ac3f[_0x0b01('0x40')]=_0x29ac3f['attributes'][_0x0b01('0x41')]?_0x29ac3f['attributes']:_0x345443['model'];if(!_0x179aab[_0x0b01('0x3b')]['hasOwnProperty']('nolimit')){_0x29ac3f['limit']=qs[_0x0b01('0x2f')](_0x179aab['query'][_0x0b01('0x2f')]);_0x29ac3f['offset']=qs[_0x0b01('0x2e')](_0x179aab['query']['offset']);}_0x29ac3f['order']=qs[_0x0b01('0x44')](_0x179aab[_0x0b01('0x3b')][_0x0b01('0x44')]);_0x29ac3f[_0x0b01('0x45')]=qs[_0x0b01('0x3c')](_[_0x0b01('0x46')](_0x179aab[_0x0b01('0x3b')],_0x345443[_0x0b01('0x3c')]));_0x29ac3f['where'][_0x0b01('0xa7')]=_0x148e86['id'];if(_0x179aab[_0x0b01('0x3b')][_0x0b01('0x47')]){_0x29ac3f[_0x0b01('0x45')]=_['merge'](_0x29ac3f[_0x0b01('0x45')],{'$or':_[_0x0b01('0x49')](_0x29ac3f[_0x0b01('0x40')],function(_0x45f4f2){var _0x567684={};_0x567684[_0x45f4f2]={'$like':'%'+_0x179aab['query'][_0x0b01('0x47')]+'%'};return _0x567684;})});}if(_0x179aab[_0x0b01('0x3b')][_0x0b01('0xa8')]){var _0x4409ed=_0x179aab['query'][_0x0b01('0xa8')][_0x0b01('0xa9')](',');var _0x37227f={};_0x37227f[_0x4409ed[0x0]]={'$gte':moment(_0x4409ed[0x1])[_0x0b01('0x82')](_0x0b01('0xaa'))};_0x29ac3f[_0x0b01('0x45')]=_['merge'](_0x29ac3f[_0x0b01('0x45')],_0x37227f);}_0x29ac3f=_[_0x0b01('0x48')]({},_0x29ac3f,_0x179aab[_0x0b01('0x4d')]);return db[_0x0b01('0x55')]['count']({'where':_0x29ac3f[_0x0b01('0x45')]})[_0x0b01('0x57')](function(_0x5706a3){_0x2215fb[_0x0b01('0x2d')]=_0x5706a3;if(_0x179aab['query']['includeAll']){_0x29ac3f[_0x0b01('0x4e')]=[{'all':!![]}];}return db[_0x0b01('0x55')][_0x0b01('0xab')](_0x29ac3f);})[_0x0b01('0x57')](function(_0x1388d3){_0x2215fb[_0x0b01('0xac')]=_0x1388d3;return _0x2215fb;});}})[_0x0b01('0x57')](respondWithFilteredResult(_0x602b53,_0x29ac3f))[_0x0b01('0x64')](handleError(_0x602b53,null));};exports['getMyMessages']=function(_0x35ecb7,_0x2fc363,_0x590399){var _0x8fe815={'where':{}},_0x400c04={},_0x415689={'count':0x0,'rows':[]};return db[_0x0b01('0x39')]['findOne']({'where':{'id':_0x35ecb7[_0x0b01('0x66')]['id']}})[_0x0b01('0x57')](handleEntityNotFound(_0x2fc363,null))[_0x0b01('0x57')](function(_0x14bc17){if(_0x14bc17){_0x400c04[_0x0b01('0x3d')]=_[_0x0b01('0x3a')](db[_0x0b01('0x55')][_0x0b01('0xa6')]);_0x400c04[_0x0b01('0x3b')]=_[_0x0b01('0x3a')](_0x35ecb7[_0x0b01('0x3b')]);_0x400c04[_0x0b01('0x3c')]=_[_0x0b01('0x3e')](_0x400c04[_0x0b01('0x3d')],_0x400c04[_0x0b01('0x3b')]);_0x8fe815[_0x0b01('0x40')]=_[_0x0b01('0x3e')](_0x400c04[_0x0b01('0x3d')],qs[_0x0b01('0x3f')](_0x35ecb7['query'][_0x0b01('0x3f')]));_0x8fe815[_0x0b01('0x40')]=_0x8fe815['attributes'][_0x0b01('0x41')]?_0x8fe815[_0x0b01('0x40')]:_0x400c04[_0x0b01('0x3d')];if(!_0x35ecb7['query'][_0x0b01('0x42')]('nolimit')){_0x8fe815[_0x0b01('0x2f')]=qs[_0x0b01('0x2f')](_0x35ecb7['query'][_0x0b01('0x2f')]);_0x8fe815[_0x0b01('0x2e')]=qs['offset'](_0x35ecb7[_0x0b01('0x3b')]['offset']);}_0x8fe815[_0x0b01('0xad')]=qs[_0x0b01('0x44')](_0x35ecb7[_0x0b01('0x3b')][_0x0b01('0x44')]);_0x8fe815[_0x0b01('0x45')]=qs[_0x0b01('0x3c')](_[_0x0b01('0x46')](_0x35ecb7['query'],_0x400c04[_0x0b01('0x3c')]));_0x8fe815[_0x0b01('0x45')][_0x0b01('0xa7')]=_0x14bc17['id'];if(_0x35ecb7['query'][_0x0b01('0x47')]){_0x8fe815[_0x0b01('0x45')]=_['merge'](_0x8fe815[_0x0b01('0x45')],{'$or':_[_0x0b01('0x49')](_0x8fe815[_0x0b01('0x40')],function(_0x448831){var _0x8f6cf1={};_0x8f6cf1[_0x448831]={'$like':'%'+_0x35ecb7[_0x0b01('0x3b')][_0x0b01('0x47')]+'%'};return _0x8f6cf1;})});}_0x8fe815[_0x0b01('0x45')][_0x0b01('0x95')]=![];if(_0x35ecb7[_0x0b01('0x3b')]['id']){_0x8fe815[_0x0b01('0x45')]['id']={'$gt':_0x35ecb7['query']['id']};}_0x8fe815=_['merge']({},_0x8fe815,_0x35ecb7['options']);return db[_0x0b01('0x55')][_0x0b01('0x2d')]({'where':_0x8fe815[_0x0b01('0x45')]})[_0x0b01('0x57')](function(_0x200857){_0x415689[_0x0b01('0x2d')]=_0x200857;_0x8fe815[_0x0b01('0x4e')]=[];if(_0x35ecb7[_0x0b01('0x3b')][_0x0b01('0xae')]){_0x8fe815[_0x0b01('0x4e')][_0x0b01('0x4f')]({'model':db[_0x0b01('0x59')],'as':'User','attributes':['id','fullname','alias']});}if(_0x35ecb7[_0x0b01('0x3b')][_0x0b01('0x58')]){_0x8fe815[_0x0b01('0x4e')]=[{'all':!![]}];}return db[_0x0b01('0x55')][_0x0b01('0xab')](_0x8fe815);})['then'](function(_0x732193){_0x415689[_0x0b01('0xac')]=_0x732193;return _0x415689;});}})[_0x0b01('0x57')](respondWithFilteredResult(_0x2fc363,_0x8fe815))['catch'](handleError(_0x2fc363,null));};exports[_0x0b01('0xaf')]=function(_0x1c4a2c,_0x1d5c90,_0x146b1f){return db['ChatInteraction']['find']({'where':{'id':_0x1c4a2c[_0x0b01('0x66')]['id']}})[_0x0b01('0x57')](handleEntityNotFound(_0x1d5c90,null))[_0x0b01('0x57')](function(_0x15933d){if(_0x15933d){return _0x15933d[_0x0b01('0xb0')](_0x1c4a2c['body']['ids'],_[_0x0b01('0xb1')](_0x1c4a2c[_0x0b01('0x69')],[_0x0b01('0xb2'),'id'])||{})[_0x0b01('0xb3')](function(){return db[_0x0b01('0x50')][_0x0b01('0xab')]({'attributes':['id',_0x0b01('0x36'),'color'],'where':{'id':_0x1c4a2c[_0x0b01('0x69')][_0x0b01('0xb2')]}});})[_0x0b01('0x57')](function(_0x30dd99){socket[_0x0b01('0xb4')](_0x0b01('0xb5'),{'id':Number(_0x1c4a2c[_0x0b01('0x66')]['id']),'tags':_0x30dd99||[]});return{'id':Number(_0x1c4a2c[_0x0b01('0x66')]['id']),'tags':_0x30dd99||[]};});}})[_0x0b01('0x57')](respondWithResult(_0x1d5c90,null))[_0x0b01('0x64')](handleError(_0x1d5c90,null));};exports[_0x0b01('0xb6')]=function(_0x2add76,_0x5a72b0,_0x193d34){var _0x34036e;return db[_0x0b01('0x39')]['find']({'where':{'id':_0x2add76['params']['id']}})[_0x0b01('0x57')](handleEntityNotFound(_0x5a72b0,null))[_0x0b01('0x57')](function(_0x23a95a){if(_0x23a95a){return _0x23a95a['removeTags'](_0x2add76[_0x0b01('0x3b')]['ids']);}})[_0x0b01('0x57')](respondWithStatusCode(_0x5a72b0,null))[_0x0b01('0x64')](handleError(_0x5a72b0,null));};exports[_0x0b01('0x7b')]=function(_0x1f873b,_0x515ad5){var _0x1b3e8d=moment()[_0x0b01('0xb7')]()[_0x0b01('0xb8')]();var _0x1401dd=path[_0x0b01('0x80')](config[_0x0b01('0x7c')],_0x0b01('0xb9'),_0x0b01('0xba'),_0x0b01('0xbb'));var _0x573280=path[_0x0b01('0x80')](config['root'],_0x0b01('0xb9'),_0x0b01('0xba'),_0x0b01('0xbc'));var _0x3bb3c5=path[_0x0b01('0x80')](_0x1401dd,_0x1b3e8d);var _0x447f72=util[_0x0b01('0x82')]('interaction-%s.zip',_0x1b3e8d);var _0x3c660a=path[_0x0b01('0x80')](_0x1401dd,_0x447f72);var _0x1e8a31=![];return db[_0x0b01('0x39')][_0x0b01('0x67')]({'where':{'id':_0x1f873b[_0x0b01('0x66')]['id']},'include':[{'model':db['ChatMessage'],'as':_0x0b01('0x61'),'attributes':['id','body'],'include':[{'model':db[_0x0b01('0x59')],'as':'User','attributes':['id',_0x0b01('0x5d')],'raw':!![]},{'model':db[_0x0b01('0x5b')],'as':_0x0b01('0xbd'),'attributes':['id',_0x0b01('0xbe')],'raw':!![]},{'model':db['Attachment'],'as':_0x0b01('0x76'),'raw':!![]}]}]})[_0x0b01('0x57')](handleEntityNotFound(_0x515ad5,null))[_0x0b01('0x57')](function(_0x25f95d){if(_0x25f95d){_0x1e8a31=!![];var _0x5347c7='';var _0x225161={'format':_0x0b01('0xbf'),'border':_0x0b01('0xc0')};fs[_0x0b01('0xc1')](_0x3bb3c5);_0x5347c7+=util[_0x0b01('0x82')](_0x0b01('0xc2'),_0x25f95d['id']);_0x5347c7+=util[_0x0b01('0x82')]('<h2>Date:\x20%s</h2>',moment()[_0x0b01('0x82')](_0x0b01('0xc3'))[_0x0b01('0xb8')]());_0x5347c7+=_0x0b01('0xc4');for(var _0x298035=0x1;_0x298035<_0x25f95d[_0x0b01('0x61')][_0x0b01('0x41')];_0x298035++){var _0x30d04f=_0x25f95d[_0x0b01('0x61')][_0x298035];_0x5347c7+=_0x0b01('0xc5');_0x5347c7+=util[_0x0b01('0x82')]('<p\x20style=\x22margin:\x203px;\x22>%s:\x20%s</p>',_0x30d04f[_0x0b01('0x59')]?_0x30d04f[_0x0b01('0x59')]['fullname']:_0x30d04f['Contact']['firstName'],_0x30d04f[_0x0b01('0x69')]);_0x5347c7+='</div>';if(_0x30d04f[_0x0b01('0x76')]){var _0x3fc26a=_0x30d04f[_0x0b01('0x76')];var _0x2174db=path[_0x0b01('0x80')](_0x573280,_0x3fc26a[_0x0b01('0x73')]);if(fs[_0x0b01('0xc6')](_0x2174db)){fs[_0x0b01('0xc7')](_0x2174db)[_0x0b01('0xc8')](fs['createWriteStream'](path[_0x0b01('0x80')](_0x3bb3c5,_0x3fc26a[_0x0b01('0x73')])));}}}return new BPromise(function(_0x4018dd,_0xda1572){pdf[_0x0b01('0x68')](_0x5347c7,_0x225161)['toFile'](path[_0x0b01('0x80')](_0x3bb3c5,'interaction-'+_0x1b3e8d+_0x0b01('0xc9')),function(_0x150de6,_0x153dcb){if(_0x150de6)return _0xda1572(_0x150de6);_0x4018dd(_0x153dcb);});});}})[_0x0b01('0x57')](function(){if(_0x1e8a31){return new BPromise(function(_0x13b151,_0x15fa60){zipdir(_0x3bb3c5,{'saveTo':_0x3c660a},function(_0xd83305,_0x3745f5){if(_0xd83305)return _0x15fa60(_0xd83305);return _0x13b151(_0x3745f5);});});}})[_0x0b01('0x57')](function(){if(_0x1e8a31){return new BPromise(function(_0x556976,_0x28ed50){rimraf(_0x3bb3c5,function(_0x2410c6){if(_0x2410c6)_0x28ed50(_0x2410c6);return _0x556976();});});}})[_0x0b01('0x57')](function(){if(_0x1e8a31){return _0x515ad5[_0x0b01('0x7b')](_0x3c660a,_0x447f72,function(_0x59c54d){if(_0x59c54d){console['log']('err',_0x59c54d);}else{fs[_0x0b01('0xca')](_0x3c660a);}});}else{return _0x515ad5[_0x0b01('0x29')](0xc8);}})[_0x0b01('0x64')](handleError(_0x515ad5,null));};